Package topics.divideconquer
package topics.divideconquer
Divide-and-Conquer algorithms — break, solve, and combine.
Divide and Conquer solves problems by recursively splitting them into smaller sub-problems of the same type, solving each sub-problem independently, and then merging the partial results into a final answer.
Recurrence and the Master Theorem
The running time of a divide-and-conquer algorithm typically satisfies:
T(n) = a · T(n/b) + f(n)
where a is the number of sub-problems, b is the size reduction
factor, and f(n) is the cost of dividing / combining.
Distinction from Dynamic Programming
- Divide & Conquer — sub-problems are independent; solved once.
- Dynamic Programming — sub-problems overlap; results are cached.
Classes in This Package
BinarySearch— O(log n) search in sorted arraysFactorial— recursive factorialFibonacci— recursive FibonacciGCG— greatest common divisor (Euclidean)MajoritarianElement— majority element by D&CMaxSum— maximum subarray sumMedian— median of two sorted arraysMergesort— O(n log n) stable sortMode— mode by D&CSequentialSearch— linear search baselineVectorSum— parallel vector sum
-
ClassesClassDescriptionBinary Search implementation for finding an element in a sorted array.DIVIDE AND CONQUER PROBLEM: CALCULATE THE FACTORIAL OF A NUMBERFibonacci Number Calculation using Divide and Conquer and Iterative Approaches.GREATEST COMMON DIVISORS: Calculate the GCG of two positive integers//DIVIDE AND CONQUER PROBLEM: IS THERE A MAJORITARIAN ELEMENT IN n ELEMENTS?DIVIDE AND CONQUER PROBLEM: MAXIMUM SUMMATION OF ALL THE SUBSEQUENCES OF n ELEMENTS//DIVIDE AND CONQUER PROBLEM: THE MEDIAN OF n ELEMENTSMergesort algorithm using divide-and-conquer.//DIVIDE AND CONQUER PROBLEM: MODE OF n ELEMENTSDIVIDE AND CONQUER PROBLEM: CALCULATE THE POSITION OF AN ELEMENT x IN A VECTOR (SORTED OR UNSORTED) OF n DIFFERENT ELEMENTSDIVIDE AND CONQUER PROBLEM: CALCULATE THE SUM OF n ELEMENTS IN A VECTOR