Name(s) & ID(s):_________________________________________________________
Assignment P4
CS 100 – Summer 1999
Due: Thursday July 29, 1999 at the beginning of class.
NOTE: YOU MUST WORK WITH A PARTNER ON THIS ASSIGNMENT.
Turn in your assignments according to the instructions given in the first day handout. Remember to include sample output when you turn in your program listings. Also turn in a disk with a runnable version of your code (the same as what you've printed). Remember that you will be graded on both style and correctness.
Write a program that will test your modified algorithms on a representative sample of input (part of this problem is to come up with such a representative sample) and then output to the user the information you gather in a meaningful format such as:
List length list properties # comps # exchanges # loops
Select
Insert
Bubble
Quick
Select
Insert
Bubble
Quick
. . .
It may be the case that you'll come up with a snazzier way to present your output. Go for it. Note: You should use more meaningful variable names and comments in your implementation of these algorithms than what were presented on the slides in class.
Start up Matlab and do the following problems. Just type the appropriate commands in the command window. For each question, do the assignments and calculations in the order in which they are given. Do not type a semi-colon at the end of any lines unless we tell you to do so. That way the values of the variables and matrices you create will be displayed. Type a return at the end of each line.
What to Turn In: Follow the directions given and turn in a copy of the Matlab command window, any graphs you produce, and all the files you create. The printouts should only show the calculations requested in the assignment; please don't turn in your experiments, false starts, and other work. however, if you make a typo or other small error at some point, you don't need to start over. Just fix the error, and cross out anything you don't want the grader to look at.
Your answers should be in the right order. Please use either Matlab comments (beginning with a % sign) or legible hand-written annotations to number your answers. The command window printout should include the commands used to produce the various plots.
For more information on Matlab, be sure to check out the course website for a handout that provides some Matlab hints and experiments.
6 3 -2 5
3 0 4 -6
-5 2 7 -1
g) Create a new matlab function (.m file) called pos. The result of a function call pos(M) should be a matrix of ones and zeros the same size as M, with a one everywhere that m contained a positive integer. For example, if even is called on the M from problem 4, the result would be
1 1 0 1
1 1 1 0
0 1 1 0
Test your function on the following matrix:
5 -3 2 -1
4 1 -5 -6
-2 0 1 3