Divide and Conquer Alogrithms Flashcards

(75 cards)

1
Q

What is the Max Subarray Problem?

A

It asks for indices i and j in an array A such that A[j] - A[i] is maximized, and i ≤ j.

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

What is the practical application of the Max Subarray Problem mentioned in the lecture?

A

Retrospective stock trading — determining when to buy and sell for maximum profit.

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

What is the constraint on buying and selling in the Max Subarray Problem?

A

No short selling; you must buy before you sell (i ≤ j).

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

What is the time complexity of the brute force solution?

A

Theta(n^2)

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

How does the brute force solution work?

A

It uses two nested loops to evaluate A[j] - A[i] for all i < j.

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

What are the three main steps in a divide and conquer algorithm?

A

Divide, Recurse, Combine.

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

In the divide step, how is the array divided?

A

It is split into two halves: A[l to m] and A[m+1 to u], where m = (l + u) // 2.

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

What are the three cases considered when combining solutions?

A

1) Max subarray in left half, 2) Max subarray in right half, 3) Max subarray straddling the midpoint.

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

How is the straddling case handled in the algorithm?

A

By computing min in the left half and max in the right half, then taking their difference.

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

What is the time complexity of the divide and conquer solution?

A

Theta(n log n)

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

Why is the divide and conquer approach more efficient?

A

It reduces the time complexity from quadratic (Theta(n^2)) to near-linear (Theta(n log n)).

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

What is the main idea behind divide and conquer algorithms?

A

Divide the problem into subproblems, solve each recursively, and combine their solutions.

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

What are the three main phases of a divide and conquer algorithm?

A

Divide, Conquer, Combine

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

What does the ‘Divide’ step do in divide and conquer?

A

It splits the problem into smaller subproblems.

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

What happens in the ‘Conquer’ step of divide and conquer?

A

Each subproblem is solved, usually recursively.

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

What is the purpose of the ‘Combine’ step in divide and conquer?

A

To merge the solutions of subproblems into a solution for the original problem.

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

What is the time complexity of Merge Sort?

A

Θ(n log n)

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

In Merge Sort, which step is most costly in terms of time?

A

The Combine step, which takes Θ(n) time.

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

In Quick Sort, where is the majority of the work done?

A

In the Divide step (partitioning), which takes Θ(n) time.

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

What is the role of the pivot in Quick Sort?

A

It is used to partition the array into two subarrays.

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

What is a method to choose a good pivot in Quick Sort?

A

The Median of Medians trick.

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

What is the time complexity of Binary Search?

A

Θ(log n)

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

Which step is the most computationally expensive in Binary Search?

A

None, each step is Θ(1); the recursion provides the efficiency.

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

What is the Master Method used for?

A

