Professional Documents
Culture Documents
L10 BinaryTree
L10 BinaryTree
type nodes
§ one entry point called root
§ Each node is either a leaf or an
internal node
§ An internal node has 1 or more
children, nodes that can be
reached directly from that internal
node.
§ The internal node is said to be the leaf nodes
parent of its child nodes
MA512: Data Structures and Algorithms
5
Definition: Siblings, path length
root
• siblings: two nodes that
edge
have the same parent
• edge: the link from one
node to another
• path length: the number
of edges that must be siblings
traversed to get from
one node to another
A A
B B
Fig.: Different binary trees
B
B
C C
D D
C(3)
B(2)
B(2)
H(8)
H(8)
1 2 3 4 5 6 7 8 … 1 2 3 4 5 6 7 8 …
A B C D E F G H .. A B D H ..
• The numbering scheme suggest that we can use a 1-D
array to store the nodes
B C
D E F
• Predecessor(X): Node which comes before X in the
inorder traversal