Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions