Non-Linear Data Structures MCQs for the NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

Non-linear data structures let one element connect to several others, so the data forms a hierarchy or a network rather than a single sequence. The core four are trees, binary search trees (BSTs), heaps and graphs. They are the third of 12 topics in the Data Structures & Algorithms area, which carries 10% of the NSCT according to HEC's Areas of Competencies.

This page covers the structures themselves. Algorithms that run on them are covered in Tree Algorithms and Graph Algorithms.

Trees

A tree is a hierarchy of nodes with one root, where every other node has exactly one parent. A leaf has no children. The depth of a node is its distance from the root, and the height of a tree is the longest root-to-leaf path. Most texts, including CLRS, count edges (a single node has height 0); some count nodes, so read the question.

In a binary tree each node has at most two children. Facts worth memorising:

Fact Formula Example
Max nodes at height h 2^(h+1) - 1 h = 4: 31 nodes
Min height for n nodes floor(log₂ n) n = 20: height 4
Leaves vs two-child nodes n0 = n2 + 1 7 two-child nodes: 8 leaves
Edges in a tree of n nodes n - 1 10 nodes: 9 edges

Terminology differs here too. Usually a full binary tree has 0 or 2 children at every node, and a complete one fills every level except possibly the last, from the left. CLRS uses "complete" for a tree with every level full, which others call perfect.

Exam angle: the three depth-first traversals are preorder (node, left, right), inorder (left, node, right) and postorder (left, right, node). Given preorder and inorder, you can rebuild the tree.

BST

A binary search tree keeps every key in a node's left subtree smaller than the node, and every key in its right subtree larger. Inorder traversal therefore gives sorted order.

Insert 8, 3, 10, 1, 6, 14, 4 into an empty BST:

        8
      /   \
     3     10
    / \      \
   1   6      14
      /
     4

Search, insert and delete all cost O(h). That is O(log n) when the tree is balanced, but O(n) when keys arrive in sorted order and the tree becomes a chain. To delete a node with two children, replace it with its inorder successor (smallest key on the right) or predecessor; textbooks differ on which, so both are accepted.

Exam angle: a validity check that only compares each node with its direct children is wrong. The rule applies to whole subtrees.

Heaps

A binary heap is a complete binary tree with the heap property: in a min-heap each parent is ≤ its children (max-heap: ≥). It is stored in an array; with 0-based indices the children of i are 2i + 1 and 2i + 2, and its parent is floor((i - 1) / 2).

Operation Cost
Read min (max) O(1)
Insert (sift-up) O(log n)
Remove min (sift-down) O(log n)
Build heap bottom-up O(n)
Search for any key O(n)

Inserting 7, 3, 5, 1 into an empty min-heap gives [1, 3, 5, 7]: 1 enters at index 3 and swaps up past 7 and then 3.

Exam angle: a heap is not sorted. In a min-heap the maximum is somewhere among the leaves, so finding it is O(n). Heaps are the usual way to implement a priority queue.

Graphs

A graph G = (V, E) is a set of vertices joined by edges, which may be directed or undirected, weighted or unweighted. A tree is a connected graph with no cycles.

Representation Space Edge (u, v) check List neighbours
Adjacency matrix Θ(V²) O(1) O(V)
Adjacency list Θ(V + E) O(degree) O(degree)

Use a matrix for dense graphs and fast edge checks, and a list for sparse graphs. In an undirected graph the degrees add up to 2E (the handshaking lemma). A simple undirected graph has at most n(n - 1)/2 edges, and a directed one at most n(n - 1). A directed graph has a topological order exactly when it has no cycle (a DAG).

Exam angle: BFS uses a queue and DFS uses a stack or recursion; both run in O(V + E) on an adjacency list.

Common traps

Worked examples

1. Understanding. In a max-heap, which element is at the root? Answer: the largest. Every parent is at least as large as its children, so the maximum cannot sit below anything.

2. Application. Insert 8, 3, 10, 1, 6, 14, 4 into an empty BST. What is the postorder traversal? Answer: 1 4 6 3 14 10 8. Postorder lists the left subtree (1, then 4 and 6 under 3), then the right subtree (14, then 10), then the root 8.

3. Analysis. A social network has 1 million users, each with about 200 friends. Should it use an adjacency matrix? Answer: no. A matrix needs 10¹² cells. An adjacency list stores each friendship twice, about 2 × 10⁸ entries. The graph is sparse, so a list is far smaller.

Practise

The quiz below has 100 questions on this topic, filterable by tier and difficulty.

