Computers in Engineering - 308-208 Lecture 21
Computers in Engineering - 308-208


Lesson 21 - Learning Goals



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
Go back to lecture menu
Browse other websites on this topic

Copyright © 1996 McGill University. All rights reserved.