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 binary search tree, values in the left subtree of a node are:

  1. AEqual to the node's value
  2. BSmaller than the node's value
  3. CLarger than the node's value
  4. DIn random order
2.Easy

In a singly linked list, each node contains:

  1. AData and references to all other nodes
  2. BData and an index
  3. COnly data
  4. DData and a reference to the next node
3.Easy

A graph consists of:

  1. AOnly a root and leaves
  2. BVertices (nodes) connected by edges
  3. CKeys and hashes only
  4. DRows and columns
4.Medium

A trie (prefix tree) is especially efficient for:

  1. AFinding shortest paths
  2. BStoring matrices
  3. CPrefix searches such as autocomplete
  4. DSorting numbers
5.Medium

An application needs fast lookups and also needs to list keys in sorted order and answer range queries. Which structure fits best?

  1. AA stack
  2. BA hash table
  3. CA balanced binary search tree
  4. DAn unsorted linked list
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 dynamic array
  2. BA doubly linked list
  3. CA singly linked list
  4. DA sorted array
7.Hard

Without union by rank or path compression, what is the worst-case cost of a single find in a union-find structure with n elements?

  1. AO(α(n))
  2. BO(n)
  3. CO(log n)
  4. DO(1)
8.Hard

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

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

Answer key

  1. 1. B · Smaller than the node's value
  2. 2. D · Data and a reference to the next node
  3. 3. B · Vertices (nodes) connected by edges
  4. 4. C · Prefix searches such as autocomplete
  5. 5. C · A balanced binary search tree
  6. 6. B · A doubly linked list
  7. 7. B · O(n)
  8. 8. B · 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.