11
As an example of developing a complete program, today we write a “selection sort” algorithm. See Chapter 8. Sorting is very important. For example, it is used in Google’s indexing of web sites to speed searches See this web simulation of sorting algorithms https://www.toptal.com/developers/sorting-algorithms

As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

As an example of developing a complete program, today we write a “selection sort” algorithm.See Chapter 8.

Sorting is very important. For example, it is used in Google’s indexing of web sites to speed searches

See this web simulation of sorting algorithms https://www.toptal.com/developers/sorting-algorithms

Page 2: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

Ready to click “Play All” next

Page 3: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

THESE HAVE ALREADY FINISHEDPART WAY THROUGHTHE SORT

Page 4: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

I often start with sketching and outlining the problem on a piece of paper.

Here, we start working on the “Selection Sort” algorithm

In the next slides, we use “temp” instead of “a” for the swap variable name

Page 5: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

start by outlining with comments, write a line or two, then test

Page 6: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

In order to do more scans of the vector, weneed to make this into a variable… this is also aproblem if v(1) is the lowest value since lowValue andlowVindex will be unknown variables in the fprintf’s

Page 7: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations
Page 8: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations
Page 9: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

convert some more numeric constantsto variables

Page 10: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

Now, repeat scanning the vector

Page 11: As an example of developing a complete program, today we ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20180824.pdfSorting AlgorithmsAnimations The following animations

now that we are done, we can comment the rng lineand get a new vector each run