Re: O-notation
- From: Pat Farrell <pfarrell@xxxxxxxxxx>
- Date: Mon, 21 Nov 2005 16:24:15 -0500
Richard Harter wrote:
> 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.
>
> 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, ....
so more generally, it is
for (jp = 0, j=0; j<=n; j = 2 **(++jp))
Unhelpful was intentional, don't know if I agree with your use of
disservice.
--
Pat
.
- References:
- O-notation
- From: Ronny Mandal
- Re: O-notation
- From: Pat Farrell
- Re: O-notation
- From: Richard Harter
- O-notation
- Prev by Date: Re: O-notation
- Next by Date: rb-tree creation from sorted sequence
- Previous by thread: Re: O-notation
- Next by thread: [ counting sort ideea... ]
- Index(es):