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 main difference between a static array and a dynamic array?

  1. AA static array allows slower index access
  2. BA dynamic array can grow by moving to a larger block of memory
  3. CA static array can only store numbers
  4. DA dynamic array stores its elements in linked nodes so it can grow one at a time
2.Easy

What does each node in a doubly linked list contain?

  1. AData and two pointers, one to the next node and one to the node after that
  2. BTwo copies of the data and one pointer
  3. CData, a pointer to the next node and a pointer to the previous node
  4. DData and a pointer to the next node only
3.Easy

Which operation is slow in an array but fast at the head of a linked list?

  1. AAccessing the 5th element
  2. BInserting at the beginning
  3. CReading the last element by index
  4. DFinding the length of a fixed array
4.Medium

The keys 50, 30, 70, 20, 40 are inserted in this order into an empty binary search tree. What is the left child of 30?

  1. A40
  2. B50
  3. C70
  4. D20
5.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 singly linked list
  3. CA sorted array
  4. DA doubly linked list
6.Medium

AVL trees and red-black trees guarantee:

  1. AThat keys are stored in insertion order
  2. BO(log n) height through rebalancing
  3. CThat no node has two children
  4. DConstant-time search in every case
7.Hard

Deleting a node with two children from a binary search tree is usually done by:

  1. ASwapping it with the root
  2. BRemoving the whole subtree
  3. CRebuilding the subtree below it from scratch and reinserting every key it contained
  4. DReplacing it with its in-order successor (or predecessor) and deleting that node
8.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. ANothing changes, because a key's hash is computed only once when the program starts
  2. BLooking up the object may fail because it sits in the bucket for its old hash
  3. CThe map automatically moves the key to its new bucket
  4. DThe map throws an error at the moment the field changes

Answer key

  1. 1. B · A dynamic array can grow by moving to a larger block of memory
  2. 2. C · Data, a pointer to the next node and a pointer to the previous node
  3. 3. B · Inserting at the beginning
  4. 4. D · 20
  5. 5. D · A doubly linked list
  6. 6. B · O(log n) height through rebalancing
  7. 7. D · Replacing it with its in-order successor (or predecessor) and deleting that node
  8. 8. B · Looking up the object may fail because it sits in the bucket for its old hash

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