Results 1 to 7 of 7
Thread: time complexity questions
- 07-12-2010, 09:53 PM #1
Member
- Join Date
- May 2010
- Posts
- 44
- Rep Power
- 0
time complexity questions
what are the time complexities in these two cases, big O notation.
1.Java Code:int a =3; while (a <= n) a = a*a;
2.for number 1, I would guess it would have something to do with log(_3)nJava Code:public void foo (int n, int m) { int i = m; while (i > 100) i = i/3; for (int k=i ; k>=0; k--) { for (int j=1; j<n; j*=2) System.out.print(k + "\t" + j); System.out.println(); } }
and the second one i'm just confused. although the general rule is that with two loops is O(n^2), but i'm assuming they're tricking us here...
- 07-12-2010, 10:09 PM #2
Is this a java programming question?
- 07-12-2010, 10:21 PM #3
Member
- Join Date
- May 2010
- Posts
- 44
- Rep Power
- 0
I dunno. It's part of my Intro to Computer Sciences - Java course...
- 07-13-2010, 06:11 AM #4
Member
- Join Date
- May 2010
- Posts
- 44
- Rep Power
- 0
Does anyone have an idea??
- 07-13-2010, 07:17 AM #5
In 1, what is 'n'. If it is integer and initialized (say n=3), then 'a' be 9.Java Code:int a =3; while (a <= n) a = a*a;
In 2, pass m=300 and n=5, see the result your self. even better, try while (i>10), have smaller loop.Java Code:public void foo (int n, int m) { int i = m; while (i > 100) i = i/3; for (int k=i ; k>=0; k--) { for (int j=1; j<n; j*=2) System.out.print(k + "\t" + j); System.out.println(); } }
- 07-13-2010, 08:15 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
- 07-13-2010, 11:02 AM #7
Similar Threads
-
Time complexity - foor loop
By hawaiifiver in forum New To JavaReplies: 5Last Post: 02-05-2011, 04:06 PM -
Time Complexity Java Code?
By Lyricid in forum New To JavaReplies: 11Last Post: 12-08-2009, 04:27 PM -
complexity issue!!
By deepa8400 in forum New To JavaReplies: 4Last Post: 08-25-2009, 04:25 AM -
Please tell me I am not crazy... Time Complexity (Big-O) Question
By Jordan in forum New To JavaReplies: 2Last Post: 11-04-2008, 02:48 AM -
Singleton considered stupid, Java and complexity
By fishtoprecords in forum Forum LobbyReplies: 11Last Post: 07-06-2008, 03:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks