Data Structures & AlgorithmsEasyTCS NQT · Infosys pattern
A binary tree has root 1; 1's children are 2 (left) and 3 (right); 2's children are 4 (left) and 5 (right); 3 has only a right child, 6. What is its postorder traversal?
- A. 4 2 5 1 3 6
- B. 1 2 4 5 3 6
- C. 4 5 2 6 3 1
- D. 4 5 6 2 3 1
Correct answer: C. 4 5 2 6 3 1
Postorder is left, right, root: finish 2's subtree (4 5 2), then 3's subtree (6 3), then the root 1. 1 2 4 5 3 6 is preorder and 4 2 5 1 3 6 is inorder.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Keys 50, 30, 70, 20, 40, 60, 80 are inserted in that order into an empty BST. How many leaves does the tree have, and what is its height…
- What is the maximum number of nodes in a binary tree of height 4, where a single-node tree has height 0?
- What is the minimum possible height of a binary tree with 100 nodes (height of a single node = 0)?
- With the edges sorted first, what is the time complexity of Kruskal's algorithm using a union-find structure, for a graph with V vertices…
- Which single-source shortest path algorithm can detect a negative-weight cycle reachable from the source?
- A topological ordering of a directed graph exists if and only if the graph is: