Construct Binary Tree from Inorder and Postorder GFG POTD JAVA Solution geeks for geeks potd

Pubblicato il: 03 maggio 2024
sul canale di: VS Code
130
2

Problem - https://www.geeksforgeeks.org/problem...

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.

Driver code will print the preorder traversal of the constructed tree.

Example 1:

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
Example 2:

Input:
n = 5
in[] = {9, 5, 2, 3, 4}
post[] = {5, 9, 3, 4, 2}
Output:
2 9 5 4 3
Explanation:
The resultant binary tree will be
2
/ \
9 4
\ /
5 3


In questa pagina del sito puoi guardare il video online Construct Binary Tree from Inorder and Postorder GFG POTD JAVA Solution geeks for geeks potd della durata di ore minuti seconda in buona qualità , che l'utente ha caricato VS Code 03 maggio 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 130 volte e gli è piaciuto 2 spettatori. Buona visione!