What is the algorithm paradigm or approach in this function?
int algo(int n, int k) {
if (k == 1 || k == 0) return k;
if (n == 1) return k;
int min = Integer.MAX_VALUE;
int x, res;
for (x = 1; x <= k; x++) {
res = Math.max(algo(n-1, x-1), algo(n, k-x));
if (res < min) min = res;
}
return min + 1;
}
a. Dynamic programming
b. Divide and conquer
c. Greedy
d. Recursive
a. Dynamic programming
This function implements the dynamic programming problem of the "egg dropping puzzle," which is to determine the minimum number of times to drop n-eggs from a k-floor building. For example, with 2-eggs and 10-floors the number of times is 4.
You might also like to view...
A runnable thread enters the ________ state (sometimes called the dead state) when it successfully completes its task or otherwise terminates (perhaps due to an error).
a. extinct b. defunct c. terminated d. aborted
List the total number of employees in each department for those departments with more than 10 employees. Create an appropriate heading for the columns of the results table.
What will be an ideal response?
When using a bubble sort to sort a 10-element array, on the fourth pass through the array list you detect that no swap has occurred. This indicates ____.
A. the elements in the array were badly out of order B. all elements in the array are already in the correct order C. you must make one more pass through the array D. you must make a total of 10 passes through the array
?Anasideelement is contained in the middle of eacharticleelement.
Answer the following statement true (T) or false (F)