Notes
Slide Show
Outline
1
Complete Binary Trees
  • Chapter 9 introduces trees.
  • This presentation illustrates the simplest kind of trees: Complete Binary Trees.
2
Binary Trees
  • 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
Binary Trees
  • 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
A Binary Tree of States
  • In this example, the data contained at each node is one of the 50 states.
5
A Binary Tree of States
  • Each tree has a special node called its root, usually drawn at the top.
6
A Binary Tree of States
  • Each tree has a special node called its root, usually drawn at the top.
7
A Binary Tree of States
  • Each node is permitted to have two links to other nodes, called the left child and the right child.
8
A Binary Tree of States
  • Each node is permitted to have two links to other nodes, called the left child and the right child.
9
A Binary Tree of States
  • Children are usually drawn below a node.
10
A Binary Tree of States
  • Some nodes have only one child.
11
A Quiz
  • Some nodes have only one child.
12
A Quiz
  • Some nodes have only one child.
13
A Binary Tree of States
  • A node with no children is called a leaf.
14
A Binary Tree of States
  • Each node is called the parent of its children.
15
A Binary Tree of States
  • Two rules about parents:
16
A Binary Tree of States
  • Two nodes with the same parent are called siblings.
17
Complete Binary Trees
  • A complete binary tree is a special kind of binary tree which will be useful to us.
18
Complete Binary Trees
  • A complete binary tree is a special kind of binary tree which will be useful to us.
19
Complete Binary Trees
  • The second node of a complete binary tree is always the left child of the root...
20
Complete Binary Trees
  • 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
Complete Binary Trees
  • The next nodes must always fill the next level from left to right.
22
Complete Binary Trees
  • The next nodes must always fill the next level from left to right.
23
Complete Binary Trees
  • The next nodes must always fill the next level from left to right.
24
Complete Binary Trees
  • The next nodes must always fill the next level from left to right.
25
Complete Binary Trees
  • The next nodes must always fill the next level from left to right.
26
Complete Binary Trees
  • The next nodes must always fill the next level from left to right.
27
Is This Complete?
28
Is This Complete?
29
Is This Complete?
30
Is This Complete?
31
Is This Complete?
  • Yes!
  • It is called the empty tree, and it has no nodes, not even a root.
32
Implementing a Complete Binary Tree
  • We will store the date from the nodes in a partially-filled array.
33
Implementing a Complete Binary Tree
  • We will store the date from the nodes in a partially-filled array.
34
   Summary
  • 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
THE  END