int Q (int[]values){
int len = values.length;
int res = values[0];
for (int i =1; i<len; i++){
if (values[i] > res) res = values[i];
};
return res;
}
9 replies to this topic
#1
Posted 15 April 2011 - 07:55 AM
I need help to understand how to calculate the time complexity class O() for a function:
|
|
|
#2
Posted 15 April 2011 - 01:46 PM
What do you, and don't you understand about measuring the complexity?
#3
Posted 15 April 2011 - 02:36 PM
For this function above for example what is time complexity?
#4
Posted 15 April 2011 - 02:37 PM
What do you think it is? What variables affect how long it runs? How do they affect the runtime?
#5
Posted 15 April 2011 - 02:40 PM
O(N)?
#6
Posted 15 April 2011 - 02:43 PM
This appears to be a basis level question, are you taking a class of which teaches this? I would consult your instructor or learning material to the definitions of each of the asymptotic notations and theorize what fits the best one.
I will start you with the most efficient of the pair, constant time, which can be written as O(1).
I will start you with the most efficient of the pair, constant time, which can be written as O(1).
- An algorithm is said to be constant time if the value of T(n) is bounded by a value that does not depend on the size of the input.
- An algorithm is said to be linear time if the value of T(n) is bounded by a value that increases linearly with the size of the input. O(n).
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#7
Posted 15 April 2011 - 05:52 PM
The first thing I would do: pass in a few different sized arrays, and note how many statements are executed, based on each size. Which statements are responsible for the difference in the number of statements executed?
#8
Posted 16 April 2011 - 12:01 AM
I think 'for' and 'if' statments are responsible
#9
Posted 16 April 2011 - 06:49 AM
Does increasing the size of the array make the if statement take longer to run? Remember to initially look at each line independent of the others.
#10
Posted 16 April 2011 - 08:19 AM
I think got the meaning...regardles the array size, if function always executed one time, then is O(1), if time increased as array increased then is O(N) or O(N^2) and so on...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









