If resizable array X has m elements:
If linked list X has m elements:
If binary tree X has m elements:
If hash table X has m elements:
P(0) = P(1) = P(2) = 1
P(n) = P(n-2) + P(n-3) for n > 2
Write a recursive method that returns the nth Padovan number.
A(0, n) = n + 1
A(m, 0) = A(m-1, 1) if m > 0
A(m, n) = A(m-1, A(m, n-1)) if m > 0 and n > 0
Write a recursive method that computes Ackermann(m, n) for any positive integers m and n.
class Node {
E element;
Node next;
}
Write a recursive method add(E e) in the Node class
that adds the given element to the end of the linked list. Note that this method
is a member of the Node class; you do not need to deal with an empty linked list
in this problem.
class TernaryTreeNode {
E data;
TernaryTreeNode left;
TernaryTreeNode middle;
TernaryTreeNode right;
}
Write a recursive method in the TernaryTreeNode class that prints
the data on the rightmost branch (root to leaf) of the tree,
with the root first and the leaf last.
1. Traverse X to find the smallest element in X. Put that smallest element into X[0].
2. Repeat step 1 to find the 2nd smallest (putting it into X[1]).
3. Repeat step 1 to find the 3rd smallest (putting it into X[2]).
4. Etc until all N elements are done.
Be able to explain your answers to the following:
1. If start >= end, stop (the array is sorted in the range from start to end). Otherwise:
2. Recursively MergeSort the left half of X (from start to the middle).
Recursively MergeSort the right half of X (from middle to end).
3. Merge the two sorted halves [as described in class].
Be able to explain your answers to the following:
1. If start >= end, stop (the array is sorted in the range from start to end). Otherwise:
2. Let Pivot = X[start].
For k from start + 1 to end:
-- If X[k] <= Pivot, copy X[k] into the next spot of temporary array called LessThanPivot.
-- If X[k] > Pivot, copy X[k] into the next spot of temporary array called MoreThanPivot.
3. Recursively QuickSort LessThanPivot.
Recursively QuickSort MoreThanPivot.
4. Copy the sorted LessThanPivot into X,
then put Pivot into the next position in X,
then copy the sorted MoreThanPivot into the remaining positions in X.
Be able to explain your answers to the following:
Total: 130 points (but the exam will cover only 100 of the above 130 points, i.e., some topics will not show up on the exam)