• retagged by
727 views

2 Answers

1 1 vote
The best case will be for balanced binary search tree, O(log n).

Inserting an element takes time proportinal to  the tree height.
0 0 votes
It depends on data structure used to represent a binary tree.

If array is used then inserting will take O(1), just insert at the last position in an array.

If standard structure is made then it takes O(logn) time in best case if tree is balanced but if it left or right skewed then it takes O(n) if we want to insert in leaf node, if we try to insert at root then it will take O(1) in case of skewed binary tree.
Position:
Show:

Related questions

0 0 votes
2 2 answers
1.3k
1.3k views
2 2 votes
3 3 answers
1.5k
1.5k views
Kapil asked Jun 23, 2016
1,481 views
If the inorder traversal and preorder traversal of a binary tree having N elements are given, then what will be the time complexity of post order traversal and level orde...
10 10 votes
1 1 answer
290
290 views
GO Classes asked Jul 28
290 views
A binary tree has:$1000$ nodes in the left subtree $100$ nodes in the right subtreeHow many nodes are processed before the root in preorder, inorder, and postorder traver...
7 7 votes
1 1 answer
189
189 views
GO Classes asked Jul 13
189 views
Which of the following functions correctly returns the total number of nodes in a binary tree rooted at $\texttt{t}$?int tree_size(TreeNode *t) { if (t == NULL) return 0;...