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: 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: <519e46c0$0$26690$862e30e2@ngroups.net> Date: Thu, 23 May 2013 10:44:53 -0700 Subject: Re: Ordered dictionaries compared From: Dan Stromberg To: Python List 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --20cf3074afe066f32504dd663d7f Content-Type: text/plain; charset=ISO-8859-1 On Thu, May 23, 2013 at 9:41 AM, duncan smith 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. --20cf3074afe066f32504dd663d7f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

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

RBT is quicker than Treap for insertion with randomized data, but slower wi= th ordered data. Randomized data will tend to minimize the number of tree r= otations needed to keep the RBT balanced, whilst the Treap will be performi= ng rotations to maintain the heap property in an already reasonably well ba= lanced 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 bett= er 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 o= rdered 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 ran= domly 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 r= esults) if populated from ordered data. Treaps appear to perform better on = insertion, find and deletion when populated from ordered data.
=A0
Strange.=A0 I was comparing r= andomized data (95% get, 50-50 get and set, 95% set) when I found that trea= ps were quite a bit faster than red black trees.

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

See also https://en.wikipedi= a.org/wiki/Binary_search_tree#Performance_comparisons , which found tha= t treaps were faster on average the red black trees.


--20cf3074afe066f32504dd663d7f--