Thread: Big-oh Notation
View Single Post
Old Sep 8th, 2004, 3:52 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
void function(vector<int>& g) {

for (int a = 0; a < g.size(); a++) {
for (int z = 0; z <g.size(); z++) {
//constant body
}
}
}
N == the size of the input (as all the text books say!!)

I think you are on teh right track cant say 100% though.

inner loop has to run through N*N iterations (eg if size = 10 then obviously inner loop runs 10 times, for each outer loop so 10 * 10 which is 10^2)

So yeah it is N^2, not to sure about the O thing though, never seen it at my uni.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote