Chapter 16

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the number of times the method calls itself?

depth of recursion

What is it called when a recursive methods directly call themselves? What is it called when a method calls a second method that then calls the original method?

direct recursion; indirect recursion

Some mathematical problems are designed to be solved recursively. What is one well known example? Hint: after the second number, each number in the series is the sum of the two previous numbers

fibonacci numbers calculation is popular; it can be defined as f0 = 0 f1=1 fN - fN-1 + FN-1 for N >= 2

What sorting algorithm is used when you recursively divided the list in half until each sub-list is just one element? Then merge the two lists such that they are in order. Recursion first and then do the work of merging.

mergesort

Recursive solutions repetitively: -allocate memory for parameters and local variables -store the address of where control returns after the method terminates These actions are called ______ and take place with each method call.

overhead; this overhead does not occur with a loop

What sorting algorithm is used when you sort a list based on a partition element, also called a pivot, and then recursively sorts the sub-lists? Does the work first or partitioning, then call recursive method.

quicksort 1. choose pivot (arbitrarily choose first/last element) 2. partition elements about pivot 3. left of pivot are elements less than pivot; right of pivot are elements greater than pivot

Some repetitive problems are more easily solved with ______ than with iteration. - iterative algorithms might execute faster; however - a recursive algorithm might be _______ ________

recursion; designed faster

We have been calling other methods from a method. It's also possible for a method to call itself. A method that calls itself is a:

recursive method

Recursion can be a powerful tool for solving _______ problems. Recursion is never absolutely required to solve a problem. Any problem that can be solved recursively can also be solved ______, with a ______. In many cases, recursive algorithms are ______ __________ than iterative algorithms.

repetitive problems; iteratively, with a loop; less efficient

What search algorithm can be implemented recursively?

the binary search algorithm can be implemented recursively;

How does recursion work? - a _____ ______ is established. - if it cannot be solved now: - the method reduces it to a smaller problem(______ ______) and calls itself to solve the ______ problem. - by reducing the problem with each _____ call, the _____ ______ will eventually be reached and the recursion will stop.

Base case is established. If matched, the method solves it and returns; the method reduces it to a smaller problem(recursive case) and calls itself to solve the smaller problem; recursive call; the base case will eventually be reached


Set pelajaran terkait

Conduit LvL 1 L1 How to Work with Fractions

View Set

Pricing Decisions and Market Success: Priceline and Uber

View Set