Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Give a big-O estimate for the number of operations, where an operation is anaddition or a multiplication,used in this segment of an algorithm (ignoring comparisons used to test the conditions in the while loop).

i:=1t:=0whileint:=t+ii:=2i

Short Answer

Expert verified

The complexity of the given algorithm is O(log n).

Step by step solution

Achieve better grades quicker with Premium

  • Unlimited AI interaction
  • Study offline
  • Say goodbye to ads
  • Export flashcards

Over 22 million students worldwide already upgrade their learning with Vaia!

01

Given algorithm:

The given algorithm is

i:=1t:=0whileint:=t+ii:=2i

02

Finding the number of operations in the algorithm:

Consider n = 1 for n = i

Then,

i=2i=2×1=2

If n = 2

Then,

i=2i=2×2=4

If n = 3

Then,

i=2i=2×3=6

Therefore, the value of i is double for every repetition of while loop.

Thus,

i=2n

The value if i is increased at the rate of power of digit 2 since the number of operations is log (2n) .

Therefore, the complexity of the algorithm is O (log n) .

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Study anywhere. Anytime. Across all devices.

Sign-up for free