1 Use pseudocode to write recursive algorithms for the follo

1. Use pseudocode to write recursive algorithms for the following: a. Find the largest odd number that divides n, where n > = 1. b. Calculate n.a, where n is a positive integer and a is a real number. c. Calculate where there will be n nested square roots. You may assume that a will be positive. d. Reverse the order of the characters in a nonempty string and return the new string.

Solution

a.

i=n

divide(n,i)

if (i divides n)

then

largest odd number = i

else

i=i-1,

divide(n,i)

___________________________________________

b.

multiply (n,a)

if(n=1)

return a

else

return

a+multiply(n-1,a)

_______________________________________________--

3.

square root(n,a)

if(n=1)

return sqrt(a)

else

return square root(n-1,sqrt(a))

______________________________________________________

for i =1:n

a[i] = i_th character of string

end

reverse(a[n])

if(lenght of n = 0)

return

a[0]

else

return

a[n] concate(reverse(a[n-1]))

 1. Use pseudocode to write recursive algorithms for the following: a. Find the largest odd number that divides n, where n > = 1. b. Calculate n.a, where n i
 1. Use pseudocode to write recursive algorithms for the following: a. Find the largest odd number that divides n, where n > = 1. b. Calculate n.a, where n i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site