• recategorized by
1,641 views

3 Answers

Best answer
3 3 votes

In Binary Search Tree, if We encounter same value which a node present in the Tree then we can insert into either left side or right side, it's our choice...

 

let take it is left side...

 

We all know that in BST,

insertion takes = O(h) , ===> it leads to O(n)

• selected by
0 0 votes
The worst case complexity of TREE-INSERT in the case of the Binary Search Tree is O(n). So when we are inserting n keys then also it will be the same i.e. O(n)

We cannot insert duplicate keys in the Binary Search Tree. So if you are inserting n identical keys then only one key will be inserted and as the binary search tree is empty initially so O(1) for the first element. Rest of them wont be inserted in the bst.
• edited by
0 0 votes
what i think it will depend upon the code. that we are using for the insertion of a node in BST. if you have a condition where you compare values of root with >= or <= operator with the child you can insert the node. but if u have < or > operators  u cannot insert it as the value wont be found.

in both cases time will be O(n) ,as you have to compare the value with the previous one n times in duplicate case.
Position:
Show:

Related questions

2 2 votes
3 3 answers
403
403 views
Shubham Sharma 2 asked Sep 9, 2025
403 views
Which of the following is $\text{TRUE}?$The cost of searching an AVL tree is $\theta(\log n)$ but that of binary search is $0(n)$The cost of searching an AVL tree in $\th...
1 1 vote
0 0 answers
147
147 views
Shubham Sharma 2 asked Jul 24, 2025
147 views
What is the time complexity for searching an element in a balanced Binary Search Tree?$\text{O}(1)$$\text{O}(\log n)$$\text{O}(n)$$\text{O}(n \log n)$ 
2 2 votes
1 1 answer
471
471 views
Shubham Sharma 2 asked Jun 12, 2025
471 views
Let $R$ be the root of a balanced binary search tree having $n$ nodes, where each node contains an integer, a pointer to its left child and a pointer to its right child. ...
1 1 vote
0 0 answers
230
230 views
admin asked Nov 25, 2024
230 views
A binary search tree is a binary tree whose proper subtrees are binary search trees, and whose root is strictly greater than all elements in the left subtree, and strictl...