Which of the following is the worst case time complexity of the linear search algorithm when 'n' is the number of elements in the list?
Which of the following is the worst case time complexity of the linear search algorithm when 'n' is the number of elements in the list?
Solution
Linear search compares the target with each element one by one. In the worst case, the target is the last element or is not in the list at all, so all elements are checked. The number of comparisons grows in direct proportion to , so the worst case time complexity is .
Option 1: is the best case, where the target is the first element.
Options 2 and 4: these are the costs of sorting algorithms such as merge sort and bubble sort, not of a single pass through the list.
Related questions:
2026: 31 May Shift 1
2025: 22 May Shift 1
2025: 13 May Shift 2
2026: 13 May Shift 2