


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



}^ Return^ a.compareTo(b);
4). We define two linked lists to be equal if (1) each list is the same length, and (2) the items at position each list are equal (as equals() for the LinkedList determined by the item’s class described below. Your method must run in O(n) time. equals method). Implement the method boolean x in class LinkedList
7). Compute f (5, 3) using the definition of f below: f(5,3) = 8 int { f(int if (x x,== int1) returny) 1; if if return (y(y ==== f(x x)1)- (^) 1,returnreturn y) + 1;x;f(x-1, y-1); } 8). Describe what f(x, x-1) does in general when x > 1. (MTH 225 people should attempt to prove your answer by induction.) f(x, x-1) = x. As a base case, consider x = 2. f(2, 1) = 2. Now, assume inductive that f(x, x def inductive hypothesis tells us that f(xinition f(x, x-1) = f(x-1, x-1) + f(x - 1, x-1, x - -2). The definition of f tells us that f(x 2) = x - 1. Thus, f(x, x - 1) = x – 1 + 1 = x as desired.- - 1) =x for all x >= 2. By1, x-1) = 1. Our 9). Write a recursive implementation of int indexOf(char c, int place) int indexOf(char c). { if (place == if (c == this.charAt(place)) { return place; } this.length() - 1) { return - 1; } }^ return^ indexOf(c,^ place + 1); 10). Write a method subsequence of array. (The maximum subsequence is the subset [i, j]of the array for which int maxSubsequence(int[] array) that returns the value of the maximum
!