Question: Sorting is a very important concept in computer science. The basic idea is that an unsorted list of numbers is assigned to a vector. The
Sorting is a very important concept in computer science. The basic idea is that an unsorted list of numbers is assigned to a vector. The numbers are then ordered by a process which essentially passes through the vector many times swapping consecutive elements that are in the wrong order, until all elements are in the right order 1. 2. 3. Generate a random vector X of numbers of length N Set N to the length of X Repeat N-1 times with the counter K a. Repeat N -K times with counter J b. If xj> Xj-1 then i. Swap the contents of Xj and Xj+1 4. Stop since the list is sorted Submit your program in a well-document MATLAB script bubbleSort.m. Here the program should NOT use MATLABs vectorizing commands Hints: Make sure your program works for N-5 first. Print out the vector (during program debugging) each time through the sort. Suppress the vector display whern timing (profiling) your code below After the program is working, determine the time it takes to sort 200 random numbers using the built in commands tic and toc. Compare it to the time it takes MATLAB to perform the sort using the sort command. Why is there a discrepancy? Sort the N = 5 element column vector 3 9 222 1 1 9 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
