Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Best structure for (binary) trees?

Reply
Thread Tools

Best structure for (binary) trees?

 
 
Rasmus
Guest
Posts: n/a
 
      12-07-2003
Hi.

As partly novice in python I would like a piece of advise of how to
implement (binary) trees the best way?

Thanks in advance,

Rasmus

PS: Due to heavy spam reception (20.000+/week), I use a fake sender address.
Please answer in the newsgroup. Thanks


 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      12-07-2003
"Rasmus" wrote:

> As partly novice in python I would like a piece of advise of how to
> implement (binary) trees the best way?


if you're 100% sure you cannot use a standard dictionary, the best
way is probably to get ZODB and use its BTrees module...

code:

http://www.zope.org/Products/ZODB3.2

introduction:

http://zope.org/Wikis/ZODB/FrontPage/guide/node6.html

</F>




 
Reply With Quote
 
 
 
 
Aahz
Guest
Posts: n/a
 
      12-07-2003
In article <jVGAb.13860$(E-Mail Removed)2net.dk>,
Rasmus <(E-Mail Removed)> wrote:
>
>As partly novice in python I would like a piece of advise of how to
>implement (binary) trees the best way?


Assuming that nodes also contain data:

class Node:
def __init__(self, data):
self.data = data
self.left = self.right = None

Assuming that you're a CS student looking for homework help, I'll leave
the rest of the implementation as an exercise. You might also consider
looking at the bisect module.
--
Aahz ((E-Mail Removed)) <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote
programs, then the first woodpecker that came along would destroy civilization.
 
Reply With Quote
 
Alan Kennedy
Guest
Posts: n/a
 
      12-07-2003
[Rasmus]
> As partly novice in python I would like a piece of advise of how to
> implement (binary) trees the best way?


The original Python Enhancement Proposal (PEP) for Generators (a
recently introduced feature of the python language), PEP-255, contains
a nice example of building and navigating binary trees.

http://www.python.org/peps/pep-0255.html

Search for the text "binary tree class" on that page. That should give
you sufficient sample code to play with.

If you're able to follow the generator/yield -based examples, I'd be
so bold as to say that that is "the best way".

regards,

--
alan kennedy
------------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/contact/alan
 
Reply With Quote
 
Rasmus
Guest
Posts: n/a
 
      12-07-2003
Thanks to all of you.
I have found several good answers of implementing trees from your postings.

R

--

PS: Due to heavy spam reception (20.000+/week), I use a fake sender address.
Please answer in the newsgroup. Thanks

"Rasmus" <(E-Mail Removed)> wrote in message
news:jVGAb.13860$(E-Mail Removed)2net.dk...
> Hi.
>
> As partly novice in python I would like a piece of advise of how to
> implement (binary) trees the best way?
>
> Thanks in advance,
>
> Rasmus
>
> PS: Due to heavy spam reception (20.000+/week), I use a fake sender

address.
> Please answer in the newsgroup. Thanks
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between c structure and c++ structure raghunandan_1081@yahoo.com C++ 9 11-11-2011 07:34 AM
How to read a Structure from a matlab file to a structure in Vc++ 2003 meisterbartsch C++ 2 06-12-2007 08:47 PM
Memory allocation in Structure to Structure pra_ramli@rediffmail.com C++ 2 03-09-2006 05:51 AM
Copy String structure "A" to string structure "B" Leo Nunez C Programming 3 02-09-2005 05:14 AM
Pointers to structure and array of structure. Excluded_Middle C Programming 4 10-26-2004 05:39 AM



Advertisments