Sorting and Searching Algorithms Flashcards

(12 cards)

1
Q

What is the time complexity of Merge Sort?

A

O(n log n) in all cases.

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

What is the worst-case complexity of Quick Sort?

A

O(n²), but it has an average complexity of O(n log n).

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

What is binary search, and what is its time complexity?

A

A divide-and-conquer search algorithm with O(log n) complexity.

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

What is the best and worst-case time complexity of linear search?

A

Best: O(1) (first element is the target), Worst: O(n).

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

pivot

What is the worst-case scenario for Quick Sort?

A

When the pivot is always the smallest or largest element → O(n²) complexity.

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

What is the best sorting algorithm for nearly sorted data?

A

Insertion Sort (O(n)).

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

What is the best-case complexity of Binary Search?

A

O(1) (if the middle element is the target).

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

What is a brute-force sorting algorithm?

A

A naive method that checks all possible orderings of elements to find the sorted one—inefficient (O(n!)) and rarely used in practice.

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

How does Selection Sort work?

A

Repeatedly selects the minimum element and moves it to the front.
Time complexity: O(n²), in-place, not stable.

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

How does Insertion Sort work?

A

Builds a sorted list one item at a time by inserting each element into its correct position.
Time complexity: Best case O(n), worst case O(n²), in-place, stable.

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

How does Bubble Sort work?

A

Repeatedly swaps adjacent elements if they are in the wrong order.
Time complexity: O(n²), in-place, stable.

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

Which simple sorting algorithm is best for nearly sorted input?

A

Insertion Sort, as its best case is O(n).

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