|
1
|
- Chapter 9 introduces trees.
- This presentation illustrates the simplest kind of trees: Complete
Binary Trees.
|
|
2
|
- A binary tree has nodes, similar to nodes in a linked list structure.
- Data of one sort or another may be stored at each node.
- But it is the connections between the nodes which characterize a binary
tree.
|
|
3
|
- A binary tree has nodes, similar to nodes in a linked list structure.
- Data of one sort or another may be stored at each node.
- But it is the connections between the nodes which characterize a binary
tree.
|
|
4
|
- In this example, the data contained at each node is one of the 50
states.
|
|
5
|
- Each tree has a special node called its root, usually drawn at the top.
|
|
6
|
- Each tree has a special node called its root, usually drawn at the top.
|
|
7
|
- Each node is permitted to have two links to other nodes, called the left
child and the right child.
|
|
8
|
- Each node is permitted to have two links to other nodes, called the left
child and the right child.
|
|
9
|
- Children are usually drawn below a node.
|
|
10
|
- Some nodes have only one child.
|
|
11
|
- Some nodes have only one child.
|
|
12
|
- Some nodes have only one child.
|
|
13
|
- A node with no children is called a leaf.
|
|
14
|
- Each node is called the parent of its children.
|
|
15
|
|
|
16
|
- Two nodes with the same parent are called siblings.
|
|
17
|
- A complete binary tree is a special kind of binary tree which will be
useful to us.
|
|
18
|
- A complete binary tree is a special kind of binary tree which will be
useful to us.
|
|
19
|
- The second node of a complete binary tree is always the left child of
the root...
|
|
20
|
- The second node of a complete binary tree is always the left child of
the root...
- ... and the third node is always the right child of the root.
|
|
21
|
- The next nodes must always fill the next level from left to right.
|
|
22
|
- The next nodes must always fill the next level from left to right.
|
|
23
|
- The next nodes must always fill the next level from left to right.
|
|
24
|
- The next nodes must always fill the next level from left to right.
|
|
25
|
- The next nodes must always fill the next level from left to right.
|
|
26
|
- The next nodes must always fill the next level from left to right.
|
|
27
|
|
|
28
|
|
|
29
|
|
|
30
|
|
|
31
|
- Yes!
- It is called the empty tree, and it has no nodes, not even a root.
|
|
32
|
- We will store the date from the nodes in a partially-filled array.
|
|
33
|
- We will store the date from the nodes in a partially-filled array.
|
|
34
|
- Binary trees contain nodes.
- Each node may have a left child and a right child.
- If you start from any node and move upward, you will eventually reach
the root.
- Every node except the root has one parent. The root has no parent.
- Complete binary trees require the nodes to fill in each level from
left-to-right before starting the next level.
|
|
35
|
|