Recursion Explained With the Mirror Analogy Essay

Exclusively available on Available only on IvyPanda®
This academic paper example has been carefully picked, checked and refined by our editorial team.
You are free to use it for the following purposes:
  • To find inspiration for your paper and overcome writer’s block
  • As a source of information (ensure proper referencing)
  • As a template for you assignment

Recursion breaks one problem into several smaller problems. A significant difference in recursion is that smaller problems have the same type as the original problem. The mirror analogy represents how one object has the same reflections in smaller sizes.

Iterative solutions use a sequential search that utilizes repeated actions or loops, while recursion uses a binary search to divide the problem. Cases that result from dividing the problem into several smaller ones are called the base case. Using recursion is not recommended for problems that have simple solutions.

Recursion divides problems into tasks with immediate clear answers and those requiring additional operations. For example, computing factorial (4) involves determining the factorial (0), which equals 1, and then computing the factorial (3) with the known data. Therefore, computing factorial (4) requires several multiplication tasks with the base case – factorial (0). Determining that n is 0, in this case, allows ensuring that the function will always come back to the base case.

Box trace includes labeling each recursive call, introducing a new box for the local environment, and drawing an arrow from the recursive process initiation statement to the first box.

On the other hand, the recursive void function could be perceived as writing a word in backward order. In this case, completing the task requires introducing two pseudocode functions, writeBackward, and writeBackward2. It is vital to trace the actions associated with the pseudocode carefully. Even though two functions use different values for the letter, they both correctly write the string backward. The box traces and court statements are important for debugging recursive functions.

Recursion can be practical when used with arrays. Passing includes anArray minus the last character through a recursive call that will decrease the number of characters by one. Passing the index of the last character through the recursive call on the subarray anArray [0..last-1] is simplified through a general variation of passing anArray[first..last].

Searching a sorted array through the binarySearch function implies searching an array of integers for a given value or target. Binary search through the integers or dictionary is conducted through the recursive binary search function that includes the array and the target information. Separating the first part of the dictionary is performed by introduction of the midpoint, where mid = (first+last)/2. Lastly, determining which half of the array or dictionary contains the target is done through if (target < anArray [mid]). Base cases for binary search could be both first > last for the case if the target is not in the original array and target == anArray [mid] when the target is in the array. The results of the binarySearch function will include the index of the target value in the array. The result with the negative values can occur if there is no target value in the array.

Recursion is a technique that breaks one problem into several similar problems. Recursion can be used for searching an array or valued and void functions. Base case in recursion is a special case where the solution is immediately known. Recursion can be explained by the analogy of finding the right word in the dictionary. In this case, a sequential search is ineffective as it takes more time to search the whole dictionary. On the other hand, binary search is used to separate the array to eliminate the one that does not have the word or target value. Box trace is used to illustrate the recursive actions.

More related papers Related Essay Examples
Cite This paper
You're welcome to use this sample in your assignment. Be sure to cite it correctly

Reference

IvyPanda. (2022, December 22). Recursion Explained With the Mirror Analogy. https://ivypanda.com/essays/recursion-explained-with-the-mirror-analogy/

Work Cited

"Recursion Explained With the Mirror Analogy." IvyPanda, 22 Dec. 2022, ivypanda.com/essays/recursion-explained-with-the-mirror-analogy/.

References

IvyPanda. (2022) 'Recursion Explained With the Mirror Analogy'. 22 December.

References

IvyPanda. 2022. "Recursion Explained With the Mirror Analogy." December 22, 2022. https://ivypanda.com/essays/recursion-explained-with-the-mirror-analogy/.

1. IvyPanda. "Recursion Explained With the Mirror Analogy." December 22, 2022. https://ivypanda.com/essays/recursion-explained-with-the-mirror-analogy/.


Bibliography


IvyPanda. "Recursion Explained With the Mirror Analogy." December 22, 2022. https://ivypanda.com/essays/recursion-explained-with-the-mirror-analogy/.

If, for any reason, you believe that this content should not be published on our website, please request its removal.
Updated:
1 / 1