HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

In which situation do we choose randomized binary search instead of the normal binary search?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
thesearchchoosesituationrandomizednormalinsteadbinarywhich

Problem

Both randomized and normal binary search takes O(log n) time complexity but why does the randomized version exist? In other words what is the advantage of randomized binary search even if it has same time complexity like that of the original binary search ?

Solution

Randomized binary search makes sense if your randomness source has a good bias towards your search target. You can then use it to reduce the expected search time (even retaining the $O(\log n)$ asymptotic worst-case complexity) as described in this answer.

If your randomness source is simply a uniform distribution, then you won't get much out of it. If you use it naively (i.e., simply choosing the midpoint according to your randomness source), it will actually perform worse than standard binary search since the worst-case complexity will be $O(n)$, not $O(\log n)$ (consider the case where your interval is $[1,n]$, your target 1, and your randomness source outputs $n-1, n-2, n-3, \dots$).

Context

StackExchange Computer Science Q#109022, answer score: 2

Revisions (0)

No revisions yet.