ch 7 sorts Flashcards

1
Q

insertion sort

A
5 4 3 2 1
4 5 3 2 1
3 4 5 2 1 
2 3 4 5 1 
1 2 3 4 5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

heapsort

A

used in priortiy queue
call delete max
instead of deleting the first element, simply put it to the back of the array
therefore, you will end up with an array of sorted decreasing numbers
97 53 39 26 41 58 31
53 39 26 41 58 31 97
NlogN?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Mergesort

A

O(Nlogn)
splits large array up so each individual index is its own array
compares indexes of the left and right sides, adds to a slightly larger array
continues doing this until there is only one array left

5263
5 2 6 3
25 36 
5 36            2
5 6              23
6                 235
2356
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

picking the pivot for quicksort

A

median of three
pick the first, last, and center index
the median of the three is the pivot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

quicksort

A

pick a pivot
move it to the very end
i (left pointer) should be smaller than pivot
j (right pointer) should be larger than pivot
if both i and j are incorrect, swap the two
when j passes i, swap i with the pivot
call quicksort on the left and right pivots

worst case N^2
average case NlogN

look at notes for review onn ccode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly