What is the time complexity of the following procedure?
for $x \in \{1,\ldots,n\}$:
$\quad$ $i \gets \lfloor n/2 \rfloor$
$\quad$ while $i \neq x$:
$\quad\quad$ if $i > x$ then $i \gets i -1$, otherwise $i \gets i + 1$.
According to me, the time complexity will be O(n^2),is $O(n^2)$. theThe inner loop while startloop starts at N/2$n/2$ and movemoves towards the value of x$x$, Worstworst case it runs N/2$n/2$ times, and best case it runs 0$0$ times, but I am still wanna know what could be the exact time complexity, can anyone help me to understand it, please? Thanks.
What is the exact time complexity of this procedure?