Answered step by step
Verified Expert Solution
Link Copied!

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)).

  1. for(int i = 1; i < n; i++) sum++; 
  2. 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; } } } 
  3. for(int i = n; i > 0; i = i / 3) sum++; 
  4. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

=+b) What is the interpretation of the coefficient for Pedro Start?

Answered: 1 week ago