473,378 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Data structures for tree traversals?

Dear friends,

What are the best options for implementing fast and efficient trees in
Python?

The typical trees that I'm thinking of are those used by the finance
industry to price different kinds of derivatives (ie forward simulation of
prices/rates in binominal/trinominal trees and backward induction to price
final claims).

Intuitively, dictionaries seem to be ideal candidates for accessing objects
at nodes and traversing the tree. Am I right or are there better choices?
Are lists better? Has Numerical Python speed-efficient methods that are to
be preferred in comparison with lists ad dictionaries?

Carl

Jul 18 '05 #1
1 1498
Hello Carl,
What are the best options for implementing fast and efficient trees in
Python? The answer varies depending on what will the trees be used for.
Intuitively, dictionaries seem to be ideal candidates for accessing objects
at nodes and traversing the tree. Am I right or are there better choices?
Are lists better? Has Numerical Python speed-efficient methods that are to
be preferred in comparison with lists ad dictionaries?

There's http://www.python.org/doc/essays/graphs.html by the BDFL.

I find that defining a little class:
class Tree:
def __init__(self, value, children=None):
self.value = value
if children is None:
self.children = []
else:
self.children = children

and subclassing each specific child.
Combined with a visitor pattern is usually the best way.

Go for the usual approach:
o Make it work
o Make it right
o Make it fast (only if you need)

HTH.

Bye.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@gmail.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: David Méndez | last post by:
Hi, If I have the preorder and inorder list, which algorithm does I need to build the corresponding B-TREE? where can I find some source code? thanks -- comp.lang.c.moderated - moderation...
22
by: delraydog | last post by:
It's quite simple to walk to the DOM tree going forward however I can't figure out a nice clean way to walk the DOM tree in reverse. Checking previousSibling is not sufficient as the...
3
by: zeah | last post by:
hi how do we build a binary search tree when post order and inorder tree traversals are given to u....and how do we make use of creat root and create tree templates in your existing code???
2
by: APEJMAN | last post by:
Hi, would you please guide me with this question? suppose we have a tree with at least 3 nodes containing unique integer values. I want to draw an example tree that justifies my answer and write out...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.