# Question:- Describe an algorithm for finding both the largest and the smallest integers in a finite sequence of integers in an array and count them how many comparison operation are involved.

1
by Sonia92

Log in to add a comment

by Sonia92

Log in to add a comment

Certified answers contain reliable, trustworthy information vouched for by a hand-picked team of experts. Brainly has millions of high quality answers, all of them carefully moderated by our most trusted community members, but certified answers are the finest of the finest.

FUNCTION MAX_MIN_COMPARE_Count ( A[0, N-1] , N)

Begin

// A[0, N-1] = integer array

integer j // = index of smallest

integer k // = index of largest

integer m // moving index

integer count //= of comparisons

m = 0 j = 0 k = 0 count = 0 m = 0

While m < N do

begin

count = count + 1

if A[m] < A[j] then

j = m

else

k = m

end if

m = m + 1

end while

print count

// A[j] is smallest and A[k] is the largest

END

Begin

// A[0, N-1] = integer array

integer j // = index of smallest

integer k // = index of largest

integer m // moving index

integer count //= of comparisons

m = 0 j = 0 k = 0 count = 0 m = 0

While m < N do

begin

count = count + 1

if A[m] < A[j] then

j = m

else

k = m

end if

m = m + 1

end while

print count

// A[j] is smallest and A[k] is the largest

END