03. If we draw a binary search tree by inserting the given numbers from left to right then what would be the height of the BST? 120,85, 100, 90, 50, 60
Answers
Answer:
Binary Search Tree-
Binary Search Tree is a special kind of binary tree in which nodes are arranged in a specific order.
In a binary search tree (BST), each node contains-
Only smaller values in its left sub treeOnly larger values in its right sub tree
Example-
Number of Binary Search Trees-
Example-
Number of distinct binary search trees possible with 3 distinct keys
= 2×3C3 / 3+1
= 6C3 / 4
= 5
If three distinct keys are A, B and C, then 5 distinct binary search trees are-
Binary Search Tree Construction-
Let us understand the construction of a binary search tree using the following example-
Example-
Construct a Binary Search Tree (BST) for the following sequence of numbers-
50, 70, 60, 20, 90, 10, 40, 100
When elements are given in a sequence,
Always consider the first element as the root node.Consider the given elements and insert them in the BST one by one.
The binary search tree will be constructed as explained below-
Insert 50-
Insert 70-
As 70 > 50, so insert 70 to the right of 50.
Insert 60-
As 60 > 50, so insert 60 to the right of 50.As 60 < 70, so insert 60 to the left of 70.
Insert 20-
As 20 < 50, so insert 20 to the left of 50.
Insert 90-
As 90 > 50, so insert 90 to the right of 50.As 90 > 70, so insert 90 to the right of 70.
Insert 10-
As 10 < 50, so insert 10 to the left of 50.As 10 < 20, so insert 10 to the left of 20.
Insert 40-
As 40 < 50, so insert 40 to the left of 50.As 40 > 20, so insert 40 to the right of 20.
Insert 100-
As 100 > 50, so insert 100 to the right of 50.As 100 > 70, so insert 100 to the right of 70.As 100 > 90, so insert 100 to the right of 90.
This is the required Binary Search Tree.
Answer:
ii of duniya sey jora ioi to do ii sath kiya