<aside> <img src="/icons/table_red.svg" alt="/icons/table_red.svg" width="40px" /> Table of Contents
</aside>
<aside> 💡
<aside> 💡
Design and Analysis of Algorithms
Introduction to Algorithm Design Techniques
Divide and Conquer
Concept: Divide the problem into smaller subproblems, solve each subproblem recursively, and combine their solutions.
Examples:
Example of Binary Search in Python:
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
arr = [10, 20, 30, 40, 50]
print(binary_search(arr, 30)) # Output: 2