What is the worst-case time complexity of the linear search algorithm for an array of size "n"?आकार "एन" के एक सरणी के लिए रैखिक खोज एल्गोरिथ्म की सबसे खराब स्थिति की जटिलता क्या है?
आकार "एन" के एक सरणी के लिए रैखिक खोज एल्गोरिथ्म की सबसे खराब स्थिति की जटिलता क्या है?
Show answerHide answer
Correct answer: (B) O(n)ओ (एन)
Explanation
In the worst case the element is at the last position or absent, so linear search compares with all n elements. That makes it O(n).सबसे खराब स्थिति में तत्व आखिरी स्थान पर होता है या होता ही नहीं, इसलिए linear search सभी n तत्वों से तुलना करता है। इससे यह O(n) होता है।