MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
The worst case occurs in linear search algorithm when ____
A
Item is not in the array at all
B
Item is somewhere in the middle of the array
C
Item is the last element in the array or item is not there at all
D
Item is the last element in the array
Explanation: 

Detailed explanation-1: -The worst case occurs in the Linear Search Algorithm when the item to be searched is in end of the Array.

Detailed explanation-2: -For Linear Search, the worst case happens when the element to be searched (x) is not present in the array. When x is not present, the search() function compares it with all the elements of arr[] one by one. Therefore, the worst-case time complexity of the linear search would be O(n).

Detailed explanation-3: -Time Complexity of Linear Search The worst-case time complexity is O(n), if the search element is found at the end of the array, provided the size of the array is n.

There is 1 question to complete.