CPSC 327 Data Structures and Algorithms Spring 2024

Homework 8
due Wed 2/14 in class

  1. ADM 3-4, page 103.

  2. ADM 3-8, page 103. "...accepts a sequence of moves, and reports in constant time whether the last move won the game" means that the data structure should support "make a move" and "game over?" operations.


About "design/create a data structure" problems: describe what is stored and how, and explain how the desired operations are carried out and how the desired running time is achieved. "What is stored and how" includes the data structure containing the elements, how the elements are arranged in the data structure, and any other information stored. For "how the desired operations are carried out", you don't need to explain how standard data structure operations are done (like inserting an element at a particular position in an array), but you do need to explain how the operations of your data structure are carried out in terms of the "what is stored and how" structure and variables. Similarly, you don't need to explain the running time of standard data structure operations, but you do need to explain the running time of how your data structure's operations are carried out.

For example, consider how to implement an O(1)-time array-based queue:

At times, such as with the queue example above, it may be clearer and easier to use pseudocode to express some or all of the operations. That's fine. The key thing is to be aware that more detail is not necessarily beneficial — you need to express the algorithm with sufficient detail to be understood and to assess running time and correctness, but too many details overwhelms the ideas and obscures understanding. Review your writeup with an eye as to whether the detail you've included is necessary or if things could be expressed at a higher level of abstraction.