341 views
0 votes
0 votes
if the value is less the root then it will goto left subtree & if the value is greater than root then it will go right.

1)what we do if value = root??(for multiple time same values)

2) duplicate values are allowed??

1 Answer

2 votes
2 votes

As per the popular implementation of BST,
We do not consider trees with duplicate values for BST.
We write algo for element < & > the root.

It does not mean we can not handle duplicate values.
One smart solution is,  in tree node, allocate a field for count.

struct node
{
   int data;
   int count;               // Counts number of nodes with equal data.
   struct node *left;
   struct node *right;
}

Related questions

0 votes
0 votes
1 answer
1
aditi19 asked Oct 1, 2018
618 views
what are the applications of optimal binary search tree?
0 votes
0 votes
1 answer
2
K ANKITH KUMAR asked Aug 29, 2018
1,815 views
Let T (n) be the number of comparisons needed in a binary search of a list of n elements. What is the recurrence relation? Explain. 1) T(n) = T(n/2) + 22) T(n) = T(n/2) +...
1 votes
1 votes
0 answers
3
Anjan asked Jan 9, 2018
334 views
Find number of BST's possible with 6 nodes numbered 1,2,3,4,5 and 6 having 6 as root and height of 4 ?please explain in detail ...
3 votes
3 votes
2 answers
4
VS asked Jan 3, 2018
832 views
Consider a Binary Search Tree is created using element 1 to n in following order: 3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, ....., n – 3, n – 4, n �...