Part 1 The function \'vbrf\' (for v ery b ad r ecursive f unction) is defined as
ID: 638726 • Letter: P
Question
Part 1
The function 'vbrf' (for very bad recursive function) is defined as follows:
Your job for this problem is to implement the function vbrf as a method in Java. Then write a program that uses this method to compute the function for various values of the argument and time how long it takes to compute. Also, include in this program a part that computes the function for the arguments from 1 to 12 and displays the argument and the results. Once you have the program working and can examine the results, report the following in a comment near the beginning of your program file:
To determine how long it takes to compute vbrf, use code something like the following:
Be aware, the time it takes to compute vbrf(n+1) is almost twice the time it takes to compute vbrf(n). Start with small values of n and work your way up.
Part 2
We will be studying one aspect of permutations in Assignment #5. We will make use of a function that is defined recursively. Your job for this part of the assignment is to implement this function and print the first few values. Implement the method as a static method that takes a long for an argument and returns a long. The method itself should do no printing.
We'll call the function h. It is defined by these conditions:
To check your work, here are the first few values of h:
Your program should print the first 10 values or so of the function. Your programshould not be interactive!
n h(n) 0 1 1 0 2 1 3 2 4 9 5 44 6 265 7 1854 8 14833 9 133496 10 1334961 11 14684570 12 176214841 13 2290792932 14 32071101049 15 481066515734Explanation / Answer
public class h{
public static void main(String[] args) {
int b = 6;
int c = h(b);
System.out.println("answer= " + c);
}
/** returns the minimum of two numbers */
public static int h(int n) {
int val;
val=(n-1)*(h(n-1)+h(n-2));
return val;
}
}