Skip to main contentSkip to solution

Arrange the following to search for an element using a linear search method.

(A) Each element in the list is compared one by one with the key.

(B) Enter the key to be searched.

(C) If no element matches the key, and we have traversed the entire list, we declare the search unsuccessful.

(D) The comparison process continues until an element matching the key is found or the end of the list is reached.

Solution

✅ Correct Option: 1

The key must be entered first, then each element is compared with it one by one. The comparison continues until a match is found or the list ends, and only after the whole list has been traversed without a match is the search declared unsuccessful.

Correct order:

(B) Enter the key to be searched.

(A) Each element in the list is compared one by one with the key.

(D) The comparison continues until a match is found or the end of the list is reached.

(C) If no element matches and the entire list has been traversed, declare the search unsuccessful.


Option 2: comparing (A) cannot start before the key is entered (B).

Option 3: (C) is the final outcome, so it cannot come before the comparisons.

Option 4: (C) cannot be the first step, since nothing has been searched yet.

Keyboard Shortcuts

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