Question trying to physically understand Algorithm run time as proportion

60 Views Asked by At

In CLRS, there's a question in the first chapter that says for certain functions $run time = f(n)$, to calculate the max number of $n$ given the run time. The math works out simply. For example, for $f(n) = \sqrt{n}$ microseconds, given a 1 second run time there is ${\frac{1\ second}{10^{-6}\ seconds}}^2$ inputs $n$, which I got from $\sqrt{n}\ microseconds = 1\ second$ and solving for n.

My confusion comes from trying to make a proportion for the system like I would for a dimensional analysis problem. I have $\frac{\sqrt{n}\ microseconds}{n\ inputs}$ and the other fraction is $\frac{1\ second}{x\ inputs}$. Here when I solve for $x$ I get $10^6*\sqrt{n}$. I think my dimensions don't make sense somehow, but in my head, saying 'it takes square root of n microseconds for n inputs' comes out as $\frac{\sqrt{n}\ microseconds}{n\ inputs}$.

Thank you!!

1

There are 1 best solutions below

0
On BEST ANSWER

Since no one really answered this, this is what I think is some physical intuition behind the situation.

It takes $\sqrt{n}\ microseconds$ to solve a given problem, so no matter what it is true that it took $\frac{\sqrt{n}\ microseconds}{problem\ of\ any\ size\ n}$. So if the problem took 1 second to solve (for whatever n), the fraction would be $\frac{1\ seconds}{problem\ of\ size\ n}$. And since we know the first fraction is always true we can set up a proportion $\frac{\sqrt{n}\ microseconds}{problem\ of\ any\ size\ n} = \frac{1\ seconds}{problem\ of\ size\ n}$. So now we can solve the proportion for $n$.