What is the binary search algorithm and when should you use it?

Technical
Easy
Infosys
127.3K views

Candidates must explain binary search mechanics and prerequisites. This tests algorithmic knowledge and conditional logic.

Why Interviewers Ask This

Binary search is a cornerstone algorithm for interviews. Interviewers ask this to ensure candidates understand logarithmic time complexity and the requirement for sorted data. It also tests their ability to implement the logic correctly without infinite loops.

How to Answer This Question

Define binary search as a divide-and-conquer algorithm for sorted arrays. Explain splitting the search space in half based on comparisons. Mention the O(log n) time complexity. Highlight that the data must be sorted beforehand.

Key Points to Cover

  • Requires sorted data
  • Divide and conquer
  • Logarithmic time complexity
  • Middle element comparison

Sample Answer

Binary search is an efficient algorithm to find an element in a sorted array by repeatedly dividing the search interval in half. I compare the target value with the middle element; if they match, the search is done. If t…

Common Mistakes to Avoid

  • Applying to unsorted arrays
  • Incorrect midpoint calculation causing overflow
  • Infinite loops due to boundary errors

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 180 Technical questionsBrowse all 149 Infosys questions