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 singly linked list, what does the next pointer of the last node contain?

  1. ANull (no node)
  2. BThe number of nodes in the list
  3. CThe address of the first node
  4. DThe address of the previous node
2.Easy

What is a deque (double-ended queue)?

  1. AA queue sorted by priority
  2. BTwo separate queues sharing one array
  3. CA queue that only allows removal at the back
  4. DA structure that allows insertion and removal at both ends
3.Easy

What is the name of the stack operation that adds an element to the top?

  1. APush
  2. BPeek
  3. CEnqueue
  4. DPop
4.Medium

An adjacency matrix for a graph with V vertices uses how much memory?

  1. AO(V²)
  2. BO(V + E)
  3. CO(log V)
  4. DO(E)
5.Medium

A hash table of size 7 uses h(k) = k mod 7 and linear probing. After inserting 10, where is 17 stored?

  1. AIndex 3
  2. BIndex 6
  3. CIndex 4
  4. DIndex 0
6.Medium

You have a reference to a node in the middle of a list. In which list can you remove it in O(1)?

  1. AA sorted array
  2. BA singly linked list
  3. CA doubly linked list
  4. DA dynamic array
7.Hard

Kahn's algorithm for topological sorting repeatedly removes vertices with in-degree 0. Which structure holds those vertices?

  1. AA max-heap ordered by out-degree
  2. BAn adjacency matrix recording which vertices have already been removed
  3. CA stack of all visited edges
  4. DA queue (or any collection) of vertices whose in-degree is 0
8.Hard

How does a radix tree (compressed trie) improve on a plain trie?

  1. AIt stores each word in a hash table at the root instead of in separate nodes
  2. BIt keeps only the first letter of each word
  3. CIt sorts the children of each node by frequency
  4. DIt merges chains of single-child nodes into one edge labelled with a string

Answer key

  1. 1. A · Null (no node)
  2. 2. D · A structure that allows insertion and removal at both ends
  3. 3. A · Push
  4. 4. A · O(V²)
  5. 5. C · Index 4
  6. 6. C · A doubly linked list
  7. 7. D · A queue (or any collection) of vertices whose in-degree is 0
  8. 8. D · It merges chains of single-child nodes into one edge labelled with a string

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