To analyze the time complexity of divide and conquer algorithms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How does Merge Sort split the input?
Into two equal parts, assuming n is even.
26
How does Binary Search determine which half to search?
By comparing the target with the middle element.
27
What is the word size in modern CPUs?
64 bits
28
How are large numbers represented for computation?
As arrays of binary bits (bit strings)
29
Why is big number arithmetic important?
It's essential for cryptography and large integer operations.
30
What is the purpose of the carry variable in binary addition?
To handle overflow during bit-wise addition.
31
What is the complexity of binary addition for n-bit numbers?
Θ(n)
32
What is the time complexity of grade-school multiplication?
Θ(n^2)
33
How does grade-school multiplication work?
Multiply each bit of one number with the other and shift accordingly, then add all results.
34
How does divide and conquer multiplication initially work?
Split numbers in halves and recursively multiply, add, and pad results.
35
Why doesn't basic divide and conquer improve time complexity over grade-school method?
Because it still performs four n/2-bit multiplications.
36
What is the recurrence relation for naive divide and conquer multiplication?
T(n) = 4T(n/2) + Θ(n)
37
What trick is used in Karatsuba’s algorithm?
Use (A1+A2)(B1+B2) to replace two multiplications with one.
38
How many multiplications does Karatsuba’s algorithm perform?
Three
39
What is the recurrence relation for Karatsuba’s algorithm?
T(n) = 3T(n/2) + Θ(n)
40
What is the time complexity of Karatsuba’s algorithm?
Θ(n^1.585)
41
Why is Karatsuba’s algorithm faster than grade-school multiplication?
Fewer recursive multiplications lead to faster asymptotic growth.
42
What does multiplying a binary number by 2^k mean?
Appending k zeros to the number.
43
What is a recurrence relation?
An equation that defines a sequence recursively: each term is defined in terms of previous terms.
44
What is divide and conquer?
An algorithm design strategy where a problem is broken into smaller subproblems, solved recursively, and combined.
45
In a recurrence T(n) = a·T(n/b) + f(n), what does 'a' represent?
The number of subproblems the problem is divided into.
46
In a recurrence T(n) = a·T(n/b) + f(n), what does 'b' represent?
The factor by which the problem size is reduced.
47
In a recurrence T(n) = a·T(n/b) + f(n), what does 'f(n)' represent?
The cost of the divide and combine steps outside the recursive calls.
48
What is the Master Method used for?
To solve recurrences of the form T(n) = a·T(n/b) + Θ(n^c) in divide-and-conquer algorithms.
49
Master Method Case 1 condition?
If log_b(a) > c, then T(n) = Θ(n^log_b(a)).
50
Master Method Case 2 condition?
If log_b(a) = c, then T(n) = Θ(n^c·log n).
51
Master Method Case 3 condition?
If log_b(a) < c, then T(n) = Θ(n^c).
52
What is the result of T(n) = 2·T(n/2) + Θ(n)?
Θ(n·log n) - Example: Merge Sort or Max Subarray.
53
What is the result of T(n) = 3·T(n/2) + Θ(n)?
Θ(n^1.58) - Example: Karatsuba Multiplication.
54
What is the result of T(n) = 4·T(n/2) + Θ(n)?
Θ(n^2) - Example: Naive Multiplication.
55
What is the result of T(n) = 7·T(n/2) + Θ(n^2)?
Θ(n^2.81) - Example: Strassen's Matrix Multiplication.
56
How do you calculate log_b(a)?
Use the formula log_b(a) = ln(a)/ln(b).
57
What are the steps to apply the Master Method?
1. Identify a, b, c. 2. Compute log_b(a). 3. Compare with c. 4. Apply the correct case.
58
What does the expansion method do?
It repeatedly expands the recurrence to a base case to find a pattern and solve it.
59
What is a signal in the context of Fourier Transforms?
A signal is a sequence of values over time, such as stock prices, voice recordings, or temperature data.
60
What does the Fourier Transform do?
It converts a time-domain signal into its frequency components, revealing the contribution of each frequency.
61
What is the Discrete Fourier Transform (DFT)?
A version of the Fourier Transform for discrete-time signals; it converts n time samples into n frequency components.
62
What is the Inverse Fourier Transform?
It converts frequency components back into the original time-domain signal.
63
Why do Fourier Transforms use complex numbers?
Because the frequency components often involve phase and amplitude, which are represented naturally using complex numbers.
64
What is the form of a complex number?
a + bj, where 'a' is the real part, 'b' is the imaginary part, and j = sqrt(-1).
65
How do you compute the modulus of a complex number a + bj?
modulus = sqrt(a^2 + b^2)
66
What is the polar form of a complex number?
z = re^(jθ), where r is the modulus and θ is the phase angle.
67
What does multiplying two complex numbers do in polar form?
Multiplies their magnitudes and adds their angles.
68
What is a root of unity?
A complex number ω such that ω^n = 1 for some integer n.
69
What is the general form of the nth root of unity?
ω_k = e^(2πjk / n), for k = 0 to n-1.
70
What is the time complexity of the Fast Fourier Transform (FFT)?
O(n log n)
71
What is the complex conjugate of a + bj?
a - bj
72
What is the purpose of the FFT algorithm?
To compute the DFT efficiently using divide-and-conquer strategy.
73
How are discrete signals typically represented?
As a sequence of samples: a_0, a_1, ..., a_{n-1}.
74
What happens if you remove high-frequency components from a signal?
You get a smoothed or denoised version of the original signal.
75
How is 1 represented as a complex number?
1 = e^(j*0), with modulus 1 and angle 0 radians.