Tip:A–D to answerE for explanationV for videoS to reveal answer
Given an array A = {55, 66, 77, 88, 99} and a key = 88. How many iterations are done until the element is found?
- A.
1
- B.
3
- C.
4
(Correct Answer) - D.
2
Explanation
1. Using Linear Search
In a linear search, the algorithm checks each element sequentially from left to right.
The Iteration Logic:
Iteration (i)=Check A[i] against Key
-
Iteration 1: Check 55=88 ? (No)
-
Iteration 2: Check 66=88 ? (No)
-
Iteration 3: Check 77=88 ? (No)
-
Iteration 4: Check 88=88 ? (Yes)
Total Iterations (Linear)=4
Explanation
1. Using Linear Search
In a linear search, the algorithm checks each element sequentially from left to right.
The Iteration Logic:
Iteration (i)=Check A[i] against Key
-
Iteration 1: Check 55=88 ? (No)
-
Iteration 2: Check 66=88 ? (No)
-
Iteration 3: Check 77=88 ? (No)
-
Iteration 4: Check 88=88 ? (Yes)
Total Iterations (Linear)=4