Which data structure is most suitable for representing hierarchical…

2012

Which data structure is most suitable for representing hierarchical relationships among elements?

Answer: C. TreeConceptHierarchical data is organized into levels, so an element can have parent-child relationships rather than only a single linear predecessor or…

  1. A.

    Deque

  2. B.

    Priority queue

  3. C.

    Tree

  4. D.

    Deque and priority queue

Attempted by 499 students.

Show answer & explanation

Correct answer: C

Concept

Hierarchical data is organized into levels, so an element can have parent-child relationships rather than only a single linear predecessor or successor.

A tree models this arrangement as nodes connected by edges from a root.

Application

The relationship described here is hierarchical. A tree directly represents root, parent, child, and descendant relationships, so Tree is the suitable data structure.

Contrast

  • A deque is linear and provides insertion and removal at its two ends.

  • A priority queue orders access by priority rather than by parent-child levels.

  • Deque and priority queue combines two queue-oriented linear structures, neither of which supplies parent-child levels.

Cross-check

A file-system directory or an organization chart branches from one parent into children and descendants; drawing the same relationships produces a tree.

Therefore, the suitable data structure is Tree.

Explore the full course: Coding For Placement

Loading lesson…