Services
Discover
Homeschooling
Ask a Question
Log in
Sign up
Filters
Done
Question type:
Essay
Multiple Choice
Short Answer
True False
Matching
Topic
Computing
Study Set
Java Software Solutions
Quiz 12: Recursion
Path 4
Access For Free
Share
All types
Filters
Study Flashcards
Practice Exam
Learn
Question 21
Multiple Choice
Recall the Towers of Hanoi recursive solution for this problem. If there are six disks to move from one Tower to another, how many disk movements would it take to solve the problem using the recursive solution?
Question 22
Multiple Choice
Example Code Ch 12-2 Given the following recursive factorial method: public int factorial(int x) { if (x > 1) return x * factorial (x - 1) ; else return 1; } -Refer to Example Code Ch 12-2: What is returned if factorial(3) is called?
Question 23
Multiple Choice
The difference between direct and indirect recursion is
Question 24
Multiple Choice
Example Code Ch 12-3 Given the two recursive methods shown below, foo and bar. Assume int[] a = {6, 2, 4, 6, 2, 1, 6, 2, 5} public int foo(int[] a, int b, int j) { if (j < a.length) if (a[j] != b) return foo (a, b, j+1) ; else return foo (a, b, j+1) + 1; else return 0; } public int bar(int[] a, int j) { if (j < a.length) return a[j] + bar(a, j+1) ; else return 0; } -Refer to Example Code 12-3: What is the result of calling bar(a, 8) ?
Question 25
Multiple Choice
Recall the Towers of Hanoi recursive solution for this problem. The solution to the Towers of Hanoi has a(n) __________ complexity.
Question 26
Multiple Choice
Example Code Ch 12-1 Given the following recursive method: public int question1_2(int x, int y) { if (x == y) return 0; else return question1_2(x-1, y) + 1; } -Refer to Example Code Ch 12-1: If the method is called as question1_2(8, 3) , what is returned?
Question 27
Multiple Choice
Example Code Ch 12-1 Given the following recursive method: public int question1_2(int x, int y) { if (x == y) return 0; else return question1_2(x-1, y) + 1; } -Refer to Example Code Ch 12-1: Calling this method will result in infinite recursion if which of the following conditions is initially true?
Question 28
Multiple Choice
Example Code Ch 12-2 Given the following recursive factorial method: public int factorial(int x) { if (x > 1) return x * factorial (x - 1) ; else return 1; } -Refer to Example Code Ch 12-2: How many times is the factorial method called with factorial(5) ? Include the original method call in your counting.
Question 29
Multiple Choice
The Koch fractal of order 1 is
Question 30
Multiple Choice
Example Code Ch 12-2 Given the following recursive factorial method: public int factorial(int x) { if (x > 1) return x * factorial (x - 1) ; else return 1; } -Refer to Example Code Ch 12-2: What is returned if factorial(0) is called?
Question 31
Multiple Choice
Recall the Towers of Hanoi recursive solution for this problem. If there are two disks to move from one Tower to another, how many disk movements would it take to solve the problem using the recursive solution?
Question 32
Multiple Choice
Define the magnitude of a number as the location of the decimal point from the left of the number (that is, if a number has 4 digits followed by the decimal point, it will have a magnitude of 4) . 100 would then have a magnitude of 3 and 55,555.555 would have a magnitude of 5. A partial recursive method is given below to compute a positive int parameter's magnitude. Which answer below is needed to complete the method? public int magnitude(double x) { If (x < 1) return 0; Else return _______; }
Question 33
Multiple Choice
Example Code Ch 12-3 Given the two recursive methods shown below, foo and bar. Assume int[] a = {6, 2, 4, 6, 2, 1, 6, 2, 5} public int foo(int[] a, int b, int j) { if (j < a.length) if (a[j] != b) return foo (a, b, j+1) ; else return foo (a, b, j+1) + 1; else return 0; } public int bar(int[] a, int j) { if (j < a.length) return a[j] + bar(a, j+1) ; else return 0; } -Refer to Example Code 12-3: What is the result of calling foo(a, 2, 9) ?
Question 34
Multiple Choice
What can be said about the difference or similarity, if any, between an infinite loop and an infinite recursion?
Question 35
Multiple Choice
Example Code Ch 12-3 Given the two recursive methods shown below, foo and bar. Assume int[] a = {6, 2, 4, 6, 2, 1, 6, 2, 5} public int foo(int[] a, int b, int j) { if (j < a.length) if (a[j] != b) return foo (a, b, j+1) ; else return foo (a, b, j+1) + 1; else return 0; } public int bar(int[] a, int j) { if (j < a.length) return a[j] + bar(a, j+1) ; else return 0; } -Refer to Example Code 12-3: What is the result of calling bar(a, 0) ?
Question 36
Multiple Choice
Example Code Ch 12-4 The following recursive method recognizes whether a String parameter consists of a specific pattern and returns true if the String has that pattern, false otherwise. public boolean patternRecognizer(String a) { if (a == null) return false; else if (a.length() == 1 || (a.length() == 2 && a.charAt(0) == a.charAt(1) ) ) return true; else if ) return false; else if ) return patternRecognizer) ; else return false; } -Refer to Example Code Ch 12-4: Which String of the following would result in patternRecognizer returing true?
Question 37
Multiple Choice
Each time the order of a Koch fractal increases by one, the number of straight line segments
Question 38
Multiple Choice
Example Code Ch 12-3 Given the two recursive methods shown below, foo and bar. Assume int[] a = {6, 2, 4, 6, 2, 1, 6, 2, 5} public int foo(int[] a, int b, int j) { if (j < a.length) if (a[j] != b) return foo (a, b, j+1) ; else return foo (a, b, j+1) + 1; else return 0; } public int bar(int[] a, int j) { if (j < a.length) return a[j] + bar(a, j+1) ; else return 0; } -Refer to Example Code 12-3: What is the result of calling foo(a, 2, 0) ?
Question 39
Multiple Choice
Example Code Ch 12-2 Given the following recursive factorial method: public int factorial(int x) { if (x > 1) return x * factorial (x - 1) ; else return 1; } -Refer to Example Code Ch 12-2: What condition defines the base case for this method?