CMPU-235: Software Development Methodology

Homework #4

Due: Wednesday, Nov. 30

Email your answers to the following questions to me (weltyc@cs.vassar.edu) before midnight on Wednesday. The answers to most questions involve identifying a C++ STL class that is most appropriate for solving the stated problem. Some may require designing simple data structures of your own. Some may require both. In cases where your own data structure is appropriate, show only the data members of the class (unless specifically directed otherwise).

  1. You are contracted by the NFL to develop software for keeping track of statistics for NFL teams. Your program will keep track, for each team, of the win/loss record of the team versus each other team in the league. In other words, the NY Jets won 2 and lost 0 versus the Miami Dolphins, however they won 1 and lost 1 versus the Buffalo Bills. A few teams will not play each other.
    What data structure(s) would you use to store this information in your program (i.e. not on a disk)? Show an example of assignment statements for the NY Jets record against the Miami Dolphins above.

  2. You are now asked to modify your program from the previous question to track the number of points scored for and against each team versus each other team. In other words, the NY Jets scored 50 points (for) and gave up 40 points (against) versus the Miami Dolphins.
    How would you change the data structures from the previous question? Would you use a different container? Why?

  3. NASA is testing a new deep-space probe, DS-2, that, like its predecessor DS-1, has on-board intelligence for following through on simple plans of action. The probe must consider all the actions it is capable of taking, what their consequences may be, and what actions should follow, and their consequences, etc. For example, one plan might be that the probe could turn on the camera, then rotate, then turn off the camera. Another could be that it would rotate, turn on the camera, then turn off the camera. The important difference between these two plans are the intermediate states that occur between each step. It needs to consider many such plans to determine which one is the best for meeting its goals.
    During testing, the engineers want accountability - they want to know all the choices considered in coming up with a particular plan. What data structure would you use to represent all the possible situations the probe considers?

  4. A program is being developed to rapidly solve the "15-puzzle" problem. A 15-puzzle is a 4x4 grid of tiles, with one empty space in the grid. Any of the 2-4 tiles neighboring the empty space (2 if the space is in the corner, 3 if its on one of the edges, 4 if its in one of the middle spaces) can move into it, generating a new board configuration. The goal is to start from some random initial configuration and get to a configuration in which the numbered tiles are in some order in the shortest number of moves.
    The programmers are using a special search algorithm to find the best solution quickly, however their algorithm requires checking whether a given board configuration has already been visited by the search - this is because there are potentially a large number of cycles in the moves. For example, you may move a tile down into the empty space, and then move it right back to where it was. Or, you may move three tiles in an endless circle.
    While they are working on their algorithm, they would like you to develop a way for testing whether a configuration has already been generated. They will send your function an array of 16 integers, representing the configuration of the tiles in the puzzle reading left to right across the top row in array positions 0-3, then the second row in array positions 4-7, and so on. The value in each array position corresponds to the tile number in that board position, with 0 representing the blank. Your function will return true if the configuration has been seen before, and false if not.
    To "remember" all the configurations your function has been passed, you will need a static or global data structure of some kind. What would you use?

  5. The programmers from the previous question add a new constraint to your function. Speed is of the utmost importance. Could you make your function work in log time? What data structure would you use and how would you make it work - describe any supporting functions you might need.

  6. Could you make your function from the previous question work in constant time? If yes, describe precisely the data structure you would use and any supporting functions you might need.

  7. A print shop is implementing a new on-line printing service offered over the web. Scheduling of submitted print jobs on their three high-capacity digital printers will be done automatically. Generally speaking, jobs will be printed in the order they are received (with one exception), and once a job is released from the scheduling system to the printer it can not be preempted. The scheduling system will re-order jobs in one case: when a small job (less than 50K) is received, it will be released to a printer before any big jobs (greater than 5MB).
    What data structure would you use for the scheduling system to store the jobs? Describe precisely any supporting functions you might need. Assume there is a "printJob" class with a public method called "Size()" that returns the size of the job.

  8. A bitmap is a graphic image stored as bits. Each x,y position of a 2D image is stored as an integer from 0-255 whose value corresponds to the color of the pixel at that point. The important operations in accessing a bitmap are setting the color value of a particular x,y position, and reading the color value of a particular x,y position. These operations must be as fast as possible.
    What data structure would you use to store bitmaps?

Note: Collaboration is acceptable on this homework to gather a sense of understanding for the questions, however what you hand in must be your own work.