Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'binary': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'terry': 0.09; 'trees': 0.09; 'applies': 0.15; 'entities.': 0.16; 'message-id:@dough.gmane.org': 0.16; 'nodes': 0.16; 'nodes.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'otherwise,': 0.20; 'trying': 0.21; '31,': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'url:wiki': 0.26; 'right.': 0.27; 'forgive': 0.27; 'tree': 0.27; 'header:X-Complaints-To:1': 0.28; 'leaves': 0.29; 'node': 0.29; 'parent': 0.29; 'url:wikipedia': 0.29; 'could': 0.32; 'to:addr:python-list': 0.33; 'point.': 0.33; 'pm,': 0.35; 'there': 0.35; 'received:org': 0.36; 'except': 0.36; 'url:org': 0.36; 'child': 0.36; 'two': 0.37; 'quite': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'url:en': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'more': 0.63; 'limit': 0.65; 'total': 0.65; 'jul': 0.65; 'everything.': 0.84; 'received:fios.verizon.net': 0.84; 'subject:better': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Why 'Flat is better than nested' Date: Tue, 31 Jul 2012 19:57:24 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343779070 news.xs4all.nl 6970 [2001:888:2000:d::a6]:41819 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26331 On 7/31/2012 5:49 PM, Ian Kelly wrote: > On Tue, Jul 31, 2012 at 3:28 PM, Ifthikhan Nazeem wrote: >> as many as (about) 2*N - log2(N) parent child relationships >> >> I would like to know how did you come up with the above formula? Forgive my >> ignorance. By non-rigorous experimentation, which did not quite count everything. > I come up with 2N - 2 myself. If there are N leaf nodes and N - 1 > non-leaf nodes, then there are 2N - 1 total nodes, each of which has > one parent except for the root. That's 2N - 2 parent-child > relationships. That looks right. I was trying to think recursively, which in this case is more rather than less complicated. That actually sharpens my original point. N-1 new nodes and 2N-2 new relationships is 3N-3 new entities. The internal node limit of N-1 only applies to full-proper-strict binary trees without one-child internal nodes. Otherwise, a single leaf node could have an indefinite number of ancestors. from https://en.wikipedia.org/wiki/Binary_tree "A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in which every node other than the leaves has two children." -- Terry Jan Reedy