How to find the position of an element in a vector

62 Views Asked by At

Given the vector: $$v=[a_1,a_2,\ldots,a_N]$$ where $N\in\mathbb{N}$ and $v_j\in\mathbb{R}$ with $a_j\lt a_{j+1}$ and given a number $b$ with $b\in\mathbb{R}$ what is the fastest algorithm to find the position of $b$ inside $v$ such that $a_k\le b\le a_{k+1}$? Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

Bisection, also known as binary search. It has $\log N$ complexity and I don’t see how to beat that.