Need help with calculating Big-O notation. Please show each
steps.
public static void a(int n) { O(3n+2) = O(n) ?
int a = 0; // 1
int i = 0; // 1
while (i < n) { // n
a = i; //
n
i++; // n
}
}
public static void b(int n) {
int a = 0; // 1
for(int i = 0; i < n; i += 3) {
// 1 + n +
a = i;
}
}
public static void c(int n) {
int a = 0; // 1
int i = 0; // 1
while (i < n) { // n
for (int j = n;
n > 0; n = n/10) {
a = i + j;
}
i++; // n
}
}
public static void d(int n) {
int a = 0; // 1
for(int i = 0; i < n; i += 1)
{
for(int j = i; j
< n; j += 1) {
a = i + j;
}
}
}
public static void e(int n) {
int a = 0; // 1
for(int i = 0; i < n * n; i +=
1) {
for(int j = 0; j
<= n; j += 1) {
a = i + j;
}
}
}
public static void f(int n) {
int k = 1, a = 0; // 1 + 1
for(int i = 0; i < n; i += 1) {
// 1 + n + n
for(int j = 0; j
<= k * 2; j += 1) {
a = i + j;
}
k = k * 2;
}
}
Need help with calculating Big-O notation. Please show each steps. public static void a(int n) { O(3n+2) = O(n) ?
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Need help with calculating Big-O notation. Please show each steps. public static void a(int n) { O(3n+2) = O(n) ?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!