[Chicago] A fun problem using a binary tree.

Joshua Herman zitterbewegung at gmail.com
Sat Mar 28 18:58:19 CET 2015


Python doesn't have a built in datastructure for trees but you could
represent them as a nested dictionary.
On Sat, Mar 28, 2015 at 9:27 AM Lewit, Douglas <d-lewit at neiu.edu> wrote:

> I'm just starting to learn about binary trees in my data structures
> class.  Interesting!  Just as I'm getting used to linked lists, the plot
> thickens and becomes even more complicated!  Oh geez!
>
> Here's the problem.  The root has a value of 1,000.  Every left child is
> 50 less than its parent, and every right child is 50 more than its parent.
> Continue adding nodes and children until finally the leftmost node (a leaf)
> has a value of 0.  Then add up all the nodes!  What is the total sum?
>
> I used Python 2.7 to solve the problem, although I believe my code is
> equally legit for Python 3.#, but try it and let me know.  I hope my answer
> is right!  I'm still confused about this whole tabs vs. spaces issue.
> What's the difference.  I mean.... as long as the interpreter doesn't yell
> at me, why should I worry about the difference between tabs and spaces?
>
> I believe that Java has a built-in class for constructing trees.  Does
> Python have such a built-in data structure?  If it does I don't know about
> it.  I created my own binary tree structure.  Cool stuff.
>
> Thanks for the feedback.
>
> Best wishes,
>
> Douglas Lewit
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150328/d066a153/attachment.html>


More information about the Chicago mailing list