

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Project; Class: Introduction to Computing Using MATLAB; Subject: Computer Science; University: Cornell University; Term: Fall 2008;
Typology: Study Guides, Projects, Research
1 / 3
This page cannot be seen from the preview
Don't miss anything!


You must work either on your own or with one partner. You may discuss background issues and general solution strategies with others, but the project you submit must be the work of just you (and your partner). If you work with a partner, you and your partner must first register as a group in CMS and then submit your work as a group.
To gain familiarity and experience in the following:
You will implement various sorting algorithms for this assignment. Sorting a group of elements is extremely common in programming for many reasons:
Bubble sort is one of the simplest sorting algorithms. It works by repeatedly iterating thru the array to be sorted, comparing two adjacent numbers in the array, and swapping them if they are in the wrong order. The iterations thru the list are repeated until no swaps are needed, which means that the array is sorted. In order to implement bubble sort, you can decompose the problem into smaller sub problems:
b) Implement the bubble sort function by completing BubbleSort.m. You must use the ProperOrder and SwapElements functions wherever possible in your implementation. Submit ProperOrder.m, SwapElements.m and BubbleSort.m to CMS.
Merge sort is another famous sorting algorithm. We will not be implementing merge sort in its full beauty. Instead, we will implement PMerge sort, a sorting algorithm that takes advantage of one of the core ideas used in real merge sort.
An algorithm’s complexity refers to the number of computer operations executed when it is run. For this question you will analyze the complexity of the sorting algorithms that we’ve implemented. We will use the number of swaps made to sort the array as the measure the complexity of each sorting algorithm; the less swaps used to sort the array, the less complex the sorting algorithm is. Note that low values of complexity is desired as algorithms that require fewer operations will take less time to run. For each of the sorting algorithms you implemented, you will generate arrays of random numbers and record the number of swaps used by Bubble sort, and by PMerge sort. You will need to vary the sizes of the arrays generated, and plot, on the same graph, the complexity of both algorithms vs. the length of the array. The plot must be properly labeled with a title, axis labels, and a legend. a) First, we should solve the problem of generating random arrays. To do this, complete the function found at GenerateArray.m b) Use the GenerateArray function to implement the function in CompareSorts.m More detailed descriptions of these functions are found in the m‐files provided. Bubble sort is so named because of the way larger numbers ‘bubble’ to the end of the array. Merge sort gets its name from this crucial ‘merge’ step