1. Write a function that finds the maximum value in an array containing n intege
ID: 3587345 • Letter: 1
Question
1. Write a function that finds the maximum value in an array containing n integers. Compute T(n) for the function. Write a function that finds the largest difference between successive integers in an array containing n integers. Compute T(n) for the function. Write a function that matches an input key in an array of n integers that are sorted in ascending order. Compute T(n) for the function. Write a function that computes the mean value of an array of n integers. Compute T(n) for the 2. 3. functionExplanation / Answer
int find_largest(int arr1[],int size1)
{
int temp_larg,i;
temp_larg=arr1[0];
for(i=1;i<size1;i++)
{
if(arr1[i]>temp_larg)
temp_larg=arr1[i];
}
return(temp_larg);
}
int maxDiff(int arr[],int size) {
int i;
int max_diff = arr[1]-arr[0];
int min_element = arr[0];
for (i=1;i<size;i++) {
if (arr[i] > min_element) {
// diff of current and min element
int diff = arr[i]-min_element;
if (diff > max_diff) {
// update max diff
max_diff = diff;
}
}
else {
// update the min element in the array
min_element = arr[i];
}
}
return max_diff;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.