Aoa Expt3
Aoa Expt3
Problem Statement: Finding out Minimum and Maximum using Divide and Conquer
Strategy.
Subject: CSL401-Analysis of Algorithm Lab Sem: IV(2023-24) Subject In-charge: Dr. Shaikh Phiroj
Theory:
Step-by-Step Algorithmic Explanation
Step 1: Base Case (Single Element)
If the array contains only one element, the function returns that
element as both minimum and maximum.
This serves as the base case for the recursive function.
Step 2: Divide the Array
If the array has more than one element, it is split into two halves:
o The left half from low to mid
o The right half from mid + 1 to high
The midpoint is calculated as: mid=low+high2mid = \frac{low +
high}{2}mid=2low+high
Step 3: Recursive Calls
The algorithm recursively calls itself to find the min and max in both
halves:
o left = findMaxMin(arr, low, mid) → Finds min & max in the
left half.
o right = findMaxMin(arr, mid + 1, high) → Finds min & max
in the right half.
Step 4: Conquer (Merge the Results)
Once the recursive calls return, the results are merged:
o The overall maximum is the greater of the left and right
maximum values:
result.max=max (left.max,right.max)result.max =
\max(left.max, right.max)result.max=max(left.max,right.max)
o The overall minimum is the smaller of the left and right
minimum values:
result.min=min (left.min,right.min)result.min =
\min(left.min, right.min)result.min=min(left.min,right.min)
Step 5: Return the Final Result
The function returns the final result, which contains both:
o result.max → The maximum value in the entire array
o result.min → The minimum value in the entire array
Pseudo Code:
FUNCTION findMaxMin(arr, low, high)
DECLARE result, left, right
RETURN result
Subject: CSL401-Analysis of Algor ithm Lab Sem: IV(2023-24) Subject In-charge: Dr. Shaikh Phiroj
Algorithm: Function: findMaxMin (Recursive Approach)
1. Input: Array arr, indices low, and high.
2. Base Case:
o If low == high,
Set result.max = arr[low]
Set result.min = arr[low]
Return result
Program Code:
Subject: CSL401-Analysis of Algorithm Lab Sem: IV(2023-24) Subject In-charge: Dr. Shaikh Phiroj
Output Snapshot:
Subject: CSL401-Analysis of Algorithm Lab Sem: IV(2023-24) Subject In-charge: Dr. Shaikh Phiroj
Edge detection: Finding intensity peaks in pixel arrays.
4 . Network and Cybersecurity
Load balancing: Identifying max-min load in distributed
systems.
Traffic control: Finding highest and lowest network
speeds in real-time monitoring.
5 . Financial Applications
Stock market analysis: Finding highest and lowest stock
values in a dataset.
Risk assessment: Identifying extreme financial
transactions.
6 . Scientific Computing
Climate and weather prediction: Identifying the hottest
and coldest days.
Geographical data analysis: Finding highest mountains
and lowest valleys from elevation maps.
Subject: CSL401-Analysis of Algorithm Lab Sem: IV(2023-24) Subject In-charge: Dr. Shaikh Phiroj