Shortcuts binary search algorithm

I’ve not attempted to create one, until you posted this, but maybe something like this?

I’ve tried to use some more explicitly named variables, some comments and even a bit of extra code for debugging to try and help anyone reading it make sense of it. As a result of all of the extra cruft, I’m sure it is running slower.

If you wanted to speed things up, it might make sense to look at a recursive shortcut that splits the list or simply keeps passing it along and effectively turn it into a function / parameter based subroutine.

Alternatively, I’m pretty sure that if your data set was large enough to warrant such a search for performance reasons, that it would further be worth applying JavaScript to the approach as it could then take advantage of browser optimisations. I posted a solution to something else recently that takes exactly that sort of thing to consideration…

Hope that helps.

1 Like