Semester
Subject
Year
Tribhuwan University
2079
Bachelor Level / Third Year / Fifth Semester / Science
(Design and Analysis of Algorithms)
Full Marks: 60
Pass Marks: 24
Time: 3 Hours
Candidates are required to give their answers in their own words as for as practicable.
The figures in the margin indicate full marks.
Long Answers Questions
Divide and Conquer is an algorithm design paradigm that solves a problem by recursively breaking it into smaller sub-problems, solving each sub-problem independently, and then combining their solutions to get the final answer.
The strategy works in three steps:
General Recurrence:
Where = number of sub-problems, = size of each sub-problem, = cost of dividing and combining.
Examples: Merge Sort, Quick Sort, Binary Search, Strassen's Matrix Multiplication.
The Worst-Case Linear Time Selection algorithm (also called SELECT or Median of Medians) finds the i$-th smallest element in an unsorted array in $O(n) time in the worst case.
Unlike Randomized Select (which has worst case), this algorithm guarantees linear time by choosing a good pivot.
Steps of the Algorithm:
Step A: Divide the elements into groups of 5 (last group may have fewer elements). This gives groups.
Step B: Find the median of each group by sorting each group (takes constant time since group size is 5).
Step C: Recursively find the median of these medians using SELECT. Call this pivot .
Step D: Partition the array around pivot . Let be at position after partitioning.
Step E:
Key Insight: The median of medians guarantees that at least 30% of elements are smaller and at least 30% of elements are larger than the pivot. So the worst-case recursive call is on at most 70% of elements (i.e., $7n/10$).
Counting elements guaranteed to be eliminated:
Recurrence Relation:
Where:
Solving the Recurrence:
Assume for some constant :
This holds when , i.e., .
Therefore:
The Divide and Conquer strategy is a powerful paradigm for designing efficient algorithms. The Median of Medians algorithm cleverly applies this strategy to achieve guaranteed worst-case time for selection, improving over Quick Select's worst case by ensuring a balanced partition through careful pivot selection.
Short Answers Questions
