If the binary tree in fig is traversed in inorder, then the order in which the…

1991

If the binary tree in fig is traversed in inorder, then the order in which the nodes will be visited is

image.png

Show answer & explanation

Correct answer: gcbdafe

Inorder traversal follows the sequence: Left Subtree, Root, Right Subtree.

Starting at root 'a', we move left to 'b'. From 'b', go left to 'c', then left to 'g'. Since 'g' is a leaf, we visit it first.

Backtracking to 'c', we visit it. Backtracking to 'b', we visit the root 'b' before moving right to 'd'. We visit 'd' next.

Returning to the main root 'a', we visit it. Then we traverse its right subtree rooted at 'e'. We go left to 'f', visit it, and finally visit 'e'.

The complete inorder sequence is: g, c, b, d, a, f, e.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Coding For Placement