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 with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions