In Java code Write and test two recursive methods to calcula

In Java code

Write and test two recursive methods to calculate ab for positive integers a and b.

Method 1: if b = 0 then return 1 else return a * (ab-1).

Method 2: if b = 0 then return 1 else if b is even return (ab/2)2 else return  a * (ab-1).

Time both methods. Which is faster?

Solution

In my opinion time complexiety of method 1st is somehw less than time complexiety of method 2 .so, Method 1 is faster

In Java code Write and test two recursive methods to calculate ab for positive integers a and b. Method 1: if b = 0 then return 1 else return a * (ab-1). Method

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site