Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sorting algorithms.

Similar presentations


Presentation on theme: "Sorting algorithms."— Presentation transcript:

1 Sorting algorithms

2 Outline In this lesson, we will: Describe sorting algorithms
Given an overview of existing algorithms Describe the sorting algorithms we will learn

3 Sorting Given an array that has arbitrary entries,
int array[10]{82, 25, 32, 85, 16, 36, 40, 4, 28, 7}; the entries are not in order Can we reorder the entries in the array to produce the sorted array ? Such an algorithm is described as a sorting algorithm 1 2 3 4 5 6 7 8 9 82 25 42 85 16 32 28 1 2 3 4 5 6 7 8 9 16 25 28 32 42 82 85

4 Sorting algorithms There are many different sorting algorithms
selection sort insertion sort shell sort comb sort gnome sort heap sort merge sort quick sort bucket sort radix sort cube sort block sort There are even humorous ones: bozo sort bogo sort stooge sort Some sorting algorithms are worse than others: bubble sort If you have ever learned bubble sort, please forget it… Even Barack Obama knows not to use bubble sort

5 Sorting algorithms We will look at three algorithms:
Selection sort Insertion sort Bucket sort Each of these algorithms has something to commend it, but each also has issues There is no perfect one-size-fits-all sorting algorithm Each algorithm has its own benefits and drawbacks Except bubble sort: its only redeeming feature is a memorable name In a final subsequent set of lectures, we will look at merge sort

6 Sorting algorithms The function declaration of each sorting algorithm will be similar: template <typename T> void algorithm_name( T array[], std::size_t const capacity ); Only the capacity is declared constant—it should not change The entries of the array will be changed by the algorithm

7 Summary Following this lesson, you now
Understand the definition of a sorting algorithm Know the signature that these algorithms will use

8 References [1] Wikipedia [2] nist Dictionary of Algorithms and Data Structures

9 Colophon These slides were prepared using the Georgia typeface. Mathematical equations use Times New Roman, and source code is presented using Consolas. The photographs of lilacs in bloom appearing on the title slide and accenting the top of each other slide were taken at the Royal Botanical Gardens on May 27, 2018 by Douglas Wilhelm Harder. Please see for more information.

10 Disclaimer These slides are provided for the ece 150 Fundamentals of Programming course taught at the University of Waterloo. The material in it reflects the authors’ best judgment in light of the information available to them at the time of preparation. Any reliance on these course slides by any party for any other purpose are the responsibility of such parties. The authors accept no responsibility for damages, if any, suffered by any party as a result of decisions made or actions based on these course slides for any other purpose than that for which it was intended.


Download ppt "Sorting algorithms."

Similar presentations


Ads by Google