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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!