MUST BE ANSWERED BY USING C++
Please explain the code as well.
Question 1
Write a recursive function defined by the following recursive formula:
foo (Y, X) =
Y if X = 1
0 if X = Y
(foo ( Y-1, X-1) + 3* foo ( Y-1, X)) if Y > X > 1
Write a driver to print out the value for foo (5, 4) and foo (7, 5).
In addition, print out the total number of recursive function calls in each case.
#include <iostream>
using namespace std;
int count;
int foo(int X, int Y){
count++;
// Checking if X is 1
if(X==1)
return Y;
// Checking if both X and Y are equal
else if(X==Y)
return 0;
// Checking if both X and Y are greater than 1
else if(Y>1 && X>1)
return foo ( Y-1, X-1) + 3* foo ( Y-1, X);
// if all the above conditions not apply
else
return 0;
}
int main()
{
// testing function foo
count = 0;
cout<<"foo(5,4): "<<foo(5,4)<<endl;
cout<<"The total number of recursive function calls: "<<count<<endl;
count = 0;
cout<<"foo(7,5): "<<foo(7,5)<<endl;
cout<<"The total number of recursive function calls: "<<count<<endl;
return 0;
}

foo(5,4): 947 The total number of recursive function calls: 19 foo(7,5): 20586 The total number of recursive function calls: 73
MUST BE ANSWERED BY USING C++ Please explain the code as well. Question 1 Write a...
Q5 (25pts) Consider the code: int foo(int N){ if (N <= 3) return 2; int res1 = 3*foo(N-4); int res2 = foo(N-2); return res1-res2; } a) (6 points) Write the recurrence formula for the time complexity of this function (including the base cases) for N>=0. You do NOT need to solve it. b) (5 points) Draw the tree that shows the function calls performed in order to compute foo(8) (the root will be foo(8) and it will have a child...
General Recursion C++ How many possible bridge hands are there ? This question is a specific case of the general question, “How many combination of X items can I make out of Y items ?” In the case of the bridge hand, X is 4 and Y is 8. The solution is given by the following formula: Combinations(Y, X) = Y if X = 1 1 if X = Y Combinations(Y-1, X-1) + Combinations(Y-1, X) if Y > X >...
MUST USE C++ PLEASE READ THE QUESTION CAREFULLY ADD COMMENTS AND EXPLAIN THE CODES PLEASE. Given the following skeleton of an unsorted list class that uses an unsorted linked list: template < class ItemType > struct NodeType { ItemType item; NodeType* next; }; template < class ItemType > class UList { public: UList(); // default constrctor UList(const UList &x); // we implement copy constructor with deep copy UList& operator = (UList &x); // equal sign...
PLEASE HELP!!! C PROGRAMMING CODE!!!
Please solve these functions using the prototypes provided. At
the end please include a main function that tests the functions
that will go into a separate driver file.
Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...
Using C programming language
Question 1 a) through m)
Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....
Write the code in java programming language To get some practice with recursion. You can do all this in one driver program. Write a recursive method to compute the result of the Fibonacci sequence: Fibonacci(N) = Fibonacci(N -1) + Fibonacci(N-2) N == 0 is 0 N == 1 is 1 Testing: Display the result for Fibonacci(N) and the number of function calls for N = 2, 5 and 10.
PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to: -define a recursive procedure/function and call it. -use syscall operations to display integers and strings on the console window -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9 if n <= 5 =...
You have written all of the code for this problem in ASSEMBLY. Please remember that when answering the question. 1.write a single GDB command to print out the arguments of the function • foo(int arg1, int arg2, int arg3, int arg4, int arg5); 2. write a single GDB command to print out the local variables of the function in reverse of their appearance • foo(int arg1, int arg2, int arg3, int arg4, int arg5){ • int a, b, c, d,...
Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...
JAVA turn this psuedo code into java code. USING NO LOOPS! ALL LOOPS MUST BE TURNED INTO RECURSIVE CALLS. English: 1. Prompt for and read a number between 1 and 5. Repeat this step until the input is 1..5. 2. Repeat the following multiple times according to the number read in step 1. a. Read in a list of integers ending with a 0. The 0 marks the end of the input and is not considered part of the list...