Sort Algorithms Flashcards

1
Q

Time complexity of bubble sort

A

O(n**2)

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

Time complexity of insert sort

A

O(n^2)

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

Bubble sort vs Insertion sort

A

Both has time complexity of O(n^2), where sorting time will grow quadratically.
Insertion sort takes less time than bubble sort for large values of n.

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

Time complexity of merge sort

A

O(nlogn)

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

Time complexity of quick sort (worst and average)

A

Worst case: O(n^2)
Worst case occurs when:
1. the elements in the array is mostly sorted
2. Pivot chosen is not the median

average: O(nlogn)

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

What does stable mean?

A

Stable implementation ensures that order of elements with same sorting characteristics is preserved

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

What does in place/ out of place mean?

A

Out of place means that additional data structures are instantiated /created in the process
In place means that additional data structures are not created as the process is done in the original array.

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

Describe Bubble Sort (S,M,SD,LD,ASD)

A

Stable
small Memory usage as implementation is usually in place and not much overhead
efficient with Small Datasets
slowest with Large Datasets
efficient with Almost Sorted Datasets

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

Describe Insertion Sort (S,M,SD,LD,ASD)

A

Stable
small Memory usage as in place implementation
efficient with Small Datasets
inefficient with Large Datasets as time complexity O(n^2)
most efficient with Almost Sorted Datasets

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

Describe mergsort (S,M,SD,LD,ASD)

A

Stable
large Memory usage as implementation is usually recursive and thus incurs large overhead
inefficient with Small Datasets
efficient with Large Datasets
inefficient with almost sorted Datasets as the array will be divided regardless of

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

Describe quick Sort (S,M,SD,LD,ASD)

A

usually Unstable
Memory usage depends on in place/out of place
efficient with Small Datasets
efficient with Large Datasets but slower than mergesort
MOST INEFFICIENT with Almost Sorted Datasets as the array is split up regardless, which makes the array more unsorted

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