Consider the following nested representation of binary trees: (X Y Z)…

2000

Consider the following nested representation of binary trees: (X Y Z) indicates Y and Z are the left and right subtrees, respectively, of node X. Note that Y and Z may be NULL, or further nested. Which of the following represents a valid binary tree?

  1. A.

    (1 2 (4 5 6 7))

  2. B.

    (1 (2 3 4) 5 6) 7)

  3. C.

    (1 (2 3 4) (5 6 7))

  4. D.

    (1 (2 3 NULL) (4 5))

Attempted by 158 students.

Show answer & explanation

Correct answer: C

The format (X Y Z) requires exactly three components per node: root, left subtree, and right subtree. Option A fails because (4 5 6 7) contains four elements instead of three. Option C correctly follows the triplet structure for all nodes, making it the valid binary tree representation.

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

Explore the full course: Coding For Placement