2.2 Introduction to Algorithms started from https://brilliant.org/courses/computer-science-algorithms/array-algorithms-2/insertion-sort-algo/1/
started from https://brilliant.org/courses/computer-science-algorithms/array-algorithms-2/insertion-sort-algo/1/
Selection sort animations:
https://www.youtube.com/watch?v=n7eyTv2k_-k
#SELECTION sorting Algorithm
PSEUDO selection sort .
input: A, an array of numbers
for current from 0
to length of A - 2:
set minIndex to current
for i from current + 1
to length of A - 1:
if A[i] < A[minIndex]:
set minIndex to i
swap A[current]
and A[minIndex]
Comparing Algorithms
Which algorithm should we expect will do better, on average, on arrays of size 10,000?
Suppose that we tweak the implementations of these sorting algorithms and test on arrays of size 100 again. This time we find that selection sort is twice as fast as insertion sort.
a new sorting algorithm called mystery sort, which has a best-case, worst-case, and average-case cost of
We test the implementation of mystery sort along with an implementation of selection sort on arrays of size 100, and find that mystery sort is five times faster.
runtimes are in
Comments
Post a Comment