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

How does the number of multiplications used by the algorithm in Exercise 26 compare to the number of multiplications used by Algorithm 2 to evaluate ana?

Short Answer

Expert verified

There are multiplications in exercise 2, and O(log n) multiplications in exercise 26.

Step by step solution

01

Describe the algorithm 2

The Algorithm 2 is a Recursive Algorithm for Computing .an

procedure power (a : nonzero real number, n : nonnegative integer)

if n = 0 then return 1

else n = 0 then a. power (a, n - 1)

{outputisan}

02

Compare the number of multiplications used by the algorithm in Exercise 26 and multiplications used by Algorithm 2

As per Algorithm 2, there will be n multiplications by , one for each factor of in the productan .

As per algorithm in Exercise 26, there will be O(log n) multiplications as it computes squares. Apart from squaring, sometimes a multiplication by is needed, which will add at most another O(log n) multiplications. Thus, in totality O (log n) multiplications are used.

Hence, there are multiplications in exercise 2, O(log n) and multiplications in exercise 26.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

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

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