











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
An introduction to sorting algorithms, explaining what sorting is, why it is important, and the primary types of sorting algorithms. It also covers the concept of time and space complexity and provides examples of common big-oh notations. The document concludes with a discussion on stable and unstable sorting algorithms and their implications.
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












Docsity.com
Docsity.com
Types of Sorting Algorithms
There are many, many different types of sorting
algorithms, but the primary ones are:
● Bubble Sort ● Selection Sort ● Insertion Sort ● Merge Sort ● Shell Sort ● Heap Sort
● Quick Sort ● Radix Sort ● Swap Sort
Docsity.com
Review of Complexity
Most of the primary sorting algorithms run on different space and time complexity.
Time Complexity is defined to be the time the
computer takes to run a program (or algorithm in
our case).
Space complexity is defined to be the amount of memory the computer needs to run a program.
Docsity.com
●An algorithm or function T(n) is O(f(n)) whenever
T(n)'s rate of growth is less than or equal to f(n)'s
rate.
●An algorithm or function T(n) is Ω(f(n)) whenever
T(n)'s rate of growth is greater than or equal to
f(n)'s rate.
●An algorithm or function T(n) is Θ(f(n)) if and
only if the rate of growth of T(n) is equal to f(n).
O(n), Ω(n), & Θ(n)
Docsity.com
Common Big-Oh’s
Time complexity Example O(1) constant Adding to the front of a linked list O(log N ) log^ Finding an entry in a sorted array O( N^ ) linear^ Finding an entry in an unsorted array O( N log N ) n-log-n Sorting n items by ‘divide-and-conquer’ O( N 2 ) quadratic Shortest path between two nodes in a graph O( N 3 ) cubic Simultaneous linear equations
(Binary) Finding 8:
9
50
22
21
8
5
1
(Linear) Finding 8:
9
50
22
21
8
5
Front 1 Initial: Final: 63
http://www.cs.sjsu.edu/faculty/lee/cs146/23FL3Complexity.ppt Docsity.com
Time Efficiency
90% of the execution time of a program is spent in executing 10% of the code
Docsity.com
Time Efficiency
Improvements
Possibilities (some better than others!)
(just good programming!)
are expensive time-wise)
Moral - Choose the most appropriate algorithm(s) BEFORE
program implementation
Docsity.com
Unstable sort algorithms
Bob
Ann
Joe
Zöe
Dan
Pat
Sam
original array
Bob
Ann
Joe
Zöe
Dan
Pat
Sam
unstably sorted
www.cis.upenn.edu/~matuszek/cit594-2002/ Slides/searching.ppt Docsity.com
Selection Sorting
Step:
rio.ecs.umass.edu/ece242/slides/lect-sorting.ppt^5 7 8 10 20 Docsity.com
Insert Action: i=
temp
i = 1, first iteration
rio.ecs.umass.edu/ece242/slides/lect-sorting.ppt Docsity.com
Insert Action: i=
temp
5
i = 2, second iteration
rio.ecs.umass.edu/ece242/slides/lect-sorting.ppt Docsity.com
Insert Action: i=
temp
i = 4, forth iteration
rio.ecs.umass.edu/ece242/slides/lect-sorting.ppt Docsity.com