Selection Sort Algorithm - Laboratory 7 | CISC 106, Lab Reports of Computer Science

Material Type: Lab; Class: General Computer Science for Engineers; Subject: Computer/Information Sciences; University: University of Delaware; Term: Spring 2009;

Typology: Lab Reports

Pre 2010

Uploaded on 09/02/2009

koofers-user-okt
koofers-user-okt 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab 7
CISC 106, Spring 2009
1.(30 points) Write the Selection Sort algorithm first in pseudocode in a text editor (emacs) and save it in
a .txt file called pseudoSelectionSort.txt . Then implement the Selection Sort algorithm in a function
that takes as its input an array of random integers. Call this function selectionSort1.m Use the following
code to generate a 10 element array of random integers.
input = round(rand(1,10)*100);
Call your selection sort algorithm using the 10 element random number array as input. Your function
should print out the unsorted input array you began with and sorted array at the end. Create a diary,
selectionDiary.txt, of you creating the random input from the command window and calling
selectionSort1.m .
2. (30 points) Write a second function called selectionSort2.m . Create a new pseudocode file for this
algorithm called pseudoSelectionSort2.txt . How would you modify your earlier pseudocode to
accommodate the following problem? This function will sort one dimension of a two dimensional array
but will use the second dimension as a tie breaker if elements in the first dimension are equal. Create a
random two dimensional array with the command : -
input = round(rand(2,10)*10);
Call your second selection sort algorithm using the 20 element random number array as input.
Your function should print out the unsorted input array you began with and sorted array at the end.
Create a diary selection2Diary.txt of you creating the random input from the command window and
calling selectionSort2.m
3.Using the MATLAB patch function. The patch command can be used to draw one or more polygons by
defining the coordinates of its vertices. You can use this command to draw shapes on a plot. e.g. goldfish
or a shark.
Type the following into the graphical MATLAB interpreter:
patch([6 7 7 6], [6 6 7 7], 'g')
What do you see? The first array is the x-coordinates and the second array is the y-coordinates. E.g. the
points respectively would be (6,6), (7,6), (7,7), (6,7). These points form a square. What does the g
mean? What are the bounds of your current plot?
Now type:
pf2

Partial preview of the text

Download Selection Sort Algorithm - Laboratory 7 | CISC 106 and more Lab Reports Computer Science in PDF only on Docsity!

Lab 7

CISC 106, Spring 2009

1.(30 points) Write the Selection Sort algorithm first in pseudocode in a text editor (emacs) and save it in a .txt file called pseudoSelectionSort.txt. Then implement the Selection Sort algorithm in a function that takes as its input an array of random integers. Call this function selectionSort1.m Use the following code to generate a 10 element array of random integers.

input = round(rand(1,10)*100);

Call your selection sort algorithm using the 10 element random number array as input. Your function should print out the unsorted input array you began with and sorted array at the end. Create a diary, selectionDiary.txt , of you creating the random input from the command window and calling selectionSort1.m.

  1. (30 points) Write a second function called selectionSort2.m. Create a new pseudocode file for this algorithm called pseudoSelectionSort2.txt. How would you modify your earlier pseudocode to accommodate the following problem? This function will sort one dimension of a two dimensional array but will use the second dimension as a tie breaker if elements in the first dimension are equal. Create a random two dimensional array with the command : -

input = round(rand(2,10)*10);

Call your second selection sort algorithm using the 20 element random number array as input. Your function should print out the unsorted input array you began with and sorted array at the end. Create a diary selection2Diary.txt of you creating the random input from the command window and calling selectionSort2.m

3.Using the MATLAB patch function. The patch command can be used to draw one or more polygons by defining the coordinates of its vertices. You can use this command to draw shapes on a plot. e.g. goldfish or a shark.

Type the following into the graphical MATLAB interpreter:

patch([6 7 7 6], [6 6 7 7], 'g')

What do you see? The first array is the x-coordinates and the second array is the y-coordinates. E.g. the points respectively would be (6,6), (7,6), (7,7), (6,7). These points form a square. What does the ‘g’ mean? What are the bounds of your current plot?

Now type:

patch([8 9 9 8], [8 8 9 9], 'b')

This draws another square up and to the right of the first square.

Assignment:

(5 points) Now draw a red triangle and a green pentagon on the same plot using the patch command. Make sure the two shapes are not touching. Print out your plot as a png file titled twoShapes.png.

(5 points) Save your commands as a script file called twoShapes.m.

(20 points) Now draw an 8 by 8 checkerboard using either for or while loops and ONLY ONE patch command inside the loop(s). Your checkerboard will alternate between red and blue squares. Save this as a script file called drawCheckerboard.m.

For more information about the patch command see: www.mathworks.com/access/helpdesk/help/techdoc/ref/ patch .html