Professional Documents
Culture Documents
• A binary tree:
– No node has more than two child nodes (called child
subtrees).
– Child subtrees must be differentiated, into:
• Left-child subtree
• Right-child subtree
• A search tree:
– For every node, p:
• All nodes in the left subtree are < p
• All nodes in the right subtree are > p
Binary Search Tree - Example
Alex
Alex
Abner
Abner Angela
Angela
Abigail
Abigail Adela
Adela Alice
Alice Audrey
Audrey
Adam Agnes
Agnes Allen Arthur
Adam Allen Arthur
Binary Search Trees (cont)
• Searching for a value is in a tree of N nodes
is:
– O(log N) if the tree is “balanced”
– O(N) if the tree is “unbalanced”
“Unbalanced” Binary Search Trees
• Below is a binary search tree that is NOT
“balanced”
Abigail
Abigail
Adam
Abner
Abner
Adam Adela
Adela
Agnes
Agnes
Alex
Alex
Alice
Alice
Allen
Allen
Angela
Angela
Arthur
Arthur
Audrey
Audrey
Properties of Binary Trees
• A binary tree is a full binary tree if and only
if:
– Each non leaf node has exactly two child nodes
– All leaf nodes have identical path length
• It is called full since all possible node slots
are occupied
A Full Binary Tree - Example
Full Binary Trees
• A Full binary tree of height h will have
how many leaves?
leaves
BB CC
DD EE FF GG
HH II JJ KK
N M
N-M<=1