Can we use a linear search instead of a binary search to find insertion position, without incurring any significant runtime penalty?

Viewed 114
2 Answers

My guess is if you are searching for number i, instead of searching from the beginning, you can start searching from the index i. But this only works well if the numbers do not contain a lot of duplicates.

The problem will cost O(n) both in linear search and binary search, so just do the easier linear search.

Related