ACM Forums Forum Index
ACM Forums
Welcome to the bulletin board for UNL's official computer science organization!
Reply to topic
OMG algorithm analysis
civilmass


Joined: 08 Mar 2006
Posts: 52
Reply with quote
int i, j, k=n
for(i=0; i<n && k >= i-1; i++){
j=n-2; k=-2;
while (j>=0){
for (;j>=0 && A[j+1] >= A[j]; j--);
if (j>=0){
swap(A,j+1,j); k=j; //swap takes constant time
}
}
}


that is the code. I am having a problem with this one. Any ideas? I just need to know the time complexity

_________________
Civilmass
View user's profileSend private messageSend e-mail
rockhead85
ACM Secretary

Joined: 08 Mar 2006
Posts: 62
Reply with quote
From a quick glance, I think it is a bubble sort.
(Correct me if I'm wrong)

If I'm correct, it should be n^2. Right?
But since it has that 'for' loop, it should be n^3. I'll go with n^3.

Mind if you tell me where you got the code?
View user's profileSend private message
civilmass


Joined: 08 Mar 2006
Posts: 52
Reply with quote
I got it from my teacher Stephen Scott. He gave us a bunch of peices of code and we have to prove the big O big (omega) and big (thetta) for each of them. Most of them were pretty easy but that one was quite hard to solve. I did talk to derek about that one and he had Professor scott as a teacher and said that he likes to do stuff like that where it is a sorting algorithm that we know bu he changes it to make it look ridiculously hard. Well thanks for the help man!!!

_________________
Civilmass
View user's profileSend private messageSend e-mail
rockhead85
ACM Secretary

Joined: 08 Mar 2006
Posts: 62
Reply with quote
That code was the piece of code I've ever read.
View user's profileSend private message
civilmass


Joined: 08 Mar 2006
Posts: 52
Reply with quote
Quote:
That code was the piece of code I've ever read.


Hmm.... I bet it was.... did not get enough sleep??

_________________
Civilmass
View user's profileSend private messageSend e-mail
rockhead85
ACM Secretary

Joined: 08 Mar 2006
Posts: 62
Reply with quote
Lol. No I didn't (had 1 hour sleep)

What I wanted to say was, "That was the worst piece of code I've ever read."
View user's profileSend private message
Kano


Joined: 15 Sep 2006
Posts: 1
Reply with quote
That could be in the Obfuscated C Code Contest. I guess it itself isn't that bad, most of the stuff in the contest is one line if i remember right, but yeah, it does break a few unwriten rules.

_________________
(1) A sheet of paper is an ink-lined plane.
(2) An inclined plane is a slope up.
pla(3) A slow pup is a lazy dog.

QED: A sheet of paper is a lazy dog.
-- Willard Espy, "An Almanac of Words at Play"

Kyle Brown
View user's profileSend private messageVisit poster's website
OMG algorithm analysis
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 6 Hours  
Page 1 of 1  

  
  
 Reply to topic