Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45826

Re: Ordered dictionaries compared

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.029
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'subsequent': 0.05; 'tree': 0.05; 'suppose': 0.07; 'insertion': 0.09; '23,': 0.16; 'deletion': 0.16; 'get,': 0.16; 'heap': 0.16; 'reasonably': 0.16; 'set,': 0.16; 'subject:dictionaries': 0.16; 'to:name:python list': 0.16; 'url:svn': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; 'thu,': 0.19; '(in': 0.22; 'comparing': 0.24; 'tend': 0.24; 'looks': 0.24; 'performing': 0.26; '(for': 0.26; 'header:In- Reply-To:1': 0.27; 'appear': 0.29; 'am,': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'url:wiki': 0.31; '(on': 0.31; 'url:wikipedia': 0.31; 'quite': 0.32; 'cases': 0.33; 'received:209.85': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'data,': 0.36; 'ordered': 0.36; 'whilst': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'being': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'black': 0.61; 'here:': 0.62; 'more': 0.64; 'worth': 0.66; 'smith': 0.68; 'surprise': 0.74; 'heavy': 0.81; '50-50': 0.84; '95%': 0.84; 'balanced': 0.84; 'quicker': 0.84; 'quickest': 0.84; 'average': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=f71SeF451+23Nl/8c1dUwueCdvzNaprvJwQLpf43Pk0=; b=hRkdxC3ExrQ3aGFA71p4WP+4lQqVMQ9mV5mGrfkz8JyZ7OqrBOZGJuRPbhsVtToUiL 4cuh4zXPmgUttFE/6wdQmibiWyr35hJBKMD1BqfhOLi86FViWRs1iek795idkr/4FRFz aVrkPEKv7BaA+nlYjD89iRRge7x+c669NxkXjYoLYiC5NW6MgNdqUI+OrS8g1+yqvCtc oCAdaFWwAzqUwPD6N/BGvVFyLAQHuZE6MlybCfmft72aaswM5UAeDPq2mV7Smrceg4ZS pe0gT6yruOeJ8r30/0cbINKGIeRkoZS/qtwmy3cpiddBpfAUozpz5aYin/8XoSUFiavU tkrg==
MIME-Version 1.0
X-Received by 10.224.35.67 with SMTP id o3mr12877080qad.11.1369331093393; Thu, 23 May 2013 10:44:53 -0700 (PDT)
In-Reply-To <519e46c0$0$26690$862e30e2@ngroups.net>
References <mailman.1989.1369279892.3114.python-list@python.org> <519e46c0$0$26690$862e30e2@ngroups.net>
Date Thu, 23 May 2013 10:44:53 -0700
Subject Re: Ordered dictionaries compared
From Dan Stromberg <drsalists@gmail.com>
To Python List <python-list@python.org>
Content-Type multipart/alternative; boundary=20cf3074afe066f32504dd663d7f
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2024.1369331102.3114.python-list@python.org> (permalink)
Lines 96
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369331102 news.xs4all.nl 15866 [2001:888:2000:d::a6]:46202
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45826

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Thu, May 23, 2013 at 9:41 AM, duncan smith <buzzard@invalid.invalid>wrote:

>
> RBT is quicker than Treap for insertion with randomized data, but slower
> with ordered data. Randomized data will tend to minimize the number of tree
> rotations needed to keep the RBT balanced, whilst the Treap will be
> performing rotations to maintain the heap property in an already reasonably
> well balanced tree. With ordered data the RBT will have to work harder to
> keep the tree balanced, whilst the Treap will be able to maintain the heap
> property with fewer rotations.
>
> No surprise that find() is generally quicker for RBTs, they tend to be
> better balanced.
>
> Deletion is a bit more confusing. I suppose deletion from a better
> balanced tree will tend to be quicker, but deletion from a treap
> constructed from ordered data is (for some reason) quickest of all.
>
> All these operations require a call to find(), and that is generally going
> to be quicker for RBTs. Treaps tend to require fewer subsequent rotations,
> but they have variable worth (in terms of rebalancing).
>
> Looks like RBTs are better than treaps if they are being populated with
> randomly ordered data, but not if they are being populated with ordered
> data. RBTs are better for use cases that are heavy on finds.
>
> Both types of tree appear to be better balanced (on the basis of the find
> results) if populated from ordered data. Treaps appear to perform better on
> insertion, find and deletion when populated from ordered data.
>

Strange.  I was comparing randomized data (95% get, 50-50 get and set, 95%
set) when I found that treaps were quite a bit faster than red black trees.

The code I used is here:
http://stromberg.dnsalias.org/svn/python-tree-and-heap-comparison/trunk/

See also
https://en.wikipedia.org/wiki/Binary_search_tree#Performance_comparisons ,
which found that treaps were faster on average the red black trees.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Ordered dictionaries compared Dan Stromberg <drsalists@gmail.com> - 2013-05-22 20:31 -0700
  Re: Ordered dictionaries compared duncan smith <buzzard@invalid.invalid> - 2013-05-23 17:41 +0100
    Re: Ordered dictionaries compared Dan Stromberg <drsalists@gmail.com> - 2013-05-23 10:44 -0700
      Re: Ordered dictionaries compared duncan smith <buzzard@invalid.invalid> - 2013-05-24 00:57 +0100

csiph-web