can you provide the solution?

Dark Mode

vishal burnwal
asked
in Algorithms
Aug 31, 2018

198 views
0 votes

Consider the code below, How many times the function Anand(2,3,3) is executed______? |
||

The answer is given as 65536.

Please provide solution for above question ?

Shaik here is the solution,

**Solution :**

→ Evaluating Anand(m,n,3) for small values of n suggests that Anand(m,n,3)=mn.

→ Anand(m,0,3)=1= m^{0}.

→ Assuming that Anand(m,n-1,3)=m^{n-1}

→ Anand(m,n,3) = Anand(m,Anand(m,n-1,3),2) = Anand(m,m^{n-1},2) = m*m^{n-1} =m^{n}

→ Anand(2,0,3) = 2.

Anand(2,1,3) = Anand(2,Anand(2,0,3),2) = Anand(2,2,2) = 2^{2} = 4.

Anand(2,2,3) = Anand(2,Anand(2,1,3),2) = Anand(2,4,2) = 2^{4} = 16.

Anand(2,3,3) = Anand(2,Anand(2,2,3),2) = Anand(2,16,2) = 2^{16} = 65536.

I didn't understood the solution.

0