This is a Discrete Math question not a code question Elisa K
This is a Discrete Math question, not a code question.
Elisa Kazan^1 loves to drink cider. During the weekend. Elisa goes to the pub and runs the following recursive algorithm, which takes as input an integer n greaterthanorequalto 0: Algorithm ElisaGOESToThePub(h): if n = 0 then order Fibonachos else if n Is even then ElisaGoesToTHEPuB(n/2); drink;n^2/2 pints of cider: ElisaGoesToT hePub(n/2) else for i = 1 to 4 do EuSaGoesToThePub((n-1)/2): drink (n -1)/2 bottles of eider endfor; drink 1 bottle of cider etidif endif For n greaterthanorequalto 0. let C(n) be the number of bottles of cider that Elisa drinks when running algorithm ELlSAGoEsToTHEPuB(n). Determine the value of C(n).Solution
The equivalent c++ program will be:
#include<iostream>
using namespace std;
int drinks=0;
int pubb(int n)
{
if(n==0)
return 0;
else if(n%2==0)
{
pubb(n/2);
drinks=n*n/2;
pubb(n/2);
}
else
{
for(int i=0;i<4;i++)
{
pubb((n-1)/2);
drinks=(n-1)/2;
}
drinks=1;
}
return drinks;
}
int main()
{
int dr=pubb(10);
cout<<dr;
return 0;
}
so for n=10. c(n)=1
