Using an ordering algorithm for prime numbers less than 1,000,000 I get the following execution times:
|Prime numbers|--Time
100--.039s
1000--.039s
10,000--.209s
50,000--.299s
78498--.301s
The problem says "fit a curve via least squares type $a(\lg(n))^2+b(\lg(n))+c$".
Theoretically the algorithm has execution time $O((\lg(n))^2)$.
I am somewhat lost on the subject of least squares,my algorithm class does not cover this topic, I do not ask to solve the problem, only guidance on how to start with the adjustment or what things should be done.
Since the algorithm is $O(lg(n))^2$, we can express the time complexity as $T(n)= a(lg(n)^2+b(lg(n))+c$, for some constants $a,b,c$ and try to estimate the constants from the data using non-linear least squares model.
For example, the below code snippet shows how we can estimate $a,b,c$ with
R, where the runtime data is stored in a dataframedf:Now, let's visualize how the NLS model predicted runtime compare with the actual runtime values for different values of $n$, using the following code snippet:
The black datapoints represent the original runtimes for the corresponding $n$s, whereas the red dotted curve represents the one predicted by the fitted NLS model.