CS301 – Data Structures
Lecture No. 12
These methods have already been discussed at the end of the previous lecture, however,
few more methods are required to construct a binary tree:
Creates the left child node of
Creates the right child node of
child node contains the info
All these methods are required to build and to retrieve values from a tree.
Applications of Binary Tree
Let’s take few examples to understand how the tree data type is used and what are its
benefits. We will also develop some algorithms that may by useful in future while
working with this data type.
Binary tree is useful structure when two-way decisions are made at each point. Suppose
we want to find all duplicates in a list of the following numbers:
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
This list may comprise numbers of any nature. For example, roll numbers, telephone
numbers or voter’s list.
In addition to the presence of duplicate number, we may also
require the frequency of numbers in the list. As it is a small list, so only a cursory view
may reveal that there are some duplicate numbers present in this list. Practically, this list
can be of very huge size ranging to thousands or millions.