M4: Divide and Conquer Flashcards

Divide and Conquer

1
Q

Name two key examples of Divide-and-Conquer algorithms.

A
  • Merge Sort
  • Quick Sort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the general recurrence relation for Divide-and-Conquer problems?

A

T(n)=aT(n/b)+f(n)

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

In the recurrence relation T(n)=aT(n/b)+f(n), what does ‘a’ represent?

A

‘a’ represents the number of subproblems.

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

In the recurrence relation T(n)=aT(n/b)+f(n), what does ‘b’ represent?

A

‘b’ represents the division factor.

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

In the recurrence relation T(n)=aT(n/b)+f(n), what does ‘f(n)’ represent?

A

‘f(n)’ represents the work done outside recursion.

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

What is the time complexity of Merge Sort?

A

Θ(nlog⁡n)

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

What are the steps of the Merge Sort algorithm?

A
  • Divide array into two halves
  • Recursively sort each half
  • Merge the two sorted halves
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the best-case and average time complexity of Quick Sort?

A

Θ(nlog⁡n)

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

What is the worst-case time complexity of Quick Sort?

A

Θ(n^2)

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

List one optimization technique for Quick Sort.

A
  • Use median-of-three for pivot selection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the primary limitation of Binary Search?

A

Requires a sorted array

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

What is the time complexity of Binary Search in the worst case and average case?

A

O(log⁡n)

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

What problem does the Maximum Subarray Problem address?

A

Find the contiguous subarray with the maximum sum.

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

What is the time complexity of the brute force approach for the Maximum Subarray Problem?

A

O(n^2)

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

What is the time complexity of the Divide-and-Conquer approach for the Maximum Subarray Problem?

A

O(nlog⁡n)

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

What is Kadane’s Algorithm used for?

A

Finding the maximum subarray sum in linear time.

17
Q

What is the time complexity of Kadane’s Algorithm?

18
Q

In the Stock Market example, what transformation is performed to find maximum profit?

A

Convert stock prices into daily differences.

19
Q

What is the optimal solution approach for calculating maximum profit in the Stock Market example?

A

One-Pass Approach

20
Q

What is the time complexity of the optimal solution for the Stock Market problem?

21
Q

What is the time complexity for Merge Sort in all cases?

A

O(nlog⁡n) for best, average, and worst cases.

22
Q

What is the time complexity for Quick Sort in the worst case?

23
Q

What is the time complexity for Binary Search in the best case?

24
Q

What is the time complexity for Kadane’s Algorithm in all cases?

A

O(n) for best, average, and worst cases.