Skip to main contentSkip to solution

Given below is the code for Selection sort procedure:

SELECTIONSORT( numList, n)

Step 1: SET i=0

Step 2: WHILE i< n REPEAT STEPS 3 to 11

Step 3: SET min = i, flag = 0

Step 4: _______________

Step 5: WHILE j<="" p="">

Step 6: ___________________________

Step 7: min=j

Step 8: __________

Step 9: IF flag=1 THEN

Step 10: swap(numList[i],numList[min])

Step 11: ________________________

Arrange the options given below in order to fill in the blanks in the above code.

A. SET i=i+1

B. SET j= i+1

C. IF numList[j] < numList[min] THEN

D. flag=1

Solution

✅ Correct Option: 3

Step 4: B. SET j = i+1, which starts the inner loop just after position i.

Step 6: C. IF numList[j] < numList[min] THEN, which compares the current element with the smallest found so far.

Step 8: D. flag=1, which records that a smaller element was found (Step 7 has already set min = j).

Step 11: A. SET i = i+1, which moves to the next position after the swap.


Step 9 swaps only when flag=1, so flag must be set inside the IF, after min=j. This is why D comes after C and not before it.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question