What is the time complexity of performing a binary search on a sorted array of size n?

O(n)

O(log n)

The time complexity of performing a binary search on a sorted array of size n is O(log n). This efficiency arises from the way binary search operates: it repeatedly divides the search interval in half.

Initially, binary search starts by examining the middle element of the array. If the middle element is equal to the target value, the search is successful. If the target value is less than the middle element, the search focuses on the left half of the array; if greater, it narrows down to the right half. Each division of the search space reduces the number of elements to examine by half, leading to a logarithmic decrease in the number of comparisons required to find the target value.

This logarithmic property can be mathematically expressed as needing approximately log2(n) comparisons in the worst-case scenario. Therefore, for an array of size n, as n increases, the number of operations grows much slower than linear, confirming the O(log n) time complexity of binary search.

O(n log n)

O(1)

Want more questions?

All options are one-time payments.

$12.99

30 day pass for new members

All the basics to get you started

  • Ad-free experience
  • View your previous attempt history
  • Mobile app access
  • In-depth explanations
  • 30 day premium pass access
$29.99$92.93 usd

6 month DELUXE pass (most popular)

Full access FOR 6 MONTHS! & the ultimate digital PDF study guide (BONUS)

  • $92.93 usd value for $29.99! You save $62.94!
  • Ad-free experience
  • View your previous attempt history
  • Mobile app access
  • In-depth explanations
  • 6 months of full access
  • Ultimate digital PDF study guide included
  • Priority support
$14.99 $19.99

Ultimate digital PDF study guide

For those that prefer a more traditional form of learning

  • Available for instant download
  • Available offline
  • Hundreds of practice multiple choice questions
  • Comprehensive content
  • Detailed explanations
Image Description
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy