Computer Science · Data Structures and Algorithms
Consider the following pseudocode of a linear search algorithm: linear(arr[], size, k) Step 1: Start Step 2: Set i = 0 Step 3: Repeat Steps 4-6 while i < size Step 4: if k = arr[i] goto Step 5 else goto Step 6 Step 5: Return i and goto Step 9 Step 6: Set i = i + 1 Step 7: If i = size goto Step 8 else goto Step 9 Step 8: Return NULL and goto Step 9 Step 9: Stop Which of the following statements is correct about the above algorithm?
- 1If the element k is present multiple times in the array, the algorithm always returns the index of the last occurrence.
- 2Step 7 is redundant, since the while loop in Step 3 already ensures termination when i = size.✓
- 3In the worst case, the time complexity of the algorithm is O(log n) because it compares sequentially.
- 4If the key is found at index 0, the total number of comparisons made is size.
Correct answer
Step 7 is redundant, since the while loop in Step 3 already ensures termination when i = size.
Download Single Question PDF
Save this question and verified answer as a clean study sheet with live clickable link.
Share with Friends & Study Groups
Challenge your peer aspirants on WhatsApp or Telegram to solve this question!
Preparing for Computer Science?
Practice full-length mock tests with real exam timers, instant score analysis, and all-India ranking.
Want more practice questions on Data Structures and Algorithms?
Solve complete topic-wise tests with detailed solutions on GkGet.
Related Practice Questions
Recommended practice questions in Computer Science · Data Structures and Algorithms