Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Examine the following code blocks and give the Big-Oh run time of the code blocks in simplest terms of n (with coefficients of 1 and
Examine the following code blocks and give the Big-Oh run time of the code blocks in simplest terms of n (with coefficients of 1 and lower-order terms dropped out e.g. O(n) not O(2n+1)).
-
for(int i = 1; i < n; i++) sum++;
-
for(int i = 1; i < n; i++) { if( i % 2 == 0 ) { array[i] = 0; } else { for( int j = 0; j < n/2; j++ ) { array[j] = 1; } } }
-
for(int i = n; i > 0; i = i / 3) sum++;
-
for(int i = n; i > 0; i = i / 3) for( int j = i; j < n; j++ ) sum++;
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