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. AThe number of nodes in the list
  2. BNull (no node)
  3. CThe address of the previous node
  4. DThe address of the first node
2.Easy

How are the elements of an array stored in memory?

  1. AIn a tree of memory pages
  2. BScattered, linked by pointers
  3. CIn random locations chosen by a hash
  4. DIn one contiguous block, one after another
3.Easy

What is the root of a tree?

  1. AA node with no children
  2. BAny node in the middle
  3. CThe top node with no parent
  4. DThe node with the largest value
4.Medium

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

  1. AIts main diagonal always contains ones
  2. BIt is always upper triangular
  3. CEach row has exactly one 1
  4. DIt is symmetric about the main diagonal
5.Medium

Which data structure does a running program use to keep track of active function calls and their local variables?

  1. AA hash table of functions
  2. BThe call stack
  3. CThe heap memory queue
  4. DA binary search tree of frames
6.Medium

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

  1. AA binary search tree
  2. BA hash table
  3. CA queue
  4. DA stack
7.Hard

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

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

Which data structure supports an LRU (least recently used) cache with O(1) get and put?

  1. AA single sorted array
  2. BA binary search tree only
  3. CA stack only
  4. DA hash map combined with a doubly linked list

Answer key

  1. 1. B · Null (no node)
  2. 2. D · In one contiguous block, one after another
  3. 3. C · The top node with no parent
  4. 4. D · It is symmetric about the main diagonal
  5. 5. B · The call stack
  6. 6. D · A stack
  7. 7. A · Expected O(log n) search by using several levels of forward pointers
  8. 8. D · A hash map combined with a doubly linked list

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