Question
Implement the following recursive methods. Note these methods are static, and work on what is passed to them as parameters. import java.util.Queue; public class RecursiveFun
Implement the following recursive methods. Note these methods are static, and work on what is passed to them as parameters.
import java.util.Queue;
public class RecursiveFun { /* @Description: this method computes the cobination (n choose m), which * can be computed using the following formula * (n choose m) = (n-1 choose m) + (n-1 choose m-1) * where (n choose 0) == (n choose n) == 1 * @param: int n, numerator * @param: int m, denominator * @return: long result of n choose m */ static long combination(int n, int m) { // WRITE code here return -1; }
/* @Description: Compute n^p (preferably in O(log(p)) time) * @param: int n, the base * @param: int p, the power * @return: n^p (in log time) */ static long pow(int n, int p) { // WRITE YOUR CODE HERE return -1; }
/* @Description: Recursively reverse the list * @param: List to be reversed. */ static void reverseQueue(Queue queue) { /* WRITE YOUR CODE HERE * You may only use the following methods of the Queue interfacce * add(e) : enqueues element e on to the queue * remove() : dequeues and returns the element at the front of the queue * isEmpty(): retiurns true if and only if the queue has no elements * HINT: the solution is only 4 - 5 lines long. * HINT 2: We covered this algorithm in class. */ } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started