1

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

means that i don't need repeat same nodes again and again?
As I said, it depends on the purpose of the tree, and how you implement it. But no, you're certainly not required to allow duplicate nodes in the tree.
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.