A Use of
A Use of
It represents the tight bound of an algorithm, i.e., it gives both the upper and
lower bounds:
b.
Master method: Directly provides the solution for recurrence relations of the
form T(n) = aT(n/b) + f(n) using predefined cases.
c.
d.
Using substitution:
T(n) = 2T(n-1) + 1
= 2[2T(n-2) + 1] + 1 = 4T(n-2) + 2 + 1
= 8T(n-3) + 4 + 2 + 1
=…
= 2ⁿ⁻¹ + (2ⁿ⁻¹ - 1) = 2ⁿ - 1
So, T(n) = 2ⁿ - 1
e.
2. Greedy Method
3. Dynamic Programming
4. Backtracking
5. Branch and
Bound
We see:
f(n) = n log n = n × log n = n^1 × log n, which is slightly more than n, i.e., f(n) =
Ω(n^1+ε) for any ε > 0, but it does not satisfy the regularity condition.
So this is Case 2 of the Master Theorem (f(n) = Θ(n^log_b a × log^k n)) with k =
1
2(b)
Each level does Θ(n) work, and the number of levels = Θ(log n)
T(n) = Θ(n^log_b a)
a = 2, b = 2, log_b a = 1
Case 3: f(n) = Ω(n^log_b a + ε) for some ε > 0, and regularity condition holds:
T(n) = Θ(f(n))
a = 2, b = 2, log_b a = 1
f(n) = n² = Ω(n^1+ε), ε = 1
Regularity holds: 2(n/2)² = n²/2 ≤ c × n²
int min_idx = i;
min_idx = j;
// Swap
A[i] = A[min_idx];
A[min_idx] = temp;
Pass-by-pass sorting:
Pass 1: Find min (2), swap with 1st → (2, 10, 4, 56, 4, 58)
Pass 2: Find min (4), swap with 2nd → (2, 4, 10, 56, 4, 58)
Pass 3: Find min (4), swap with 3rd → (2, 4, 4, 56, 10, 58)
Pass 4: Find min (10), swap with 4th → (2, 4, 4, 10, 56, 58)