Question

Write a recursive algorithm in a pseudo code, Min-Max, for finding both the minimum and the...

Write a recursive algorithm in a pseudo code, Min-Max, for finding both the minimum and the maximum elements in an array A of n elements. Your algorithm calls itself only once within the algorithm and should return a pair (a, b) where a is the minimum element and b is the maximum element.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Write a recursive algorithm in a pseudo code, Min-Max, for finding both the minimum and the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (a) Give the pseudo-code for a recursive algorithm called Find_Smallest(A, n) that returns the value of...

    (a) Give the pseudo-code for a recursive algorithm called Find_Smallest(A, n) that returns the value of the smallest element in an array of n integers called A. Assume the elements in the array are at locations A[1]..A[n]. (b) Give a recurrence T(n) for the running time of your algorithm. (c) Solve the recurrence in part (b)

  • 1.we need n-1 comparisons at most 3*n/2comparisons suffice to find both the min and max Basic...

    1.we need n-1 comparisons at most 3*n/2comparisons suffice to find both the min and max Basic Strategy: Maintain the minimum and maximum of elements seen so far. Don't compare each element to the minimum and maximum separately. Process elements in pairs. Compare the elements of a pair to each other. Then compare the larger element to the maximum so far, and compare the smaller element to the minimum so far. This leads to only 3 comparisons for every 2 elements...

  • 2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting...

    2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting the left side, sorting the right side, and then merging them. Write a similar recursive algorithm that finds the maximum element of an array. (Find the max of the left side, then find the maximum of the right side, then compare the two.) Write pseudo-code for this algorithm. Give the recurrence relation that describes the number of comparisons that your algorithm uses.

  • What is the run-time of this recursive code: int maximum(int array[], int index, int len); //define...

    What is the run-time of this recursive code: int maximum(int array[], int index, int len); //define maximum function. int minimum(int array[], int index, int len);//define minimum function. int main() { //Main method int array[MAX_SIZE], N, max, min; //Defining all the variable. int i; printf("Enter size of the array: ");//Taking input from user as a array size scanf("%d", &N); printf("Enter %d elements in array: ", N);//Taking input from user for(i=0; i<N; i++) { scanf("%d", &array[i]);//storing all the element in array. }...

  • 07-15 pts) Develop a recursive version of the Bubble Sort algorithm. (a) Write the pseudo code...

    07-15 pts) Develop a recursive version of the Bubble Sort algorithm. (a) Write the pseudo code of the algorithm and justify that it is recursive and works correctly Write the recurrence relation for the algorithm and solve it using one of the two approaches discussed in class, as appropriate. Solve the recurrence relation and show that the time complexity of the recursive algorithm is θ(n).

  • Question 1. Below is the pseudo code for a divide and conquer algorithm that finds the...

    Question 1. Below is the pseudo code for a divide and conquer algorithm that finds the minimum value in an array. Suppose that the input array, A, is of size n, analyze the computational cost of this algorithm in the form of Tin) and prove your conclusion findMin (A, left, right) if (left == right) return Alleft) center - (left + right) / 2 return min (findMin (A, left, center), findMin (A, center + 1, right)

  • MATLAB: Write a code using loop for which implements the following algorithm for finding the maximal...

    MATLAB: Write a code using loop for which implements the following algorithm for finding the maximal element in a vector (without using the ready Matlab function max): 1) Assume the first element of the vector to be the maximal one and assign its value to MyMax. 2) Take the second number and compare with the current maximum. If the second number is bigger, assign it as the new maximum, otherwise keep the old max as reference. 3) Take the third...

  • ngu Cons eY Ja Question 1 a) Write pseudo code to output a singly-linked list in...

    ngu Cons eY Ja Question 1 a) Write pseudo code to output a singly-linked list in reverse order when you are NOT allowed to allocate memory dynamically. What is the running time of the algorithm? b) Write pseudo code to output a singly-linked list in reverse order when you are ALLOWED to allocate memory dynamically. What is the running time of the algorithm? c) You have an increasingly-sorted circular list (using an array) of n elements that is full. The...

  • Question 7 (10%) formally, the second minimum of an array is larger than the minimum but...

    Question 7 (10%) formally, the second minimum of an array is larger than the minimum but smaller than all the other elements in the array A of size n 1 (a) Write pseudo code to search for the second minimum element (5 points), (b) What is the running time of your algorithm (5 points).

  • I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is...

    I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is not limited to finding only the median, but can generally find the ith element with 0≤i <n. Implement this generic version of the median algorithm by creating a class selector in the ads.set2.select package and implementing the following method: /** * Returns the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT