Tip:A–D to answerE for explanationV for videoS to reveal answer
What is the worst-case time complexity of linear search algorithm?
- A.
O(n)
(Correct Answer) - B.
O(i)
- C.
O(logn)
- D.
O(n2)
Explanation
1. Worst-Case Scenario: Worst-case tab hota hai jab:
2. Number of Comparisons: Agar array ka size n hai:
-
Pehle element ke liye: 1 comparison
-
Doosre element ke liye: 2 comparisons
-
...
-
n-th element (aakhri) ke liye: n comparisons
Total Comparisons in Worst Case=n
3. Mathematical Representation: Kyunki time complexity seedhe taur par input size (n) ke proportional hai, isliye ise Big-O notation mein aise likha jata hai:
Worst-case Complexity=O(n)