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

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

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.

One App. One Place for Learning.

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

Get started for free

Most popular questions from this chapter

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free