Professional Documents
Culture Documents
1)
Elementary Data The Stack ADT stores
arbitrary objects
Structures Insertions and deletions Auxiliary stack
follow the last-in first-out operations:
scheme object top(): returns the
Stacks, Queues, & Lists Think of a spring-loaded last inserted element
plate dispenser without removing it
Amortized analysis integer size(): returns the
Main stack operations:
number of elements
Trees push(object): inserts an
stored
element
object pop(): removes and boolean isEmpty():
returns the last inserted indicates whether no
element elements are stored
f ∅
∅
A B C D
elements
Elementary Data Structures 13 Elementary Data Structures 14
6 7 8 1 2 4 5 6
3 4
2.1 Stock 2.2 Ponzi 2.3 Bank h1c.doc h1nc.doc DDR.java Stocks.java Robot.java
1.1 Greed 1.2 Avidity
Fraud Scheme Robbery 3K 2K 10K 25K 20K
Amortized Analysis of
Tree Traversal Binary Trees (§2.3.3)
A binary tree is a tree with the Applications:
Time taken in preorder or postorder traversal following properties: arithmetic expressions
of an n-node tree is proportional to the sum, Each internal node has two decision processes
children
taken over each node v in the tree, of the The children of a node are an
searching
h ≥ log2 (n + 1) − 1 1 4 7 9
3 5
B
nodes Left child node
Right child node
Node objects implement ∅ ∅
A D F A D ∅ ∅ ∅ ∅
C E ∅ ∅
C E C E
C E
Elementary Data Structures 29 Elementary Data Structures 30
Array-Based Representation of
Binary Trees
nodes are stored in an array
1
A
…
2 3
B D