270 likes | 379 Views
Introductory Algorithms. Lecture 01: Sorting Algorithms April 8 th , 2009 Jonathan Tse. Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up. Sort Playing Cards. Sorting Order Sort into Suits Clubs, Diamonds, Hearts, Spades Sort Suits
E N D
Introductory Algorithms Lecture 01: Sorting Algorithms April 8th, 2009 Jonathan Tse Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Sort Playing Cards • Sorting Order • Sort into Suits • Clubs, Diamonds, Hearts, Spades • Sort Suits • A 2 3 4 5 6 7 8 9 10 J Q K • Rules Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Post-Sort Discussion • What was different about how you sorted? • Which way was harder/more time consuming? • Which way took up more physical space? • Was one way clearly better than another? • Was one way better in a given situation? Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Post-Sort Discussion • Moving 1 Card == 1 Processor Action • Memory Space == Physical Space • Tradeoff Between: • Number of Processor Actions • Memory Space Used Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort Working Space 23 17 45 18 12 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort 23 23 Working Space 17 45 18 12 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort Working Space 17 23 23 23 45 18 12 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort Working Space 45 45 17 23 18 12 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort Working Space 18 17 23 23 45 23 45 12 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort Working Space 12 17 17 17 18 23 18 23 45 45 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort Working Space 22 12 17 18 23 23 45 23 45 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Insertion Sort Done! 12 17 18 22 23 45 Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Working Space 23 17 45 18 12 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Working Space 23 12 17 45 18 12 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Working Space 17 17 12 45 18 23 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Working Space 45 18 12 17 23 22 Array Space 18 Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Working Space 45 22 12 17 18 23 22 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Working Space 23 23 12 17 18 22 45 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Working Space 45 45 12 17 18 22 23 Array Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Selection Sort Done! 12 17 18 22 23 45 Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Merge Sort Array Space Working Space Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Merge Sort Array Space Working Space Done! Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Radix Sort 12 17 18 22 23 12 22 37 23 36 Done! 45 Working Space 45 36 17 37 18 Array Space 12 23 17 17 18 45 18 22 23 12 22 36 37 37 36 45 Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Summary of Sorting Algorithms • Insertion Sort • Selection Sort • Merge Sort • Radix Sort Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms– Wrap Up
Wrap-Up • Was there anything in particular you noticed about the algorithms? • Is one better than the other? • In what situation is one better than the other? • How do we objectively compare these algorithms? Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Wrap Up • Is there some comparison metric? • Can we quantify memory usage? • What about execution time? • Does the list to be sorted affect anything? • Is there a worst case? Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up
Next Time • Standard Metrics for Algorithm Performance • Worst Case Analysis Overview – Sorting Activity – Post Sort Discussion – Sorting Algorithms – Wrap Up