Question

1. Analyze the running time of the following algorithm and write it using ( notation. You must show detailed calculation/deri

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

The 2 for loops in the code segment are not independent and so the product rule cannot be used to compute the time complexity.

Since both i loop and j loop are dependent upon each other, let's analyze how both the loops work using the following table :

Value of i n n/2 n/4 1
j loop runs for log n times log ( n / 2 ) times log ( n / 4 ) times log ( 1 ) times

Let the running time of the algorithm be represented as T(n).

So, the time complexity is calculated as :

T(n) = Sum of the total number of times j loop runs

= log n +  log ( n / 2 ) +  log ( n / 4 ) + .................... log ( 1 )

= log ( n * n /2 * n / 4 .......... 1 ) + 0 [ logarithmic property ]

<= log ( n^n)

<= n log n

So,

T(n) = Θ(n log n)

Hence, the running time of the given algorithm is Θ(n log n).

Add a comment
Know the answer?
Add Answer to:
1. Analyze the running time of the following algorithm and write it using ( notation. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT