Optimal rates for k-NN density and mode estimation