Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert the following recursive algorithm into a iterative one. Power(y: number; z: non-negative integer) 1. if z==0 then return 1 2. if z is odd

Convert the following recursive algorithm into a iterative one.

Power(y: number; z: non-negative integer)

1. if z==0 then return 1

2. if z is odd then

3. return (Power(y*y, z/2)*y) comment: z/2 is integer division; note the parentheses

else

4. return Power(y*y, z/2) comment: z/2 is integer division

Some parts of this iterative algorithm is given below. Fill in the blanks:

Power-iterative(y: number; z: non-negative integer)

1. answer=1

2. while z > 0

3. if z is odd then answer=__________

4. z = ________

5. y = _________

6. return answer

Step by Step Solution

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

Step: 3

blur-text-image

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

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

Which months of this year 5 Mondays ?

Answered: 1 week ago

Question

Define Leap year?

Answered: 1 week ago