Re: time complexity
Keith Thompson said:
> ashu <ashishmourya21@gmail.com> writes:
>> there is question :
>> What is the smallest value of n such that an algorithm whose running
>> time is 100n2 runs faster than an algorithm whose running time is 2n
>> on the same machine.
>>
>> i can`t understand this question plz me
>
> Ask your instructor for . This is homework, right?
>
> In any case, this isn't a question about the C programming language,
> so I don't know why you're asking it here.
>
> I also suspect you've quoted the question incorrectly. Is "100n2"
> supposd to be 100 * n * n?
I expect so. And presumably 2n supposed to be 2 to the power n.
It may the OP to recognise that the question, as asked (i.e. in the
absence of big-O notation, which IMHO would in any case make the question
meaningless), is looking for the integer value of n that is just higher
than the real value that is the solution to the following equation:
2 to the power n = 100 * n * n
This is a simple mathematical exercise. It may also be useful to realise
that, when n is set to the correct value, both 2 to the power n and 100 *
n * n easily fit in an unsigned long int. (Yes, I know, but I don't want
to be more specific than that, because it would give too much information;
what I have given, however, should enable the OP to recognise that this
problem can be solved with a very, very, very simple C program.)
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
|