recategorized by
910 views
2 votes
2 votes
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 order traversal of such a tree. Plz explain also ?
recategorized by

3 Answers

1 votes
1 votes

Time Complexity : O(n2). Worst case occurs when tree is skewed. 

0 votes
0 votes

when given binary tree postorder ,inorder or preorder , inorder then O(n^2)
when given binary search tree postorder ,inorder or preorder , inorder then O(nlogn)
O(nlogn)
why because of sorted inorder.

0 votes
0 votes

If we assume that the constructed binary tree is always balanced, then we can guarantee the run time complexity to be O(Nlog N), where N is the number of nodes. However, this is not necessarily the case and the constructed binary tree can be skewed to the left/right, which has the worst complexity of O(N2).

ref: http://articles.leetcode.com/construct-binary-tree-from-inorder-and-preorder-postorder-traversal/

Related questions

2 votes
2 votes
3 answers
2
Parshu gate asked Nov 13, 2017
2,995 views
For a binary tree T,preorder traversal yields: 11,8,6,4,7,10,19,43,31,29,37,49 andinorder traversal yields: 4,6,7,8,10,11,19,29,31,37,43,49The height of the T is _____...