n.
f(n) .
f(n), where n is the size of the input.
f(n) = 3n + 2
for (int i = 0; i < n; i++)
{
System.out.println("Hi");
}
for (int i = 1; i <= n; i++)
{
System.out.println("Hello");
}
f(n) = 1 // initialization
+ (n + 1) // comparisons
+ n // increments
+ n // print operations
f(n) = 3n + 2
3n+2 to O(n)).
for (int i = 1; i <= n; i++)
{
System.out.println(i*2);
}
f(n) = 3n + 3
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
System.out.println("Hello");
}
}
f(n) = (2n+2) + n*(3n+2) β 3nΒ² + 4n + 2
f(n): n Γ n = nΒ².
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
System.out.println("Hello");
}
}
f(n, m) = (2n+2) + n*(3m + 2) β 3nm + 4n + 2
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weβre here to make our tutorials better based on your thoughts and suggestions.