in DS
330 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??
in DS
330 views

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;
}

by