Embed presentation
Downloaded 12 times





![Recursion (cont’d) Example 2 Quicksort Sort an N-element array Basic algorithm Selects a partition element x Assume that the final position of x is array[ i ] Moves elements less than x into array[0]…array[ i 1] Moves elements greater than x into array[ i +1]…array[ N 1] Applies quicksort recursively to sort these two subarrays](https://image.slidesharecdn.com/al2edchapter16-110223130749-phpapp02/85/Al2ed-chapter16-6-320.jpg)


The document discusses recursion and compares it to iteration. It provides two examples of recursion - calculating the factorial of a number and quicksorting an array. Recursion involves a procedure calling itself, directly or indirectly. This results in activation records being stored on the stack. While recursion can make some problems more concise and natural to express, it also has potential disadvantages like inefficiency and increased memory usage compared to iteration.





![Recursion (cont’d) Example 2 Quicksort Sort an N-element array Basic algorithm Selects a partition element x Assume that the final position of x is array[ i ] Moves elements less than x into array[0]…array[ i 1] Moves elements greater than x into array[ i +1]…array[ N 1] Applies quicksort recursively to sort these two subarrays](https://image.slidesharecdn.com/al2edchapter16-110223130749-phpapp02/85/Al2ed-chapter16-6-320.jpg)
