● Recursion: helpful for solving a problem with similar occurrences.
● Recursion Programming: These methods call themselves and solve problems using recursion.
● public static int mystery(int n)
{
if (n < 5) {
return n;
} else {
int a = n / 5;
int b = n % 5;
return mystery(a + b);
}
}
What result do you get for the following callings?
mystery (3)
answer = 3
mystery (20)
answer = 2
● Recursive method – method which calls itself
● Recursive methods
o Contain at least one base case
o Halt the recursion
o And contain at least one recursive call
● Recursive call should have own set of:
o Local variables (and formal parameters)
● Recursive solutions
o Replicated through iterations
● You don’t have to know how to write recursive code for the exam.
● Recursion is used to traverse through String, array, and ArrayList objects.
● The binary search algorithm can be composed of either iteratively or recursively written code.
● Data must be in sorted order to utilize the binary search algorithm.
● The binary search algorithm begins at the center of an arranged exhibit or ArrayList and eliminates a portion of the cluster or ArrayList until the desired value is found or all elements of the ArrayList have been checked or eliminated from the process.
● Binary Search can be more productive than sequential/linear search.
● Merge sort is a recursive sorting algorithm that can be utilized to sort components in an Array or ArrayList.
● base case - An approach to stop the recursive calls. This is an arrival without a recursive call.
● call stack - A class characterizes what all objects of that class know (fields) and can do (strategies). You can likewise have information and conduct in the item that speaks to the (class fields and strategies). All objects of a class approach class fields and class techniques, yet these can likewise be gotten to utilizing className.field or className.method().
● recursive method - A method which contains in any event one call to itself inside the method.
● Missing the recursive call. Make certain to search for a call to a similar technique.
● Getting confounded about when a recursive strategy returns and what it returns.
● Expecting you comprehend what the recursion is managing without following every last bit of it.