AP Computer Science A - Unit 10 Recursion Practice Test

[Pages:7]AP Computer Science A - Unit 10 Recursion Practice Test Question 1 Which of the following cannot be converted in a recursion function?

A. Random function generation B. Greatest common divisor(GCD) C. Binary search D. Factorial program Question 2 What will be the output of the following recursive algorithm below?

A. 9 B. 11 C. 10 D. 12 Question 3 What is the definition of recursion? A. Recursion is a program that translates a source program written in some high-level

programming language into machine code. B. Recursion is a programming technique you can use to allow a method to have numerous

fields in its argument. C. Recursion is a programming language model organized around objects rather than

"actions" and data rather than logic D. Recursion is programming technique you can use in which a method calls itself to solve a

problem.

Question 4

Based on the code above, what is the value of the following function call: foo(5,9); A. 18 B. 24 C. 32 D. 36

Question 5 Which of the following is the best definition of a recursive method?

A. A method that iterates itself exactly 5 times. B. A method that will never iterate infinitely. C. A method that invokes itself by name within the method. D. A method that cannot be called more than once. Question 6

What does the code print? A. Error, infinite loop B. 9 7 5 3 1 -1 C. 11 9 7 5 3 1 -1 D. 1 ? 1

Question 7 Which of the following sorting algorithms use recursion?

A. Selection sort B. Insertion sort

C. Mergesort D. None of the above Question 8 The number of recursive calls is limited to the ____ of the stack. A. Time B. Size C. Quality D. Ability Question 9 What will be the output of the following recursive algorithm below?

A. 17 B. 23 C. -17 D. -23 Question 10 The program may run out of memory in a _____________. A. Non-recursive function call B. Condition when too many variables are declared C. Recursive function call D. None of the above Question 11 What does this factorial code snippet return after calling run()?

A. 2 will be printed out B. 6 will be printed out C. 3 will be printed out D. 4 will be printed out Question 12

What is the value returned by foo(3)? A. 12 B. 8 C. 6 D. 3

Question 13 What is the returned value of recmethod(5)?

A. 68 B. 70 C. 75 D. 82

Question 14 How is merge sort accomplished?

A. The original list is continuously broken up into sublists until each sublist is containts 1 element, then the sublists are combined together.

B. If there are an even number of elements, the list is broken into two groups, are sorted, then merged back together. If there are odd numbered elements, the list is broken into three groups.

C. Each element in the list is compared to all the other elements and inserted where it fits. D. The orginal list is broken into sublists of 4, then are combined together.

Question 15 The Fibonacci sequence is a classic example of: _________

A. Iteration B. Primitive C. Selection D. Recursion

Question 16 Which of the following problems can be solved using recursion?

A. Finding Nth number of the Fibonacci sequence B. Finding the length of a string C. Finding the factorial of a number D. All of the above

Question 17 What would happen if the base case if not defined in the recursive method?

A. Program Crashes B. Stack Overflow C. Stack Underflow D. None of the above

Question 18 Consider the following code:

What is the output for the code above? A. 248832 B. 1728 C. 144 D. 104

Answer Key 1. A 2. B 3. D 4. B 5. C 6. A 7. C 8. B 9. A 10. C 11. D 12. B 13. C 14. A 15. D 16. D 17. B 18.A

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download