Unit 10 - Recursion Flashcards
Recursive method
One that calls itself
Contains at least one base case which halts the recursion and at least one recursive call -> conditional
Each recursive call contains
its own local variables, including formal parameters
Any recursive solution can be replicated through
use of iterative approach
Infinite recursion
Value is not changing in a way that allow base case to be reached -> CallStackOverFlowException
Parameter values capture
progress of recursive process
Recursion can be used to traverse
String, array, and ArrayList objects
Binary search algorithm
Data must be sorted
Starts in middle of sorted array or ArrayList and eliminates half of the array or ArrayList in each iteration until desired value is found or all elements has been eliminated
Binary search algorithm can be written
both iteratively or recursively
What do we o when lowPosition > highPosition?
Return -1
Value does not lie within list
Merge sort
Recursive sorting algorithm that can be used to sort elements in an array or ArrayList
mergeSort(myList) { mergeSort(left) mergeSort(right) mergeSort(left & right) }
Merge Method
Copy original elements to a temporary array and compares the two array to sort a list
merge(myArray, low, middle, high)