Divide-and-Conquer Technique:: Finding Maximum & Minimum
Divide-and-Conquer Technique:: Finding Maximum & Minimum
Divide-and-Conquer Technique:: Finding Maximum & Minimum
a problem of size n
subproblem 1 subproblem 2
of size n/2 Divide of size n/2
a solution to a solution to
subproblem 1 subproblem 2
a solution to
the original problem
Index: 1 2 3 4 5 6 7 8 9
Array: 22 13 -5 -8 15 60 17 31 47
(1)
Rmaxmin(1, 9, 60, -8)
(6)
1, 5, 22, -8 6, 9, 60, 17
(2) (5) (7) (8)
1, 2, 22, 13 3, 3, -5, -5
T(n) = (1) if n = 1 or 2
2T(n/2) + (1) if n > 2
equivalently
T(n) = b if n = 1 or 2
2T(n/2) + b if n > 2