UNIT III - Algorithm Design Techniques
UNIT III - Algorithm Design Techniques
Merge Sort
Divide and Conquer – Introduction
• Key Steps: Divide → Sort → Merge
• Problem-solving technique • Time complexity: O(n log n)
• Break – Solve – Combine • Stable sort
• Examples: Merge Sort, Quick Sort, • Diagram of merging
etc.
Quick Sort
Finding Maximum and Minimum • Uses partitioning
• Average case: O(n log n), Worst case:
• Description of method O(n²)
• Time complexity • In-place sorting
• Example illustration or pseudo • Pivot selection strategies
code
Divide and Conquer – Introduction
It is a problem-solving strategy that involves breaking a problem into
smaller sub-problems, solving each sub-problem independently, and combining
their solutions to solve the original problem.
Comparison Count:
•Linear scan: 2(n-1) comparisons.
•Recursively sort the left half and the •O(n) (because of the extra
right half. array used for merging)
Basic Steps:
• Choose a pivot element from the array.
• Partition the array:
• All elements smaller than the pivot go to the left.
• All elements greater than the pivot go to the right.
• Recursively apply Quick Sort to the left and right parts.
QUICKSORT(arr, low, high):
if low < high:
pivotIndex = PARTITION(arr, low, high)
QUICKSORT(arr, low, pivotIndex - 1)
QUICKSORT(arr, pivotIndex + 1, high)
Start with the main problem and Start solving smaller sub-problems
break it into sub-problems. first.