Skip to main contentSkip to solution

Given a list 'numList' of 'n' elements and the key value 'K'. Arrange the following steps in linear search algorithm 'LinearSearch(numList, key, n)' to find the position of the key 'K' in 'numList':

(A) PRINT “Search unsuccessful”

(B) WHILE index < n, REPEAT Step 3

(C) SET index = 0

(D) IF numlist[index]= key THEN

PRINT “Element found at position”, index+1

STOP

ELSE

index = index+1

Solution

✅ Correct Option: 4

The index must be initialised first, then the loop runs the comparison on each element, and "Search unsuccessful" is printed only after the loop ends without a match.

(C) SET index = 0: start at the first element.

(B) WHILE index < n, REPEAT Step 3: loop through the list while elements remain.

(D) IF numlist[index] = key THEN print the position (index+1) and STOP, ELSE index = index+1: compare the current element, and either stop or move on.

(A) PRINT "Search unsuccessful": reached only when the loop finishes without finding the key.


Option 2: the loop (B) cannot run before index is set in (C).

Option 1: it prints "Search unsuccessful" first, before any searching has happened.

Keyboard Shortcuts

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