|
|
|
|
|
Following are the number of operations in some algorithms.
Can you give the corresponding big - O ?
-
8 n2 + 10 n + 6
-
(n + 5)(3n -1)
-
20n + 3
-
n - 8
-
5n
Here is a small method that returns the square of the input value.
..
int getSq(int n) {
return n*n;
}
...
Can you estimate the number of operations?
Following is a small method that tries to find a match for a number in an array of integers.
Assuming n(i.e. input size) to be the length of the array (or the number of items in the array), can you estimate the number of operations and the big - o for the algorithm if no match is found in the list?
...
boolean findNumber(int[] intList, int num) {
for(int i=0; i < intList.length; i++) {
if (intList[i] == num)
return true;
}
return false;
}
...
Back to the Tutorial
|
|
|
|
|