Sorting Flashcards

1
Q

Describe how insertion sort works

A
start off from the left
sort ONE element first, then sort TWO elements
we'll have a SORTED list on the left
Adv:
- less swaps
- works well on mostly sorted lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe how selection sort works

A

Choose the largest number and swap it with the last element
Repeat for next largest number and the unsorted subset
Adv:
- less comparisons

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

Describe how bubble sort works

A

start from left
swap element if the element is larger than the adjacent right element
repeat until (no swaps in one traversal) or until the end

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

Describe how shell sort works

A

a.k.a diminishing increment sort
c.f insertion sort, except insertion sort for larger increments
Divide list into smaller sub-lists by choosing every nth element
sort smaller lists using insertion sort
Decrease the increment
worst case ==> O(n^2)

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

Describe how merge sort works

A

Split list into two, repeatedly
Merge and sort the small lists together
O(n log n)

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

Describe how quick sort works

A
Choose a pivot point
Sort elements (smaller values to pivot to the left, larger values to pivot to the right)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe how Timsort works

A

Hybrid sort
Finds runs of sorted elements using insertion sort
Merges them together using merge sort

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