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

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

  1. APush
  2. BPeek
  3. CPop
  4. DEnqueue
2.Easy

A graph consists of:

  1. AOnly a root and leaves
  2. BKeys and hashes only
  3. CVertices (nodes) connected by edges
  4. DRows and columns
3.Easy

Which operation is O(1) for an array but O(n) for a singly linked list?

  1. AInserting at the head
  2. BRemoving the head element
  3. CReading the first element
  4. DAccessing the element at index i
4.Medium

How much memory does an adjacency list use for a graph with V vertices and E edges?

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

Which data structure is used to check whether the brackets in "{[()]}" are balanced?

  1. AA binary search tree
  2. BA stack
  3. CA queue
  4. DA hash table
6.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 single sorted array of vertices
  4. DA binary heap of edges
7.Hard

An object is stored as a key in a hash map, and then a field used by its hash function is changed. What is the likely result?

  1. ALooking up the object may fail because it sits in the bucket for its old hash
  2. BNothing changes, because a key's hash is computed only once when the program starts
  3. CThe map automatically moves the key to its new bucket
  4. DThe map throws an error at the moment the field changes
8.Hard

What is the main advantage of a skip list over a sorted linked list?

  1. AIt stores keys without order
  2. BExpected O(log n) search by using several levels of forward pointers
  3. CIt uses no extra memory
  4. DGuaranteed O(1) search because every node stores a pointer to every other node

Answer key

  1. 1. A · Push
  2. 2. C · Vertices (nodes) connected by edges
  3. 3. D · Accessing the element at index i
  4. 4. D · O(V + E)
  5. 5. B · A stack
  6. 6. B · Adjacency list
  7. 7. A · Looking up the object may fail because it sits in the bucket for its old hash
  8. 8. B · Expected O(log n) search by using several levels of forward pointers

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