10 Replies Latest reply: Feb 25, 2009 12:33 AM by 843785

# complexity of an algorithm

Hi guys,

I don't know whether somebody can help me. I have 2 algorithms and I need to find their best and worst case in terms of the big O notation.

The first 1 is:

for(i = 0; i < = n; i++){
for(j = 0; j < = n; j++){
C[i,j] = A[i,j] + B[i,j]
}
}

The second 1 is:

while (n > = 1){
• ###### 1. Re: complexity of an algorithm
And this has what to do with Java?

(HINT: The answer rhymes with "nothing.")
• ###### 2. Re: complexity of an algorithm
Muffin rhymes with nuffin'
• ###### 3. Re: complexity of an algorithm
DrLaszloJamf wrote:
Muffin rhymes with nuffin'
Puffin (which is kind of an awk; at least that's what Wikipedia sed).

~
• ###### 4. Re: complexity of an algorithm
I have a year-old puffin
I keep it as a pet.
I feel it day-old muffin
And keep it from the wet.

And although I'd like to toughen
It, and teach it Java complexity
I worry there's positively nuffin'
To deal with its perplexity!
• ###### 5. Re: complexity of an algorithm
doobybug wrote:
Hi guys,

I don't know whether somebody can help me. I have 2 algorithms and I need to find their best and worst case in terms of the big O notation.
...
Have you any idea yourself? Explaining what you yourself think (or have thought of), will go a long way in a public forum. It now looks like you didn't give it any thoughts of yourself and are hoping that someone else will do this for you. Before you go into a "don't assume that I..."-mode, note the words "looks like" in my post.
• ###### 6. Re: complexity of an algorithm
doobybug wrote:
Hi guys,

I don't know whether somebody can help me. I have 2 algorithms and I need to find their best and worst case in terms of the big O notation.

The first 1 is:

for(i = 0; i < = n; i++){
for(j = 0; j < = n; j++){
C[i,j] = A[i,j] + B[i,j]
}
}

The second 1 is:

while (n > = 1){
Very simple. The worst case for the first is O(n*n) and for the second it's O(n). It's because of the looping.

The best case is the same as the worst case unless any of the algorithms can "break" out prematurely.
• ###### 7. Re: complexity of an algorithm
Way to spare the OP the horror of thinking for himself, uj.
• ###### 8. Re: complexity of an algorithm
jverd wrote:
Way to spare the OP the horror of thinking for himself, uj.
uj????

The OP came here for advice, not to suffer what's on your mind.

Besides, I just offered a pointer.
• ###### 9. Re: complexity of an algorithm
if you have to ask how complex an algorithm is it's too complex for you to comprehend >:=)
• ###### 10. Re: complexity of an algorithm
Sorry, but the second one is not defined as long as you don't know how n changes