Derive the Time Complexity and Space Complexity of Binary Search Algorithm


1
1 point

Time Complexity:

  • Binary Search divides the array in half with each iteration.
  • In the worst case, the number of comparisons reduces the search space by half each time.
  • This means it will take at most log₂(n) comparisons, where n is the size of the array.

Thus, the time complexity is:

O(log n)

Space Complexity:

  • Binary Search requires only a few extra variables (low, high, mid) and does not need additional space proportional to the input size.
  • If it’s implemented iteratively, the space complexity is constant.

Thus, the space complexity is:

O(1)

Like it? Share with your friends!

1
1 point
mrwixxsid

0 Comments

Choose A Format
Personality quiz
Series of questions that intends to reveal something about the personality
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Countdown
The Classic Internet Countdowns
Open List
Submit your own item and vote up for the best submission
Ranked List
Upvote or downvote to decide the best list item
Meme
Upload your own images to make custom memes
Video
Youtube and Vimeo Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format