Question: Given a unordered list of elements, find both the maximum element and the minimum element. Obvious solution: Consider first element to be max Consider first
Given a unordered list of elements, find both the maximum element and the minimum element.
Obvious solution:
Consider first element to be max
Consider first element to be min
Scan linearly from 2nd to last, and update if something larger then max or if something smaller than min
Write a recursive function that solves this using divide and conquer.
Prototype: void maxmin (list, first, last, max, min);
Base case(s)? Subproblems? How to combine results?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
