Please help me with this Algorithm problem. Write a recursive algorithm in a pse
ID: 3884124 • Letter: P
Question
Please help me with this Algorithm problem.
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 should return a pair (a, b) where a is the minimum element and b is the maximum element.
Algorithm Min-Max(A, n)
Input: an Array A of n elements
Output: a pair of (a, b) where a is the minimum element and b is the maximum element.
Explanation / Answer
Class pair { min, max } Algorithm Min-Max (A): Pair mypair if A.length == 1) mypair.max = A[1] mypair.min = A[1] return mypair if A[1] > A[2] mypair.max = A[1] mypair.min = A[2] else mypair.max = A[2] mypair.min = A[1] for i = 2 to n if A[i] > mypair.max) mypair.max = A[i] else if A[i]Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.