In Java Language Consider the following algorithm. Algorithm Sort(A,n) Input: Ar
ID: 3580939 • Letter: I
Question
In Java Language
Consider the following algorithm.
Algorithm Sort(A,n)
Input: Array A containing n dierent integer values.
Out: Array A sorted in increasing order of value.
for i n1 downto 1 do {
m i
(*)
t A[m];A[m] A[i];A[i] t // Swap A[i] and A[m]
}
return A
Which of the following instructions must be inserted at the point marked (*) so that the algorithm correctly sorts the values stored in A in increasing order
(A) for j 0 to i1 do
if A[j] > A[m] then m j
(B) for j i + 1 to n1 do
if A[j] > A[m] then m j
(C) for j 0 to n1 do
if A[j] > A[m] then m j }
(D) for j 0 to i1 do
if A[j] < A[m] then m j }
(E) for j 0 to n1 do
if A[j] < A[m] then m j }
Explanation / Answer
Option A is correct
Which of the following instructions must be inserted at the point marked (*) so that the algorithm correctly sorts the values stored in A in increasing order of value?
(A) for j 0 to i1 do if A[j] > A[m] then m j
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.