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 ? DS data-structures binary-tree time-complexity + – Kapil asked Jun 23, 2016 • recategorized Jul 6, 2022 by Lakshman Bhaiya Kapil 910 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes Time Complexity : O(n2). Worst case occurs when tree is skewed. Digvijay Pandey answered Jun 23, 2016 Digvijay Pandey comment Share Follow See all 3 Comments See all 3 3 Comments reply Kapil commented Jun 23, 2016 reply Follow Share @digvijay sir, mine is also same but answer is O(nlogn) 0 votes 0 votes Devshree Dubey commented Jun 23, 2016 reply Follow Share Sir could we go for the in-depth explanation of the above ques. 0 votes 0 votes Digvijay Pandey commented Jun 23, 2016 reply Follow Share Worst case complexity always be O(n2). Average case complexity will be ⊝(nlogn). 1 votes 1 votes Please log in or register to add a comment.
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. monty answered Jun 24, 2016 monty comment Share Follow See all 0 reply Please log in or register to add a comment.
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/ rishu_darkshadow answered Sep 18, 2017 rishu_darkshadow comment Share Follow See all 0 reply Please log in or register to add a comment.