Practise: 100 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. In a tree, what is a leaf node?

    1. The topmost node
    2. A node with exactly one child
    3. Any node at depth 1
    4. A node with no children
    Show answer

    Answer: D. A node with no children

    A leaf (external node) has no children. The topmost node is the root, and nodes with at least one child are internal nodes.

  2. Which property must every node of a binary search tree (BST) satisfy?

    1. Its key is smaller than both of its children's keys
    2. Its left and right subtrees have equal heights
    3. Keys in its left subtree are smaller and keys in its right subtree are larger
    4. It has either 0 or 2 children
    Show answer

    Answer: C. Keys in its left subtree are smaller and keys in its right subtree are larger

    The BST property applies to whole subtrees, not just the immediate children: everything on the left is smaller and everything on the right is larger (with a fixed rule for duplicates). Parent smaller than children is the min-heap property.

  3. What is the min-heap property?

    1. Every left child is smaller than its parent and every right child is larger
    2. Every parent's key is less than or equal to its children's keys
    3. The tree is sorted when traversed in inorder
    4. All leaves are at the same depth
    Show answer

    Answer: B. Every parent's key is less than or equal to its children's keys

    In a min-heap each node is no larger than its children, so the minimum is always at the root. There is no ordering between siblings, which is why a heap is not a BST and an inorder traversal is not sorted.

  4. How much memory does an adjacency matrix need for a graph with V vertices and E edges?

    1. Θ(V + E)
    2. Θ(E)
    3. Θ(V log V)
    4. Θ(V²)
    Show answer

    Answer: D. Θ(V²)

    An adjacency matrix has one cell for every ordered pair of vertices, V × V, whatever the number of edges. An adjacency list needs Θ(V + E), which is far less for sparse graphs.

  5. Which graph representation is usually preferred for a large sparse graph?

    1. Adjacency list
    2. Adjacency matrix
    3. Incidence matrix
    4. A 2D array of all vertex pairs
    Show answer

    Answer: A. Adjacency list

    A sparse graph has far fewer than V² edges. An adjacency list stores only the edges that exist, Θ(V + E), and lets you iterate over a vertex's neighbours in time proportional to its degree.

  6. In a complete binary tree stored in an array with 0-based indexing, where are the children of the node at index i?

    1. 2i + 1 and 2i + 2
    2. 2i and 2i + 1
    3. i + 1 and i + 2
    4. (i - 1) / 2 and (i + 1) / 2
    Show answer

    Answer: A. 2i + 1 and 2i + 2

    With the root at index 0, the left child is at 2i + 1, the right child at 2i + 2 and the parent at floor((i - 1) / 2). The formulas 2i and 2i + 1 belong to 1-based indexing, which CLRS uses, so check which convention a question assumes.

  7. Which traversal of a BST visits the keys in ascending order?

    1. Preorder
    2. Postorder
    3. Inorder
    4. Level order
    Show answer

    Answer: C. Inorder

    Inorder visits the left subtree, then the node, then the right subtree. By the BST property that means all smaller keys, then the node, then all larger keys, which is sorted order.

  8. What is the worst-case time to search an unbalanced BST with n nodes?

    1. O(n)
    2. O(log n)
    3. O(1)
    4. O(n log n)
    Show answer

    Answer: A. O(n)

    Inserting keys in sorted order produces a skewed tree that is effectively a linked list of height n - 1. A search may then visit every node. Balanced trees such as AVL or red-black trees keep the height at O(log n).

  9. For a binary min-heap with n elements, what are the costs of reading the minimum and of inserting a new element?

    1. O(1) and O(log n)
    2. O(log n) and O(1)
    3. O(1) and O(1)
    4. O(log n) and O(n)
    Show answer

    Answer: A. O(1) and O(log n)

    The minimum is always the root, so reading it is O(1). Insertion places the element at the end of the array and sifts it up at most the height of the tree, which is O(log n) for a complete binary tree.

  10. In any undirected graph, the sum of all vertex degrees equals:

    1. The number of edges
    2. The number of vertices
    3. Twice the number of edges
    4. The number of vertices minus one
    Show answer

    Answer: C. Twice the number of edges

    Each edge has two endpoints, so it adds 1 to the degree of each, contributing 2 to the total. This is the handshaking lemma, and it also implies that the number of odd-degree vertices is always even.

FAQs

Why are trees and graphs called non-linear?

In a linear structure, each element has at most one successor, so you can lay the data out in one line. In a tree a node can have several children, and in a graph a vertex can link to any number of others. Visiting everything therefore needs a traversal strategy such as BFS or DFS.

What is the difference between a BST and a binary heap?

Both are binary trees, but they are ordered differently. A BST orders whole subtrees (left smaller, right larger), so it supports search and sorted traversal. A heap only orders each parent against its children, so it gives fast access to the minimum or maximum but slow search for other keys.

Is every tree a graph?

Yes. A tree is a connected, acyclic, undirected graph with n - 1 edges for n vertices. A rooted tree adds a chosen root, which gives parent and child directions. A collection of disjoint trees is a forest.

When should I use an adjacency matrix instead of a list?

Use a matrix when the graph is dense, with E close to V², or when you need constant-time checks for whether an edge exists. Use a list for sparse graphs, which covers most real networks, because it uses Θ(V + E) memory and iterates over neighbours efficiently.

Next step

Move on to Searching Algorithms MCQs, see all topics on the DSA MCQs hub, or test yourself in an NSCT mock test.