Quiz 5

Question 1 of 3

Recall that, so far, we’ve seen at least two ways to store a sequence of values: arrays and linked lists.

  1. What’s one advantage that using an array has over using a linked list?
  2. What’s one advantage that using a linked list has over using an array?

Question 2 of 3

Recall from lecture that looking up a value in a hash table takes O(n) (i.e., linear) time. We also saw that looking up a value in a linked list takes linear time, too. If both data structures require linear time to look up a value, why might we prefer a hash table nevertheless?

Question 3 of 3

Recall that in lecture, we saw how Jack could use a queue or a stack to organize his clothing. Consider other real-world scenarios where you might want to store physical objects or data using a queue or a stack.

  1. Give an example of a real-world scenario where you might want to store physical objects or data in a stack. Why is a stack the preferred data structure to use for that use case?
  2. Give an example of a real-world scenario why you might want to store physical objects or data in a queue. Why is a queue the preferred data structure to use for that use case?