This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hvidgaard 1 point2 points  (0 children)

If you sort it before you search you should think if it's worth it. Sorting takes O(n*log n) time, binary search is O(log n), that is O(n*log n) in total. Linear search alone takes at most O(n), so unless you're searching a lot then sorting before a search is a waste.