Question
1. What is the time complexity of the algorithm below? void algorithm1 (int n) { int x = 0; for (int i = 0; i
1. What is the time complexity of the algorithm below? void algorithm1 (int n) { int x = 0; for (int i = 0; i < n; ++i) for (int j = i; j < n; ++j) for (int k = 1; k < 100; ++k) x += 1; } 2. What is the time complexity of the algorithm below? void algorithm ( int n ) { int i, j, k; int m = 0; for ( i = 0; i < n; i++) { for ( j = 1; j < n; j += 2) { for ( k = 1; k < n; k *= 2) { m += k; } } } } 3.
What is the time complexity of the algorithm below?
int algorithm (int n) { if (n == 1) return 1; else return 2 * algorithm (n/2); } I think the answers are O(n^3), O(n^3) and O(log n)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started