Question 18Asked in Bihar STET 2024 Paper II Computer Science, 12 Jun 2024, Shift 1 (10:00 AM)

What is the worst-case time complexity of the linear search algorithm for an array of size "n"?आकार "एन" के एक सरणी के लिए रैखिक खोज एल्गोरिथ्म की सबसे खराब स्थिति की जटिलता क्या है?

आकार "एन" के एक सरणी के लिए रैखिक खोज एल्गोरिथ्म की सबसे खराब स्थिति की जटिलता क्या है?
  1. AO(log n)ओ (लॉग एन)
  2. BO(n)ओ (एन)
  3. CO(n^2)ओ (एन^2)
  4. DO(1)ओ (1)
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) होता है।

From Bihar STET 2024 Paper II Computer Science PYQ, 12 Jun 2024, Shift 1 (10:00 AM)

This is question 18 of Bihar STET 2024 Paper II Computer Science PYQ, 12 Jun 2024, Shift 1 (10:00 AM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.