21.1 Learn why sorting is useful
21.2 Learn several different Sorting Techniques
21.3 Learn how to compare different sorting algorithms
SORTING
INTRODUCTION
ORDER NOTATION
FOR SORTING:
BUBBLE SORT
A(1) small
A(2) .
A(3) .
.
A(n) big
BUBBLE SORT ALGORITHM
for i = 1 to n do
for j = n down to i + 1 do
if A[j] < A[j-1] then
Swap(A[j] , A[j-1])
INSERTION SORT
ALGORITHM FOR INSERTION SORT
A[0] = -MaxInt
for i = 2 to n do begin
j = i
while A[j] < A[j-1] do begin
Swap(A[j], A[j-1])
j = j - 1
end
end
SELECTION SORT
ALGORITHM FOR SELECTION SORT
for i = 1 to n - 1 do begin
j = i
Min = A[i]
for k = i + 1 to n do
if A[k] < Min then begin
Min = A[k]
j = k
end
end
Swap( A[i], A[j])
end
SHELL SORT
BETTER ALGROITHMS
On to the next lecture
(g(n)) if running time
is greater than d g(n) (where d is a positive constant) for some
input of size n. O provides an upper bound on running time, while
provides a lower bound.
Go back to lecture menu
Browse other websites on this topic