• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
May 09, 2024 |30 Views
PROBLEM OF THE DAY: 04/05/24 - Construct Binary Tree from Inorder and Postorder
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Binary Tree but also build up problem-solving skills.

In this problem, we are given inorder and postorder traversals of a binary tree(having n nodes) in the arrays in[] and post[] respectively. The task is to construct a binary tree from these traversals.

Example :

Input:
n = 8
in[] = {4, 8, 2, 5, 1, 6, 3, 7}
post[] = {8, 4, 5, 2, 6, 7, 3, 1}
Output: 
1 2 4 8 5 3 6 7
Explanation: 
For the given postorder and inorder traversal of tree the  resultant binary tree will be
         1
      /      \
    2        3
  /  \      /  \
 4   5    6   7
  \
   8

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/tree-from-postorder-and-inorder/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp14-compiler/70502028-6a7e-4adc-8363-2563438baa7c