Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to choose linear search over binary search

After having searched the internet I was not able to satisfy myself that I had found a comprehensive set of situations in which a linear search would be preferable to a binary search.

I am essentially wondering whether it would be possible to compile a relatively definitive list of advice (from the point of view of general programming as one might find in industry). Alternatively I would much appreciate it if it could be verified that indeed I have seen all there is to say on the subject.

like image 563
user3444063 Avatar asked Nov 01 '22 03:11

user3444063


1 Answers

My list of reasons for choosing a linear search over a binary search are as follows:

  1. The list is unsorted and is only to be searched once

  2. The list is small (though this itself is a vague notion - I've read less than around 100 elements?)

  3. The list will need sorting following the search operation (due to say an insertion), since the resorting will dominate the time complexity of the overall task

  4. The data structure is not random access (like a linked-list)

  5. There is no knowledge of the data that could aid searching (relative proximities?)

like image 113
user3444063 Avatar answered Nov 15 '22 10:11

user3444063