

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Quiz; Class: Full Course Title: Program Design and Development; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Spring 2007;
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


public void mystery(String s, int digit) { if(digit <= 1) System.out.println(digit); else { s = s + "<"; mystery(s, digit - 2); System.out.println(s + digit); } }
____mystery(0) ____mystery(1) ____mystery(2) ____mystery(3) ____mystery(4) public int mystery(int n) { if (n <= 0) return 1; else return 3 + mystery(n - 1); }
________ mysteryTwo("T") ________ mysteryTwo("ab") ________ mysteryTwo("123") public String mysteryTwo(String s) { if (s.length() == 0) return ""; else return mysteryTwo(s.substring(1, s.length())) + "/" + s.charAt(0); }
public static void stars(int n) { if (n > 1) stars(n-1); for (int i = 0; i < n; i++) System.out.print("*"); System.out.println(); }
goingUp(1, 5); // 1 2 3 4 5 goingUp(2, 7); // 2 3 4 5 6 7 goingUp(3, 3); // 3
^ ( , % ) 0 ( , )^0 GCDn m n ifn GCDm n m if^ n
Implement the power function recursively ^ x (x,n-1)ifx 1 power(x, n)^1 ifn^0 power
Implement the factorial function recursively as fact ^ x ( 1 )ifx 1 fact(n) 1 ifn^1 factn
Implement Fibonacci recursively as f ^ fib(n-1) fib(n-2)ifx 1 fib(n)^1 ifn^2
Write recursive method addReciprocals that takes an integer as a parameter and returns the sum of the first n reciprocals. addReciprocals(n) returns (1.0 + 1.0/2.0 + 1.0/3.0 + 1.0/4.0 + ... + 1.0/n).
Write recursive method sum that returns the sum of all the int elements in a filled array referenced by y. Do not use a loop. You must have a recursive call somewhere in your answer.
Write recursive method getMax that returns the largest integer in a filled array of int referenced by x. Do not use a loop. You may use a helper method.
Write recursive method printArray that prints all array elements in a filled array of ints referenced by x. Do not use a loop. You may use a helper method.
Write recursive method printArrayInReverse that prints all array elements in a filled array of ints referenced by x in their reverse order. Do not change the array. Do not use a loop. You may use a helper method.
Implement recursive method sequentialSearch. Use recursion. Do NOT use a loop. Use this array of int values. int[] a = { 22 45, 8, 9, 12, 2, 5, 6, 16, 18 };
Implement recursive method binarySearch. Use recursion. Do NOT use a loop. Use this sorted array of int values. int[] a = { 2, 5, 6, 8, 9, 12, 16, 18, 22, 45 };
Write recursive method reverse that reverses the array elements in a filled array of ints referenced by x. Do not use a loop. You may use a helper method.
Write recursive method isPalindrime that returns true if the string argument is a palindrome. Do not use a loop.
Write recursive method printInt to print an integer with commas in the correct places.
Write recursive method printIntInNewBase to print an integer in any base from 2 through hexadecimal (base 16) without using an array.