Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The next two questions refer to the following recursive method public static int

ID: 3688346 • Letter: T

Question

The next two questions refer to the following recursive method public static int compute (int x, int y) if (xy return x return compute(x , y-1); 6.) What is returned by the call compute(, 5)? A. 2 B. 3 D. 5 E. No value is returned because an infinite recursion occurs. 7.) Which of the following calls leads to an infinite recursion? i. compute (2, 5) ii. compute (2, 8) iii. compute (8, 2) on B. iii only C. i andii only D. i andi only E. and ii 8.) Consider the following method that returns true if and only if a chain of nodes contains duplicates. Assume hasDups is initially called by passing it the first node in the chain (assume no header node): private boolean hasDups ( Listnode L if (L== null) return false; return contains (L.getNext (, L.getData)) II hasDups (L.getNext) // assume contains) returns true iff obj is in L public boolean contains( Listnode L, E obj // assume this method takes time o(N), where N is the size of List L Which one of the following pairs of recurrence equations correctly characterizes the hasDups method? A. T(0)-1, T(N) = 1 + T(N/2) B. T(0) = 1, T(N)-1 + T(N-1) C. T(0) 1, T(N) N T(N-1) D. T(1) = 1, T(N)-N + T(N-1) E. T(1) 1, T(N)-1TN+1)

Explanation / Answer

6. ans is B. 3 is output

7. ans is c.i and iii only

compute(2,5) and compute (8,2) gives output as infinite loop while compute(2,8) gives output of 5

11. ans is A

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote