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 a weighted graph?

  1. AA graph in which each edge has a numeric value such as a cost or distance
  2. BA graph with more edges than vertices
  3. CA graph that is stored on disk
  4. DA graph in which some vertices are heavier than others because they have more edges
2.Easy

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

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

What is the name of the queue operation that removes the element at the front?

  1. APush
  2. BEnqueue
  3. CDequeue
  4. DInsert
4.Medium

A node in a binary search tree has a right subtree. Where is its in-order successor?

  1. AIts parent, always
  2. BThe leftmost node of its right subtree
  3. CIts right child, always
  4. DThe rightmost node of its left subtree
5.Medium

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

  1. AIts main diagonal always contains ones
  2. BEach row has exactly one 1
  3. CIt is symmetric about the main diagonal
  4. DIt is always upper triangular
6.Medium

A queue is implemented with two stacks: push onto an "in" stack, and pop from an "out" stack, refilling it from "in" when empty. What is the amortised cost per operation?

  1. AO(1)
  2. BO(log n)
  3. CO(n)
  4. DO(n²)
7.Hard

For a hash table to work correctly, which rule must hash and equality follow?

  1. AHash values must be prime numbers
  2. BEqual hash values imply equal keys
  3. CDifferent keys must have different hash values
  4. DEqual keys must have equal hash values
8.Hard

Which property keeps every B-tree perfectly balanced?

  1. AThe keys are stored only in the root
  2. BAll leaves are at the same depth
  3. CEvery node has exactly two children
  4. DEach node stores one key

Answer key

  1. 1. A · A graph in which each edge has a numeric value such as a cost or distance
  2. 2. A · Push
  3. 3. C · Dequeue
  4. 4. B · The leftmost node of its right subtree
  5. 5. C · It is symmetric about the main diagonal
  6. 6. A · O(1)
  7. 7. D · Equal keys must have equal hash values
  8. 8. B · All leaves are at the same depth

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