[an error occurred while processing this directive]
Section 2 Notes
Lists
What are possible representations for lists?
How would you implement list operations for different representations
of a list?
Operation |
Linked List |
Continuous |
Append(L, e)
|
|
|
Remove(L, e)
|
|
|
GetPosition(L, e)
|
|
|
Find(L, e)
|
|
|
Trees
What are the different types of trees?
Tree terminology
- A leaf has no children.
- Siblings have the same parent.
- A path is a sequence of nodes n1, n2, ..., nk such that
ni is the parent of ni+1
- The length of a path is the number of edges in the path.
- The depth of a node is the length of the path from the root to
the node.
- The height of a tree is the length of the longest path from
root to a leaf.
Questions
1. Insert G, H, F, and O into the alphabetically sorted binary tree below:
2. Insert 30 into the numerically sorted binary tree below:
3. Delete P from the alphabetically sorted binary tree below:
4. Delete D from the alphabetically sorted binary tree below (show all
possibilities):
5. Delete the root (show all possibilities that preserve a sorted
binary tree):
Running Time
Operation |
Linked List |
Continuous List |
Sorted Binary Tree |
Insert(L, index, x) for lists
Insert(T, x) for trees
|
|
|
|
Find(L, x)
|
|
|
|
Remove(L, x)
|
|
|
|
Draw all the binary trees that you can generate with this set
of data (Hint: Try inserting in different orders):
1, 3, 5, 7
[an error occurred while processing this directive]