The inorder traversal of the following tree is

2015

The inorder traversal of the following tree is

  1. A.

    2 3 4 6 7 13 15 17 18 18 20

  2. B.

    20 18 18 17 15 13 7 6 4 3 2

  3. C.

    15 13 20 4 7 17 18 2 3 6 18

  4. D.

    2 4 3 13 7 6 15 17 20 18 18

Attempted by 532 students.

Show answer & explanation

Correct answer: D

Inorder traversal rule: visit the left subtree, then the node, then the right subtree.

Apply this to the tree:

Left subtree (root 13):

  • Inorder(4) = 2 4 3

  • Visit node 13 -> 13

  • Inorder(7) = 7 6

Left-subtree result: 2 4 3 13 7 6

Visit root: 15

Right subtree (root 20):

  • Inorder(17) = 17

  • Visit node 20 -> 20

  • Inorder(18) = 18 18

Final inorder traversal: 2 4 3 13 7 6 15 17 20 18 18

Explore the full course: Coding For Placement