0% found this document useful (0 votes)
8 views3 pages

Part II

The document outlines advanced recursion techniques including binary search, merge sort, quick sort, and dynamic programming methods such as memoization and tabulation. It details the processes for each algorithm, highlighting their initialization, recursive steps, and complexities. Key concepts include dividing arrays, comparing elements, and caching results to optimize performance.

Uploaded by

Agan, Mica Ella
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Part II

The document outlines advanced recursion techniques including binary search, merge sort, quick sort, and dynamic programming methods such as memoization and tabulation. It details the processes for each algorithm, highlighting their initialization, recursive steps, and complexities. Key concepts include dividing arrays, comparing elements, and caching results to optimize performance.

Uploaded by

Agan, Mica Ella
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Part II: Advanced Recursion Techniques

Chapter 4: Divide and Conquer

BINARY SEARCH

1. Initialization:

 Start with two pointers:

o low at the beginning of the array.

o high at the end of the array.

2. Compute the middle index:

3. Comparison:
 Compare the value at mid with the target
 If the middle element equals the target, return mid.
 If the middle element is greater than the target, narrow the search to the left half by
setting high = mid - 1.
 If the middle element is less than the target, narrow the search to the right half by
setting low = mid + 1.

4. Repeat:
 Continue this process until low > high or the target is found.

MERGE SHORT

1. Divide:
 If the list has more than one element, divide it into two halves.
2. Conquer (Recursion):
 Recursively apply merge sort to each half until the list is reduced to individual
elements (base case).
3. Merge:
 Merge the sorted halves back together into a single sorted list.

QUICK SORT

 Time Complexity
 Best/Average Case: O(nlog⁡n)O(n \log n)O(nlogn
 Worst Case: O(n2)O(n^2)O(n2) (occurs when pivot is poorly chosen, e.g.,
smallest or largest element)
 Space Complexity: O(log⁡n)O(\log n)O(logn) (for recursion stack)
 In-Place Sorting: Uses no extra space for sorting, making it memory-efficient.

Chapter 5: Backtracking

1. Choose a Pivot: Select an element from the array (commonly the first, last, or middle
element).
2. Partition: Rearrange the array such that:
 All elements less than the pivot go to its left.
 All elements greater than the pivot go to its right.
3. Recursion: Apply the same process to the left and right subarrays (excluding the pivot).
4. Base Case: Stop when the subarray has 0 or 1 element (already sorted).

Chapter 6: Dynamic Programming

1. Memoization
 Starts solving from the main problem, recursively breaking it into subproblems.
 Caches results of subproblems as they are computed.
 Reuses cached results for repeated subproblems.
2. Tabulation
 Builds the solution for smaller subproblems first and combines them iteratively.
 Avoids function call overhead and recursion stack usage.

You might also like