Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer the following questions about the unusual algorithm below for computing t

ID: 3781633 • Letter: A

Question

Answer the following questions about the unusual algorithm below for computing the maximum value of an array. Note that the input array must have a size that is a power of 2. (The algorithm can be modified to accommodate non-powers-of-two, but this complicates the proofs somewhat.) Input: data: array of real numbers Input: n: length of data, must be a power of two Output: the max value of data; i.e., a value in data that is greater than or equal to all elements of data Algorithm: WinnowMax if n = 1 then | return data [1] end winnow = Array(n/2) for i = 1 to n/2 do if data[2i - 1]

Explanation / Answer

Solution for the Problem :-

#include<stdio.h>
float WinnowMax(float data[],int n);
int main()
{
int n,i,j;
float data[1000],p;
printf("Enter length of the Data(length of data,must be power of two) ");
scanf("%d",&n);
printf("Enter data elements(array elements should be real numbers) ");
for(i=1;i<=n;i++)
{
scanf("%f",&data[i]);
}
p=WinnowMax(data,n);
printf("The max value of the data is %f ",p);
return 0;
}
float WinnowMax(float data[1000],int n)
{
int i,j;
float winnow,swap;
if(n==1)
{
return data[1];
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
if(data[j]>data[j+1])
{
swap =data[j];
data[j] =data[j+1];
data[j+1] =swap;
}
}
}
winnow=data[n];
return winnow;
}

OUT PUT:-

Enter length of the Data(length of data,must be power of two)
4
Enter data elements(array elements should be real numbers)
5.5
25.126547
21.23147
6.32547
The max value of the data is 25.126547

Note :- The output contain the max value of the deta i.e the value is grater then or equal to the all elements of the data.

Thank you!