Java: Chapter 16 Quiz

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Look at the following pseudocode algorithm: algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What value is returned for Test14(16)? A) 32 B) 8 C) 24 D) 16

32

The part of a problem that is solved with recursion is known as the: A) terminal case B) recursive case C) final case D) absolute case

B) recursive case

Look at the following method: public static int Test2(int x, int y) { if ( x < y ) { return -5; } else { return (Test2(x - y, y + 5) + 6); } } What is the base case for the method? A) x < y B) -5 C) +6 D) Test2(x - y, y + 5) + 6

A) x < y

Recursive algorithms are usually less efficient than: A) None of these B) iterative algorithms C) quantum algorithms D) pseudocode algorithms

B) iterative algorithms

Like a loop, a recursive method must have: A) a counter B) some way to control the number of times it repeats itself C) a predetermined number of times it will execute before terminating D) a return statement

B) some way to control the number of times it repeats itself

Look at the following pseudocode algorithm: Algorithm gcd(x, y) if (x < y) gcd (y, x) else if (y = 0) return x else return gcd(y, x mod y) end gcd What is returned from gcd(60, 24)? A) 24 B) 66 C) 12 D) 60

C) 12

Look at the following method: public static int test2 (int x, int y) { if ( x < y ) return -5; } else { return (test2(x - y, y + 5) + 6); } } What is the recursive case for the method? A) -5 B) x! = y C) x < y D) x >= y

D) x >= y

A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem. True/False

False

In Java, it is not possible for a method to call itself. True/False

False

Unlike a loop, a recursive method does not require code to stop it from repeating. True/False

False

Look at the following pseudocode algorithm: algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What is the base case for the algorithm? A) x < 8 B) 3 * Test14(x - 8) + 8 C) 2 * x D) x >= 8

A) x < 8

Look at the following method: public static int Test2(int x, int y) { if ( x < y ) { return -5; } else { return (Test2(x - y, y + 5) + 6); } } What is returned for test2(18,5)? A) 1 B) -5 C) 7 D) 6

C) 7

This type of method is a method that calls itself. A) Reoccurring B) Circular C) Looping D) Recursive

D) Recursive

Like ________, a recursive method must have some way to control the number of times it repeats. A) an event B) any method C) a class constructor D) a loop

D) a loop

Look at the following method: public static int Test2(int x, int y) { if ( x < y ) { return -5; } else { return (Test2(x - y, y + 5) + 6); } } What is returned for test2(10, 20)? A) 1 B) 6 C) 10 D) -5

D) -5

The Towers of Hanoi is: A) demonstrates the power of recursion B) often used in computer science textbooks C) a mathematical game D) All of these

D) All of these

To solve a program recursively, you need to identify at least one case in which the problem can be solved without recursion - this is known as the: A) terminal case B) final case C) recursive case D) base case

D) base case

Recursion can be a powerful tool for solving: A) object-oriented problems B) basic problems C) binary problems D) repetitive problems

D) repetitive problems

If the base case in a recursive method is never reached: A) the method will call itself only once B) the result will always be off by one C) the method will never call itself D) the method will call itself indefinitely

D) the method will call itself indefinitely

Look at the following pseudocode algorithm: algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What is the recursive case for the algorithm? A) x < 8 B) x != 8 C) 2 * x D) x >= 8

D) x >= 8

Look at the following method: public static int Test2(int x, int y) { if ( x < y ) { return -5; } else { return (Test2(x - y, y + 5) + 6); } } What is the depth of test2(18,5)? A) 2 B) 3 C) 0 D) 1

A) 2

Which of the following problems can be programmed recursively? A) All of these B) Quicksort C) Towers of Hanoi D) Binary search

A) All of these

The actions that the JVM must perform any time a method is called are known as: A) Overhead B) Method calls C) Housekeeping D) Stack depth

A) Overhead

How many times will the following method call itself if the value 10 is passed as the argument? public static void message (int n) { if (n < 0) { System.out.println("Print this line.\"); } } A) 0 B) An infinite number of times C) 10 D) 9

A) 0

Look at the following pseudocode algorithm: algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What value is returned for Test14(7)? A) 14 B) 0 C) 7 D) -5

A) 14

Look at the following pseudocode algorithm: Algorithm Test3(int a, int b) if ( a < b ) return 5 else if (a == b) return -5 else return (a + Test3(a - 1, b) end Test3 What is the recursive case for the algorithm? A) a > b B) a == b C) a < b D) None of these

A) a > b

A recursive method is: A) a method that calls itself B) a method that contains a static field C) a method that accepts no arguments D) a method that has a loop

A) a method that calls itself

The depth of recursion is: A) the number of times that a method calls itself B) The order in which the method appears on the stack C) the value that will terminate the recursive calls D) the value returned from the last recursive call

A) the number of times that a method calls itself

Look at the following pseudocode algorithm: Algorithm Test3(int a, int b) if (a < b) return 5 else if ( a == b ) return -5; else return (a + Test3(a - 1, b) end Test3 What is the base case for the algorithm? A) neither a < b nor a == b B) a < b C) Both a < b and a == b D) a == b

C) Both a < b and a == b

A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem. True/False

True

Any problem that can be solved recursively can also be solved iteratively. True/False

True

If method A calls method B, which in turn calls method A, it is called indirect recursion. True/False

True

Indirect recursion occurs when a method calls another method that in turn calls the first method. True/False

True

Recursive algorithms are usually less efficient than iterative algorithms. True/False

True

Look at the following pseudocode algorithm: algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What is the depth of Test14(7)? A) 7 B) 0 C) 6 D) 1

B) 0

Look at the following pseudocode algorithm: algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What is the depth of Test14(16)? A) 3 B) 2 C) 1 D) 0

B) 2

How many times will the following method call itself if the value 10 is passed as the argument? public static void message (int n) { if (n > 0) { System.out.println("Print this line.\"); message (n + 1); } } A) 0 B) An infinite number of times C) 10 D) 9

B) An infinite number of times

This term is used for methods that directly call themselves. A) Native recursion B) Direct recursion C) Simple recursion D) Absolute recursion

B) Direct recursion

Indirect recursion occurs when: A) a method calls itself B) a method calls itself from another method C) a recursive method has no code to stop it from repeating D) a loop is used to solve a recursive problem

B) a method calls itself from another method

The number of times that a method calls itself is known as the: A) length of recursion B) height of recursion C) depth of recursion D) width of recursion

C) depth of recursion

Usually, a problem is reduced by making the value of one or more parameters ________ with each recursive call. A) larger B) negative C) smaller D) equal

C) smaller

Look at the following pseudocode algorithm: Algorithm gcd(x, y) if (x < y) gcd (y, x) else if (y = 0) return x else return gcd(y, x mod y) end gcd What is the base case for the algorithm gcd? A) x < y B) y > x C) y == 0 D) x == 0

C) y == 0


Ensembles d'études connexes

AP Psych_Ch 19_Testing & Intelligence

View Set

Cell Molec 230 Comp Quiz 3 Mastering Questions

View Set

PSYC 210 Chapter 2 Smartbook Questions

View Set

U.S. History I.S.75 Practice Regent 2022

View Set