EECS 183 Lecture Notes - Lecture 10: Bubble Sort, Insertion Sort, Bort
1
EECS 183 Full Course Notes
Verified Note
1 document
Document Summary
Bubble sort: sort n things in an array called a . For i = n - 1 to 1. For j = 0 to i 1. Swapped = true: worst sorting method you could do but easiest to use, uses selection (for) and iteration (if, highest number bubbles up to the top. Swapped until it reaches the top, repeated until everything is in. Insertion sort order: sort n things in an array called a . For i = 1 to n 1. Do while (j > 0) and (a(j) < a(j 1) J = j - 1: maintains a hand of cards that are already sorted. Start at the highest value and go as far as you need to get in order to insert the new value into its correct spot: has an optimization built in that bubble does not. Bubble vs. insertion sort: complexity analysis for both.