Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Consider the following code fragment. Analyze its running time and express your answer as (f(n)), for some function f of n. It is possible

image text in transcribed

1. Consider the following code fragment. Analyze its running time and express your answer as (f(n)), for some function f of n. It is possible to solve this problem by precisely figuring out how many times the print statement is executed. This will involve coming up with a sum and finding a closed form solution to it. I would like you to follow a less tedious approach, outlined below: (a) Show that the running time is O(n3). You can do this by "overestimating" the work done bv the code fragment, e.g., bv allowing i and k variables to travel through a bigger range of values. (b) Show that the running time is (n3). You can do this by "underestimating" the work done by the code fragment, e.g., by restricting your attention to when i travels from 1 to n/3 and j travels from 2n/3 to n. (c) Using (a) and (b), conclude that the running time of this code fragment is (n3). for i 1 to n do for j i + 1 to n do for k i to j do print("hello")

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions