Need help with calculating Big-O notation. Please show each steps. public static void a(int n) { O(3n+2) = O(n) ?

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
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) ?

Post by answerhappygod »

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;
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply