-1
$\begingroup$

For 1,000 items, our algorithm takes 10 sec. to run on machine A, but now you replace the machine with machine B that is 2 times as fast. Approximately how long will that algorithm take to run on machine B for 2,000 items if the algorithm is:

a. linear (o(n))

b. quadratic(o(n^2))

c.o(n log n)

I solved quadratic and I got 40sec but I could't figure out linear and nlogn. can anyone help me?

  • 0
    Don't forget that machine $B$ is 2 times faster.2017-02-15
  • 0
    The usual definitions of computational complexity are about *asymptotic* behaviour, i.e., they tell you how well an algorithm performs on average for arbitrarily large inputs. The fact that an algorithm is asymptotically linear in time complexity (say) doesn't allow you to deduce anything about its performance on a small number of specific examples.2017-02-16

1 Answers 1

0

$40$ seconds would be correct if you didn't have a faster machine. You have twice as many items so have to do $2^2=4$ times the calculations, but the machine is twice as fast so it takes ???

For linear the ratio of calculations is just $2$ and for $n \log n$ it is $\frac {2000 \log (2000)}{1000 \log(1000)}$

  • 0
    last expression can be simlified to $\sim2(1+\frac{1}{10})$ considering algorithms always use $\log_2$2017-02-15
  • 0
    @zwim: Correct. I was leaving that to OP, but no problem2017-02-15
  • 0
    Duh? How does the asymptotic time complexity allow you to deduce anything about the run time on specific cases?2017-02-16
  • 0
    @RobArthan: you have to trust the problem setter to have chosen cases large enough that the leading term is dominant. In that case we know how it scales. We don't know the absolute number, but we don't need that, because it was measured at $1000$ items.2017-02-16
  • 0
    @RossMillikan: that's absurd. Who is this "problem setter" who makes choices that determine physical or mathematical reality?2017-02-16
  • 0
    @RobArthan: If we are told that it scales as $n^2$ and we have twice as many items, we should expect it to take four times as long. We don't need to know any more than the scaling to answer the question. It is true that under the rules of these things it could really be $2n^2+5000n$ and we wouldn't be in the regime the leading term is all that matters, but that would make it an unfair question.2017-02-16