Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Give an analysis of the running time (Big-Oh notation) for each of the following 4 program fragments. You must provide calculate the computational cost

1. Give an analysis of the running time (Big-Oh notation) for each of the following 4 program fragments. You must provide calculate the computational cost of each line of code that shows how you estimated the code snippets running time. Note that the running time corresponds here to the number of times the operation sum++ is executed. sqrt is the function that returns the square root of a given number.

(a

)sum = 0; for(i=0;i

b)

sum = 0;

for(i=0;i

for(j=i;j<8+i;j++)

for(k=j;k<8+j;k++)

sum++;

(c)

sum = 0; for(i=1;i<2*n;i++) for(j=1;j

if (j % i == 1)

sum++;

(d)

sum = 0; for(i=1;i<2*n;i++) for(j=1;j

2. If it takes 10ms to run program (b) for n=100, how long will it take to run for n=400

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

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

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions