question archive 1) a) Give an algorithm to find the maximum in an array  b) State an algorithm to find the minimum in an array 

1) a) Give an algorithm to find the maximum in an array  b) State an algorithm to find the minimum in an array 

Subject:Computer SciencePrice:9.82 Bought3

1) a) Give an algorithm to find the maximum in an array 

b) State an algorithm to find the minimum in an array 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Part 1

Assuming an array X[] of size n, we need to determine the element's greatest and lowest elements. Our algorithm should perform the fewest possible evaluations.

X[] = [4,2, 0,8,20,9,2], Maximum =20, Minimum =0
Input x[] = [-8.-3, -10, 32, -1], Output x[] = [-8.-3, -10, 32, -1], max = -1, min = -32

 

Part2

To find a minimum in an array.

 

A local minimum exist if there is only one element in the array.
If there are two elements in an array, look at each one. On a local level, there must be at least one.
Otherwise, have a look at the middle element of the array. If it is a local minimum, return it. If this is the case, then at least one other figure in the vicinity must be lower. Go backwards in time to the part of the array that includes the less significant member (but not the middle).
Take note of the recurrence relation in this.

T(1) 0 T(2) 1

T(2) 0 T(1) 0

the product of (n/2) and (1 - (n/2)

 

 

Step-by-step explanation

step 1

When the first iteration of Binary Search delivers the local minima at the center point, this is the best case solution.
Using this approach, the center element is selected and then checked against its companions to see if it's a local minimum.

 

Step2

Binary search can be used to locate such values if n-1 |arr[MID+1] > arr [MID]) in the event that (mid>=0 && arr[mid-1] arr[mid]) It's possible to use the localMinFinder() function to find the lowest value in an array. 19 int localMin 22 (int arr[], int n) 23 - 24 return localMinFinder (arr, 0, n-1), and printf("local minima is percent d", arr [pos] return 0;" input Success in Output #stdin #stout 1 nm m m is the local minimum for Os.

Related Questions