[solved] – Question 84586
Find the time complexity of the following algorithms in terms of Big O.
1)A function (or set of statements) that doesn’t contain loop, recursion and call to any other non-constant time function.
2)A loop or recursion that runs a constant number of times, such as follows:
for (int i = 1; i <= c; i++) // Here c is a constant
{
// some O(1) expressions
}
3)A loop where the loop variables is incremented / decremented by a constant amount, as follows:
// Here c is a positive integer constant
for (int i = 1; i <= n; i += c) {
// some O(1) expressions
}
4)Time complexity of nested loops as follows:
// Here c is a positive integer constant
for (int i = 1; i <=n; i += c) {
for (int j = 1; j <=n; j += c) {
// some O(1) expressions
}
}
//Or the following nested loop
for (int i = n; i > 0; i += c) {
for (int j = i+1; j <=n; j += c) {
// some O(1) expressions
}
Expert Answer
OR

