I have a tasks to build binary tree as follow:
- Build ideal balanced tree.
- Find amount of nodes with specified value
- Transform tree to binary search tree
So… What’s weird for me: Everywhere i read about binary trees they never contain nodes with duplicate values, but in second task i must find amount of nodes that math to entered value… isn’t it just 0 or 1 if i build tree by rules?
Or, maybe, the first tree i build must be unordered and allows to have duplicates?
If i rebuild tree into binary search tree i need just delete duplicates and order nodes by left-less right-more rule?
A binary search tree may have duplicates and an example for that are multiset and multimap. Simply define if you put elements with equal key in the right or in the left subtree of a given node and nothing substantial will change.
EDIT: Also in the second task it is not required that you have binary search tree. If I get it right you only have a binary tree there(i.e. it is not ordered)