Question

please provide these functions.

int d_recursive(int n)
{

}

int d_iterative(int n)
{

}

For the function din the accompanying p1.cpp file) (a) (10 points) a recursive implementation and (b) (10 points) an iterative implementation ) = (n-1)ld(n-1) + d(n-2)], n > 3, where d(1) 0 and d(2-1, provide (in

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Recursion and iteration have been implemented:

Kindly find the code below.

The calls are same as in the question

If you need any help feel free to approach.

Kindly see the code below. If you have any queries. Kindly comment.

********************************************************************************************************************

#include <iostream>

using namespace std;


int d_recursive(int n){
    if(n==1)
        return 0;
    else if(n==2)
        return 1;
    else if(n>=3)
        return (n-1)*(d_recursive(n-1)+d_recursive(n-2));
}

int d_iterative(int n)
{
int d[n+1];
int i;
d[0] = 0;
d[1] = 0;
d[2] = 1;
for (i = 3; i <= n; i++)
{
      d[i] = (i-1)*(d[i-1] + d[i-2]);
}
return d[n];
}

int main()
{
    int recursive= d_recursive(10);
    cout << "Recursive call for d(10) " << recursive << endl;
    int iterative= d_iterative(10);
    cout << "Iterative call for d(10) " << iterative << endl;
    return 0;
}

*********************************************************************************************************************

Sample output:

Recursive call for d(10) 1334961
Iterative call for d(10) 1334961

Process returned 0 (0x0)   execution time : 0.009 s
Press any key to continue.


****************************************************************************
I hope this helps you.
If you find my answer helpful,
Kindly rate the answer.
All the best :)

Add a comment
Know the answer?
Add Answer to:
please provide these functions. int d_recursive(int n) { } int d_iterative(int n) { } For the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT