Professional Documents
Culture Documents
Trees: Make Money Fast!
Trees: Make Money Fast!
Trees: Make Money Fast!
2 5 9
1. Motivations 2. Methods References
6 7 8
3 4
2.1 Stock 2.2 Ponzi 2.3 Bank
1.1 Greed 1.2 Avidity
Fraud Scheme Robbery
8
3 7
todo.txt
homeworks/ programs/
1K
1 2 4 5 6
h1c.doc h1nc.doc DDR.cpp Stocks.cpp Robot.cpp
3K 2K 10K 25K 20K
2 3 b
a 1
h height e 2h
h log e
2
h log2 (n 1) 1
2 8
1 4 7 9
3 5
subtree
print “)“ after traversing right print(v.element())
subtree
if v.isExternal()
inOrder(v.right())
print (“)’’)
2 3 b
((2 (a 1)) (3 b))
a 1
© 2010 Goodrich, Tamassia Trees 13
Evaluate Arithmetic Expressions
Specialization of a postorder Algorithm evalExpr(v)
traversal if v.isExternal()
recursive method returning return v.element()
the value of a subtree else
when visiting an internal x evalExpr(v.left())
node, combine the values
y evalExpr(v.right())
of the subtrees
operator stored at v
return x y
2 3 2
5 1
© 2010 Goodrich, Tamassia Trees 14
Euler Tour Traversal
Generic traversal of a binary tree
Includes a special cases the preorder, postorder and inorder traversals
Walk around the tree and visit each node three times:
on the left (preorder)
L R
B
2 3 2
5 1
A D F
C E
C E
A D
C E
C E
© 2010 Goodrich, Tamassia Trees 17
Array-Based Representation of Binary
Trees
Nodes are stored in an array A 1
A
A B D … G H …
2 3
0 1 2 3 10 11 B D