Re: O-notation
- From: cri@xxxxxxxx (Richard Harter)
- Date: Mon, 21 Nov 2005 21:00:34 GMT
On Mon, 21 Nov 2005 10:40:40 -0500, Pat Farrell <pfarrell@xxxxxxxxxx>
wrote:
>Ronny Mandal wrote:
>> for (i = 1; i<= n; i++)
>> for (j = 1; j<=n; j = 2 *j)
>>
>> Since this contains two loops tht increments their index by 2*1, 2*2,
>> 2*3 ...2*n, and the outer is linear I would say that the running-time
>> is n(log n)^2.
>
>You'd be better off doing your own homework.
>
>Hint:
> for (j = 1; j<=n; j = 4 * j)
> for (j = 1; j<=n; j = 2 * j)
>are the same O
Your statement, while true, is a disservice. Our hapless hero has
given the right answer accompanied with an error in reasoning. The
two loops do not increment "index by 2*1, 2*2, 2*3 ...2*n", they
double it each time, i.e., j= 1, 2, 4, 8, .... In consequence the two
inner loops are both O(log n). Of course, as you say, multiplying it
by 4 each time is also O(log n), but that has nothing to do with the
error in his reasoning.
Richard Harter, cri@xxxxxxxx
http://home.tiac.net/~cri, http://www.varinoma.com
I started out in life with nothing.
I still have most of it left.
.
- Follow-Ups:
- Re: O-notation
- From: Pat Farrell
- Re: O-notation
- References:
- O-notation
- From: Ronny Mandal
- Re: O-notation
- From: Pat Farrell
- O-notation
- Prev by Date: Re: O-notation
- Next by Date: Re: O-notation
- Previous by thread: Re: O-notation
- Next by thread: Re: O-notation
- Index(es):
Relevant Pages
|