Data structures worksheet with answers

Free printable Data structures worksheet: 8 problems from easy to exam level, with an answer key. Print it or save it as a PDF.

For teachers: free to print, copy and use in class. Every new worksheet has new values and its own answer key. A link to ExamProblems on your course page is appreciated.

Name: ____________________   Date: ____________

1.Easy

In a tree, what are sibling nodes?

  1. ANodes that share the same parent
  2. BA node and its parent
  3. CNodes at the same depth in different subtrees
  4. DNodes that have no children
2.Easy

In a hash table, what is a collision?

  1. AThe table runs out of memory
  2. BTwo equal keys are stored twice
  3. CA key cannot be hashed at all
  4. DTwo different keys map to the same index
3.Easy

In a tree, what is a leaf?

  1. AA node with no parent
  2. BA node with exactly one child
  3. CThe node with the largest value
  4. DA node with no children
4.Medium

A road network has 100,000 junctions, each connected to about 4 others. Which representation is most suitable?

  1. AAdjacency matrix
  2. BAdjacency list
  3. CA binary heap of edges
  4. DA single sorted array of vertices
5.Medium

What is the value of the postfix expression 3 4 + 2 * ?

  1. A10
  2. B14
  3. C24
  4. D11
6.Medium

What is true of the adjacency matrix of an undirected graph?

  1. AEach row has exactly one 1
  2. BIt is symmetric about the main diagonal
  3. CIt is always upper triangular
  4. DIts main diagonal always contains ones
7.Hard

Which pair of traversals always determines a unique binary tree with distinct keys?

  1. APreorder alone
  2. BLevel-order alone
  3. CPreorder and postorder
  4. DPreorder and inorder
8.Hard

A dynamic array doubles when full. Why do many implementations shrink it only when it is one quarter full, not half full?

  1. ABecause the memory allocator can only release memory in quarters of a block
  2. BBecause halving at one half would lose elements
  3. CTo keep the array sorted
  4. DTo avoid repeated resizing when pushes and pops alternate near the boundary

Answer key

  1. 1. A · Nodes that share the same parent
  2. 2. D · Two different keys map to the same index
  3. 3. D · A node with no children
  4. 4. B · Adjacency list
  5. 5. B · 14
  6. 6. B · It is symmetric about the main diagonal
  7. 7. D · Preorder and inorder
  8. 8. D · To avoid repeated resizing when pushes and pops alternate near the boundary

Full step-by-step solutions: practise this topic on examproblems.com.