You get silently wrong results, it will report "not found" for elements that are present, and possibly return wrong indices, with no error or crash. Binary search's correctness rests entirely on the sorted invariant: it discards half the array based on a single comparison, assuming everything in the discarded half is on the wrong side of the key. If the data isn't sorted, that assumption is false, so it throws away the half that might contain the key. The dangerous part is that it appears to work, it returns a plausible-looking answer, so the bug hides until a missing-element lookup causes a downstream failure. The sorted precondition is a contract the caller must guarantee (sort the table, or build it sorted at compile time); binary search doesn't and can't cheaply verify it, since checking sortedness is itself O(n), which would defeat the O(log n) benefit. This is why sorted lookup tables are typically sorted once at build time and treated as immutable.
Data Structures & Algorithms · Interview question
What happens if you binary-search an unsorted array?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Linear & Binary Search
O(n) linear scan works on anything; O(log n) binary search needs sorted data and gives deterministic worst-case timing, plus the overflow and off-by-one bugs that haunt it.