Sorts + Searches + Big-O Flashcards

1
Q

Big-O of Selection Sort (best case)

A

O(n^2)

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

Big-O of Selection Sort (average case)

A

O(n^2)

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

Big-O of Selection Sort (worst case)

A

O(n^2)

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

Big-O of Insertion Sort (best case)

A

O(n)

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

Big-O of Insertion Sort (average case)

A

O(n^2)

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

Big-O of Insertion Sort (worst case)

A

O(n^2)

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

Big-O of Merge Sort (best case)

A

O(nlogn)

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

Big-O of Merge Sort (average case)

A

O(nlogn)

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

Big-O of Merge Sort (worst case)

A

O(nlogn)

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

Big-O of Quick Sort (best case)

A

O(nlogn)

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

Big-O of Quick Sort (average case)

A

O(nlogn)

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

Big-O of Quick Sort (worst case)

A

O(n^2)

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

Big-O of Linear Search (best case)

A

O(1)

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

Big-O of Linear Search (average case)

A

O(n)

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

Big-O of Linear Search (worst case)

A

O(n)

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

Big-O of Binary Search (best case)

A

O(1)

17
Q

Big-O of Binary Search (average case)

A

O(logn)

18
Q

Big-O of Binary Search (worst case)

A

O(logn)

19
Q

How does selection sort work?

A

Selection sort finds the largest item in the array, and swaps it to the end. The item that was previously at the end is now where the largest item used to be. Repeat with an array of length - 1.

20
Q

How does insertion sort work?

A

Insertion sort checks if the next item in the array is smaller than the item at the current index. If it is, it is moved to before the current index, and it checks again. IT DOES NOT SWAP!!

21
Q

How does merge sort work?

A

Merge sort splits the data in half until all that’s left are pairs. It then sorts the first two pairs, then combines them, then sorts them again. Then it moves on to the next two pairs and does the same thing. Then it combines both and sorts all 8 numbers, and so on.

22
Q

How does quick sort work?

A

Quick sort selects a pivot, which is the first item in the array. Then it moves from the left and from the right of the array until it finds two items that are bigger on the left and smaller on the right. It swaps them. Once the right pointer is less than the left pointer, the pivot and the item at the right pointer are swapped. The next pivot is chosen, and so on.

23
Q

How does linear search work?

A

Linear search uses one for loop to go through the entire array and check each item until it finds what it wants.

24
Q

How does binary search work?

A

Binary search compares the target to the middle item of the array. If it’s the same, it returns that location. If not, it either checks the top or bottom half of the array depending on how the target was in comparison to the middle, and recurs. It continues until the index finds the target or the first pointer is greater than the last.