Sorting Flashcards

1
Q

Selection sort algorithm

A

For each element in list:
FInd smallest element
Swap it with the element
repeat with unsorted part

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

Selection sort Runtime efficiency

A

Worst/Best/Average case: O(n^2)

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

Bubble sort algorithm

A

Starting on the left: For each pair of elements in the list, swap them if they are not in order. The largest element is bubbled to position N
Start on the left again, and bubble the second largest element to position N-1.
Keep doing this until there are no longer any swaps

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

Bubble sort Runtime efficiency

A

WOrst/Average: O(n^2) 2 nested loops

Best case: O(n) for almost sorted list

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

Insertion sort

A

Set a marker for the sorted section after the first element.
Select the first unsorted element.
Swap other elements to the right to create the correct position and shift the unsorted element
Advance the marker to the right by one element.
Do this until unsorted section is empty.

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