Sorting Flashcards

(6 cards)

1
Q

Bubble sort

A

iterates through array and swaps adjacent numbers if they’re not in order

keeps iterating until we have an iteration with no swaps
O(n^2)

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

Insertion sort

A

build sorted array, shifting elements into the right place as we iterate through once
O(n^2)

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

Selection sort

A

split into sorted and unsorted parts

find smallest element in array and add to end of the already sorted part
O(n^2)

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

Merge sort

A

recursively sort left and right parts of array, merge them together
O(n log n) – space: O(n)

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

Heap Sort

A

convert unsorted array into max heap
(parent - A[i/2], left - A[2i], right - A[2i + 1])

swap first element with last element and remove from heap

heapify swapped element and repeat

O(n log n)

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

Quick Sort

A

choose pivot and swap to end of list

elements smaller than pivot move to the left, elements larger than pivot stay to the right

swap pivot point with counter

repeat of left and right parts

worst O(n^2) – average O(n log n)

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