Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'tree': 0.05; 'binary': 0.07; 'library?': 0.09; 'trees': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'times,': 0.14; "wouldn't": 0.14; '-tkc': 0.16; 'dict': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'heapq': 0.16; 'operates': 0.16; 'sought': 0.16; 'wrote:': 0.18; 'library': 0.18; 'cc:addr:python.org': 0.22; '(such': 0.24; "aren't": 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; "i've": 0.25; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'michael': 0.29; 'along': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'could': 0.34; "can't": 0.35; 'there': 0.35; 'combination': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.36; 'list': 0.37; 'list.': 0.37; 'received:10': 0.37; 'easily': 0.37; 'pm,': 0.38; 'algorithms': 0.60; 'to:addr:gmail.com': 0.65 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1421711934643:238944023 X-MC-Ingress-Time: 1421711934643 Date: Mon, 19 Jan 2015 18:00:51 -0600 From: Tim Chase To: Michael Torrie Subject: Re: Trees In-Reply-To: <54BD911A.1050206@gmail.com> References: <54bd8e6a$0$13009$c3e8da3$5496439d@news.astraweb.com> <54BD911A.1050206@gmail.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com Cc: python-list@python.org 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421712397 news.xs4all.nl 2836 [2001:888:2000:d::a6]:42098 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84034 On 2015-01-19 16:19, Michael Torrie wrote: > On 01/19/2015 04:08 PM, Steven D'Aprano wrote: > > Zachary Gilmartin wrote: > >> Why aren't there trees in the python standard library? > > > > Possibly because they aren't needed? Under what circumstances > > would you use a tree instead of a list or a dict or combination > > of both? While not an abundance of times, I've had a plurality of occasions when I've wanted characteristics of a red/black tree where I wanted O(log n) insertion/deletion/initial-access and O(1) access to neighbors. > > Also, what sort of tree? Binary tree? Binary search tree? > > Red/black tree? AVL tree? Splay tree? B-tree? T-tree? Scapegoat > > tree? General n-ary tree? Every possible type of tree yet > > invented? > > Don't forget left-child,right-sibling trees. > > As I go through your list of trees, I can't find any tree type that > cannot be easily and efficiently constructed with lists, possibly > with dicts. While the data-structures can easily be composed out of lists/dicts, the algorithms that go along with them (such as red/black trees with their insertion/deletion gymnastics) would be nice to have in the stdlib so they wouldn't have to be reimplemented (or sought out and downloaded, and added to the configuration/distribution) every time someone wanted that particular tree's characteristics. Much of that could be addressed with a library of algorithms much like heapq operates on a list. -tkc