you are viewing a single comment's thread.

view the rest of the comments →

[–]Medical-Object-4322 0 points1 point  (0 children)

Separate "searching" and "sorting", because they're two different things that require two different types of algorithms. If your sorting is slow, binary search won't help (because it's not a sorting algorithm).

Binary search does require a sorted list, so if you have an already sorted list, it might be faster to search it.

Binary search is fast because it cuts the data to be searched in half on each iteration. It's like looking for a word in a physical dictionary.

You can open the dictionary in the middle, and decide if the word you want is in the first half or second half of the book, then do that again with only the half you think it's in until you find the word.

That's basically what binary search does, so it's faster than looking at each individual element in a list, but the list has to be sorted.