CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the program given below:

procedure mystery (int A[1 to 100])
int i, j, position, tmp;
begin
for j = 1 to 100 do
position = j;
for i = j to 100 do
if (A[i] > A [position]) then
position = i;
end for
tmp = A[j];
A[j] = A[position];
A[position] = tmp;
end for
end

Then, the number of times the test A[i] > A [position] is executed is

A
10000
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
5050
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
100
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Depends on contents of A
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B 5050
Option (b)
In iteration j, there are 100 -j + 1 comparisons made.

So, in all there are:
100 + 99 + ... + 2 + 1 = 5050

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Vardhaman Mahavir
HISTORY
Watch in App
Join BYJU'S Learning Program
CrossIcon