Reputation: 11
Same node can repeat in binary tree for example 1,2,3,4,1,2,3 what would happen to the repeated nodes in above example?
Upvotes: 1
Views: 98
Reputation:
Depends upon the conditions you set. If small values are inserted to the left and larger or equal values to the right, equal numbers will end up on the right.
e.g.
1
\
2
\
3
\
4
/
1
\
2
\
3
if you had 1,1,1,2,3 This would be the result
1
\
1
\
1
\
2
\
3
Nothing will be on the left as the condition of >= places the nodes to the right.
Upvotes: 2
Reputation: 81684
It would depend on the implementation of the tree. If you wanted to preserve duplicates, you could implement it to keep a linked list of data items at each node. Many implementations simply ignore the issue and "collapse" duplicates.
Upvotes: 2