Skip to content

Comparing approaches for searching an element in a vector.

License

Notifications You must be signed in to change notification settings

puzzlef/vector-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comparing approaches for searching an element in a vector.


Comparing Linear vs Binary search

This experiment (compare-linear-vs-binary) was for finding when is linear search faster than binary search. Both approaches were attempted on a no. of elements ranging from 10 to 1000. For each no. of elements a random int list of that size was generated, and sorted. 5 million random numbers were searched in the list with each approach, and the total time taken was measured.

Binary search is faster than linear search when the sorted list has atleast 120 elements. Unfortunately, performing a hybrid search (linear search for few elements, and binary search for many elements) does not help. Maybe this is because of the added conditional switch? A naive implementation of hybrid search also performs worse, indicating std::lower_bound has some additional optimizations. Results for hybrid search are not included here.



ORG DOI

About

Comparing approaches for searching an element in a vector.

Resources

License

Stars

Watchers

Forks