Height of a node in a tree is

2017

Height of a node in a tree is

  1. A.

    Level of the node

  2. B.

    Number of hops from root to the node

  3. C.

    Number of hops from the node to the leaf node in the longest path

  4. D.

    Number of children

Attempted by 81 students.

Show answer & explanation

Correct answer: C

A tree node has several distinct positional metrics: depth (or level) is the number of edges on the path from the root down to that node; degree is the number of children a node has; and height is the number of edges on the longest downward path from a node to any leaf in its subtree, with a leaf itself having height 0.

For the node asked about here, its height is found by tracing every downward path from it to each leaf in its own subtree and taking the longest one — the hop count along that longest path is the node's height.

  • “Level of the node” names the node's depth, measured from the root down to the node — the opposite direction from height.

  • “Number of hops from root to the node” is again the node's depth expressed as a hop count, not its height.

  • “Number of children” is the node's degree — how many direct children it has — unrelated to how deep its subtree runs.

So the height of a node is the number of hops from the node to the leaf node in the longest path within its subtree.

Explore the full course: Coding For Placement