Find $n$ such that $n\sqrt5 - \lfloor{n\sqrt5}\rfloor$ is maximised or minimised?

Locating a real number in the Stern–Brocot tree gives good rational approximations with increasing denominators.

For $\sqrt5$, below is the output for denominators at most $2009$. The last line says that the best approximations with this restriction on denominators are $3571/1597$ and $2889/1292$. The denominators in these two fractions are the ones you seek. You just need to test which is which.

$$ \begin{array}{rrrrr} n& a& b& c& d& \\ 1& 1& 1& 1& 0 \\ 2& 2& 1& 1& 0 \\ 3& 2& 1& 3& 1 \\ 4& 2& 1& 5& 2 \\ 5& 2& 1& 7& 3 \\ 6& 2& 1& 9& 4 \\ 7& 11& 5& 9& 4 \\ 8& 20& 9& 9& 4 \\ 9& 29& 13& 9& 4 \\ 10& 38& 17& 9& 4 \\ 11& 38& 17& 47& 21 \\ 12& 38& 17& 85& 38 \\ 13& 38& 17& 123& 55 \\ 14& 38& 17& 161& 72 \\ 15& 199& 89& 161& 72 \\ 16& 360& 161& 161& 72 \\ 17& 521& 233& 161& 72 \\ 18& 682& 305& 161& 72 \\ 19& 682& 305& 843& 377 \\ 20& 682& 305& 1525& 682 \\ 21& 682& 305& 2207& 987 \\ 22& 682& 305& 2889& 1292 \\ 23& 3571& 1597& 2889& 1292 \\ \end{array} $$ Here is Python code to generate this table:

from math import sqrt
t=sqrt(5)
a,b=0,1
c,d=1,0
n=0
while 1:
    n=n+1
    e=a+c
    f=b+d
    s=(e+0.0)/f
    if s<t:
        a,b=e,f
    else:
        c,d=e,f
    print(n,a,b,c,d)
    if b>2009 or d>2009:
        break

Another method is to use the familiar Fibonacci approximants for $\phi=(1+\sqrt{5})/2$. Rendering $\sqrt{5}=2\phi-1$, carry the upper bounds until you get a maximum odd denominator $\le 2009$, or a maximum even denominator $\le 2×2009$, and take whichever is later:

$\frac{2}{1},\frac{5}{3},\frac{13}{8},...\frac{1597}{987},\color{blue}{\frac{4181}{2584}}$

Do the same with the lower bounds:

$\frac{1}{1},\frac{3}{2},\frac{8}{5},...\frac{987}{610},\color{blue}{\frac{2584}{1597}}$

So the optimal bounds within the problem constraints are:

$\frac{2584}{1597}<\phi<\frac{4181}{2584}$

and with $\sqrt{5}=2\phi-1$:

$\frac{3571}{1597}<\sqrt{5}<\frac{2889}{1292}$.