Array Sorting Algorithms Flashcards

1
Q

What is the best time complexity of quicksort?

A

O(n log(n)) - bad

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

What is quicksort?

A

A divide and conquer algorithm where it divides the array into two smaller sub arrays. An index in each array is chosen as pivot, and the pivot compares itself to all the other entries so all smaller values are before it and all larger values are behind it. Recursively goes through each sub array (the one before and the one after the pivot position) and repeats.

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

What is the average time complexity of quicksort?

A

O(n log(n)) - bad

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

What is the worst time complexity of quicksort?

A

O(n^2) - terrible

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

What is the worst space complexity of quicksort?

A

O(log(n)) - good

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

What is merge sort?

A

A comparison based divide and conquer algorithm, where the list is divided into sublists of one element, then compared with an adjacent list to merge the two lists until it is sorted.

A new array needs to be allocated to store the sorted list.

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

What is the best time complexity of merge sort?

A

O(n log(n)) - bad

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

What is the average time complexity of merge sort?

A

O(n log(n)) - bad

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

What is the worst time complexity of merge sort?

A

O(n log(n)) - bad

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

What is the worst space complexity of merge sort?

A

O(n) - okay

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

What is timsort?

A

An adaptive sorting algorithm designer by Tim Peters, where it identifies the longest “run” (sorted subarray) and chooses either insertion or merge sort.

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

What is the best time complexity of timsort?

A

O(n) - great!

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

What is the average time complexity of timsort?

A

O(n log(n)) - bad

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

What is the worst time complexity of timsort?

A

O(n log(n)) - bad

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

What is the worst space complexity of timsort?

A

O(n) - okay

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

What is heapsort?

A

An in-place algorithm that builds a heap out is the data that is placed in an array in the layout of a binary tree. The sorting is done by repeatedly moving the largest element from the heap and inserting into array.

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

What is the best time complexity of heapsort?

A

O(n log(n)) - bad

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

What is the average time complexity of heapsort?

A

O(n log(n)) - bad

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

What is the worst time complexity of heapsort?

A

O(n log(n)) - bad

20
Q

What is the worst space complexity of heapsort?

A

O(1) - great since it is done in place

21
Q

What is bubble sort?

A

A simple algorithm that begins from the beginning of the list and compares adjacent pairs and swaps their position if not sorted. It repeatedly goes through the list, which grows shorter each time as the larger values get sorted to the end.

22
Q

What is the best time complexity of bubble sort?

A

O(n) - good, only needs to go through once

23
Q

What is the worst space complexity of bubble sort?

A

O(1) - great, done in place

24
Q

What is the average time complexity of bubble sort?

A

O(n^2) - horrible

25
Q

What is the worst time complexity of bubble sort?

A

O(n^2) - horrible

26
Q

What is the best time complexity of insertion sort?

A

O(n) - great

27
Q

What is the average time complexity of insertion sort?

A

O(n^2) - horrible

28
Q

What is the worst time complexity of insertion sort?

A

O(n^2) - horrible

29
Q

What is the worst space complexity of insertion sort?

A

O(1) - great, done in place

30
Q

What is selection sort?

A

A simple but inefficient algorithm where it splits the array into two sublists, sorted and unsorted. It finds the smallest element in the unsorted list and exchanges it with element in leftmost position of unsorted list.

31
Q

What is the best time complexity of selection sort?

A

O(n^2) - horrible

32
Q

What is the average time complexity of selection sort?

A

O(n^2) - horrible

33
Q

What is the worst time complexity of selection sort?

A

O(n^2) - horrible

34
Q

What is the worst space complexity of selection sort?

A

O(1) - great

35
Q

What is insertion sort?

A

A super simple sorting algorithm where it removes one element from the list, finds where it belongs in the sorted list, and inserts it there. It can be performed online (as the list is being received).

Good for short lists, bad for long ones.

35
Q

What is bucket sort?

A

A comparison sorting algorithm that sets up an array of empty buckets. It distributes the contents of the original array in the buckets. Each non empty bucket is sorted, then each bucket is visited in order and put back in the original array.

35
Q

What is the best time complexity of bucket sort?

A

O(n + k), where K is number of buckets

36
Q

What is the average time complexity of bucket sort?

A

O(n + k), where K is number of buckets

37
Q

What is the worst time complexity of bucket sort?

A

O(n^2) - horrible

38
Q

What is the worst space complexity of bucket sort?

A

O(n) - okay

39
Q

What is radix sort?

A

A non-comparative sorting algorithm that sorts data with integer keys by grouping keys by individual digits that share the same significant digit position and value. Starts with 1s place, then 10s, then 100s, etc.

40
Q

What is the best time complexity of radix sort?

A

O(nk) - good, but k is variable

41
Q

What is the average time complexity of radix sort?

A

O(nk) - good, but k is variable

42
Q

What is the worst time complexity of radix sort?

A

O(nk) - good, but k is variable

43
Q

What is the worst space complexity of radix sort?

A

O(n+k)