0 votes 0 votes What is the time complexity to construct a binary tree when inorder and preorder traversal of the tree is given? 1. O(n) 2.O(n log n) 3. O(n2) 4.O(n2 log n) Algorithms algorithms + – kallu singh asked Aug 19, 2017 kallu singh 247 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes O(N) sachin! answered Aug 19, 2017 sachin! comment Share Follow See all 2 Comments See all 2 2 Comments reply kallu singh commented Aug 19, 2017 reply Follow Share But ans is O(n2) 0 votes 0 votes sachin! commented Aug 19, 2017 reply Follow Share http://www.geeksforgeeks.org/construct-tree-from-given-inorder-and-preorder-traversal/ this solution is in order O(n^2). optimize this solution by create hash for each value of inorder sequence and utilize it in search function as it can search inO(1) 0 votes 0 votes Please log in or register to add a comment.