Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Determine the run time equation and complexity of each of the following code segments. 1. for (i=0;i

Determine the run time equation and complexity of each of the following code segments.   

1. for (i=0;i<n;i++)

         for (j=0;j<n; j++)

 

             sum=sum+i+j;

 

What is the value of the sum if n=100?

 

 

 

2. for(int i=1; i<=n; i++)

 

               for (int j=1; j<=i; j++)

 

              sum++;

 

What is the value of the sum if n=20?

 

 

 

3. int k=0;

 

   for (int i=0; i<n; i++)

 

      for (int j=i; j<n; j++)

 

         k++;

What is the value of k when n is equal to 20?

4. int k=0;

   for (int i=1; i<n; i*=2)

       for(int j=1; j<n; j++)

             k++;

What is the value of k when n is equal to 20?

 

5.     int x=0;

for(int i=1;i<n;i=i+5)

     x++;

What is the value of x when n=25?

 

 

6.     int x=0;

for(int k=n;k>=n/3;k=k-5)

    x++;

What is the value of x when n=25?

 

7.     int x=0;

for (int i=1; i<n;i=i+5)

   for (int k=n;k>=n/3;k=k-5)

       x++;

What is the value of x when n=25?

 

8.     int x=0;

for(int i=1;i<n;i=i+5)

    for(int j=0;j<i;j++)

         for(int k=n;k>=n/2;k=k-3)

                x++;

 

What is the correct big-Oh Notation for the above code segment?

Step by Step Solution

3.50 Rating (157 Votes )

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

Visual C# How to Program

Authors: Paul J. Deitel, Harvey Deitel

6th edition

134601548, 134601793, 978-0134601540

More Books

Students also viewed these Algorithms questions

Question

Summarize group psychotherapy outcome research.

Answered: 1 week ago

Question

How does polymorphism promote extensibility?

Answered: 1 week ago

Question

Compare and contrast the break and continue statements.

Answered: 1 week ago