Results 1 to 1 of 1
 08132013, 07:39 PM #1Member
 Join Date
 May 2013
 Posts
 17
 Rep Power
 0
About the worstcase time complexity question
Hi, everyone. Could anybody help me check whether my answer for this question is correct?
The question is:
Consider the following Java method definition:
Java Code:public static void f(int [] a, int l, int h, int k){ int m = (l+h)/2; if (l >= h){ return; }else if (a[m] >= k){ System.out.println("left"); f(a,l,m,k); }else{ System.out.println("right"); f(a,m+1,h,k); } }
in bigOh notation:
f(a,0,a.length,5);
Briefly justify your answer.
I think the answer is O(log(n)) because it is half the data size when recursively called.
Anyone can help me check whether the answer is correct? If not, could you help to give me some tips?
Thanks!
Similar Threads

How to write the time complexity about n!
By hjxlpp in forum New To JavaReplies: 1Last Post: 06232013, 11:05 AM 
Time complexity question
By romavolman in forum Advanced JavaReplies: 8Last Post: 09192012, 07:41 PM 
I need help with Time Complexity???
By lulzim in forum Advanced JavaReplies: 2Last Post: 09202011, 10:11 AM 
I need help for Time Complexity of this???
By lulzim in forum Advanced JavaReplies: 9Last Post: 09162011, 04:51 PM 
Please tell me I am not crazy... Time Complexity (BigO) Question
By Jordan in forum New To JavaReplies: 2Last Post: 11042008, 03:48 AM
Bookmarks