recategorized by
812 views
4 votes
4 votes
How is it possible that the time complexity of inorder traversal is O(n), because the time complexity of Inorder Successor in Binary Search Tree is O(log n), So the inorder traversal in BST for printing the numbers take O(n*logn) time for 'n' nodes???
recategorized by

1 Answer

Best answer
1 votes
1 votes
1.How is it possible that the time complexity of inorder traversal is O(n),

as in inorder traversal we have to start from left and got to middlae and right so each and everry element is processed so o(n).

2.because the time complexity of Inorder Successor in Binary Search Tree is O(log n),

the time complexity of inorder successor in binary search tree is O(logn) as 2^H-1=n

so h=logn

3.So the inorder traversal in BST for printing the numbers take O(n*logn) time for 'n' nodes???

so as u printing the numbers then u have to access each and every elements O(n) at height O(logn)

and they are execute in combined so O(logn)

hope it will help
selected by

Related questions

2 votes
2 votes
1 answer
4
Akriti sood asked Oct 16, 2016
1,978 views
what is the time complexity in creating a BInary search tree from an unsorted array??