Algorithm Assignment
Algorithm Assignment
The problem is to find the maximum and minimum elements in an array using the Divide and
Conquer approach, minimizing the number of comparisons. The divide-and-conquer algorithm works
as follows:
Combine: Compare the two maxima from the halves to get the overall maximum, and compare the
1. Base Case: If the array contains only one element, that element is both the maximum and
minimum.
2. Recursive Case: Split the array into two halves and recursively find the maximum and minimum
3. Combine: The overall maximum will be the larger of the two maxima, and the overall minimum will
2. Implementation in C++
#include <iostream>
#include <algorithm>
if (low == high) {
if (high == low + 1) {
} else {
int main() {
return 0;
}
3. Time Complexity Analysis
The brute-force method for finding both maximum and minimum involves scanning the array and
comparing each element with both the current maximum and minimum, leading to a total of 2n - 2
The algorithm divides the array into two halves, recursively solves each half, and combines the
results.
The total number of comparisons for an array of size n using this approach is 3n/2 - 2.
This reduction in the number of comparisons is significant for large arrays, making the
Brute-force requires 2n - 2 comparisons. Divide and Conquer performs only about 3n/2 - 2
4. Deliverables
A concise report explaining the algorithm design, time complexity analysis, and the advantages of