πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      In a binary search algorithm, what is the time

      complexity of searching an element in a sorted array of size n?Β  Β  Β 
      A O(n) Correct Answer Incorrect Answer
      B O(log n) Correct Answer Incorrect Answer
      C O(n^2) Correct Answer Incorrect Answer
      D O(1) Correct Answer Incorrect Answer
      E O(n log n) Correct Answer Incorrect Answer

      Solution

      Binary search operates by repeatedly dividing the search interval in half. If the value being searched is less than the middle element, the search continues in the left half; otherwise, it proceeds to the right half. This divide-and-conquer approach reduces the size of the search space exponentially, making the time complexity O(log n). It is efficient for searching in sorted arrays and far faster than linear search, which has O(n) complexity. Why Other Options Are Wrong: A) O(n): This is the time complexity of linear search, where every element is checked one by one, which is inefficient compared to binary search. C) O(n^2): This complexity is typically associated with algorithms like bubble sort and is irrelevant in searching. D) O(1): This represents constant time, which applies when an element can be found immediately, but it does not apply to binary search. E) O(n log n): This complexity is generally associated with efficient sorting algorithms, not binary search.

      Practice Next
      More Algorithms Questions

      Relevant for Exams:

      ask-question