RSS Forums RSS
Please support our Computer Science advertiser: Programming Forums
Views: 2345 | Replies: 4 | Thread Tools  Display Modes
Reply
Join Date: Sep 2005
Posts: 8
Reputation: Gotcha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Gotcha Gotcha is offline Offline
Newbie Poster

Help Need help finding the Big Oh.

  #1  
Sep 8th, 2005
Instructions:

Find the Big Oh for the times of excecution of X: = x + 1. You should justify the answer:


I : = N
WHILE I >= 1 DO
BEGIN
FOR J : = 1 TO N DO
X : = X + 1
I = [I/2]
END


Thanks for any suggestions for solving it.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,374
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 47
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: Need help finding the Big Oh.

  #2  
Sep 8th, 2005
If actual thinking fails, run through the code by hand for various values of N and notice a pattern.
Reply With Quote  
Join Date: Aug 2005
Posts: 76
Reputation: leelee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
leelee leelee is offline Offline
Junior Poster in Training

Re: Need help finding the Big Oh.

  #3  
Sep 9th, 2005
Gotcha: your post sounds exactly like a homework question. What a coincidence!

There are plenty of articles on the 'net describing big-O; a simple search will uncover them. Read some, think about your problem, then answer it. You'll be amazed at how satisfying it will be.

And, as an added bonus, you'll stand a better chance to pass your exams.
Reply With Quote  
Join Date: May 2005
Posts: 80
Reputation: indianscorpion2 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

Re: Need help finding the Big Oh.

  #4  
Sep 15th, 2005
the time complexity for this algorithm is O(N*N)
since the outer loop is executed approaximately N/2 times and the inner loop is executed N times.
just multiply both.
you get (N*N)/2.
therefore, time complexity is O(N*N).
Reply With Quote  
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,374
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 47
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: Need help finding the Big Oh.

  #5  
Sep 15th, 2005
Thanks for giving the wrong answer. The outer loop gets executed 1 + floor(log N) times.

The time complexity is not O(N*N).

[Edit: Erm, sorry for being snippy. Anyway, in the outer loop, I gets halved, not decremented, each time. The time complexity is O(N log N).]
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Computer Science Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:20 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC