






































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Operations on Binary Tree, Applications of Binary Trees, Searching for Duplicates, C Implementation, Trace of insert, New tree node, Root node, Number of comparisons are key points of this lecture. and you can learn some other data structure terms.
Typology: Slides
1 / 46
This page cannot be seen from the preview
Don't miss anything!







































There are a number of operations that can be defined for a binary tree.
If p is pointing to a node in an existing tree then left( p ) returns pointer to the left subtree right( p ) returns pointer to right subtree parent( p ) returns the father of p brother( p ) returns brother of p. info(p) returns content of the node.
In order to construct a binary tree, the following can be useful:
setLeft(p,x) creates the left child node of p. The child node contains the info ‘x’.
setRight(p,x) creates the right child node of p. The child node contains the info ‘x’.
One way of finding duplicates is to compare each number with all those that precede it.
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
If the list of numbers is large and is growing, this procedure involves a large number of comparisons.
A linked list could handle the growth but the comparisons would still be large.
The number of comparisons can be drastically reduced by using a binary tree.
The tree grows dynamically like the linked list.
Otherwise, we create a new tree node and put the new number in it.
The new node is made the left child of the root node if the second number is less than the one in the root.
The new node is made the right child if the number is greater than the one in the root.
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14
15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14
15
4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14
15
4
9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14
4 15
9
9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14
4 15
9
7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14
4 15
9 7
18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14
4 15
9 7
18
3, 5, 16, 4, 20, 17, 9, 14, 5
14
4 15
9 7
18
3
3, 5, 16, 4, 20, 17, 9, 14, 5
14
4 15
9 7
3 18