Decrease-and-Conquer by a Factor and Variable-Size Decrease
Unlike decrease-by-a-constant, decrease-by-a-constant-factor reduces the problem instance size by a multiplicative factor (usually b=2, though sometimes b=3). Variable-size-decrease algorithms reduce instance size by an amount that varies dynamically from step to step.
1. Decrease-by-a-Constant-Factor
Binary Search (Factor of 2)
Given a sorted array A[0..n−1] and target key K, compare K with the middle element A[m]. If unequal, discard half the array and continue searching in the remaining sub-array of size ⌊n/2⌋.
BinarySearch(A[0..n-1], K): l = 0 r = n - 1 while l <= r do: m = floor((l + r) / 2) if K == A[m] return m else if K < A[m] r = m - 1 else l = m + 1 return -1
Watch the search window collapse. Each comparison discards half of what is left,
which is why only a handful of steps are needed for a 13-element array:
Binary searchStep with the slider or ← →
1BinarySearch(A[0..n-1], K):2 l = 03 r = n - 14 while l <= r do:5 m = floor((l + r) / 2)6 if K == A[m] return m7 else if K < A[m] r = m - 18 else l = m + 19 return -1
0123456789101112
3142731394255707481859398
Searching a sorted array of 13 values for K = 70.
1 / 8
Recurrence for Worst-Case Comparisons:
Cworst(n)=Cworst(⌊n/2⌋)+1for n>1,Cworst(1)=1
Solution:
Cworst(n)=⌊log2n⌋+1∈Θ(logn)
Fake-Coin Problem (Factor of 3)
Given n identical-looking coins with 1 lighter fake coin and a balance scale:
Divide n coins into three piles: two equal piles of size ⌊n/3⌋ and one pile with the remaining coins.
Weigh the two equal piles:
If they balance: The fake coin is in the third pile.
If they don’t balance: The fake coin is in the lighter pile.
Recurse on the pile containing the fake coin.
Recurrence:
W(n)=W(⌈n/3⌉)+1⟹W(n)=⌈log3n⌉∈Θ(logn)
Ternary decrease requires strictly fewer weighings than binary halving because log3n<log2n.
Russian Peasant Multiplication
Multiplies two positive integers n and m using only halving, doubling, and addition:
n×m={(n/2)×(2m)((n−1)/2)×(2m)+mif n is evenif n is odd
Example: 50×65
n (halve and truncate)
m (double)
Accumulate if n is odd
50
65
-
25
130
+130
12
260
-
6
520
-
3
1040
+1040
1
2080
+2080
Total=130+1040+2080=3250(50×65=3250!)
Number of steps: ⌊log2n⌋+1=Θ(logn).
2. Variable-Size-Decrease Algorithms
Interpolation Search
For an array sorted with uniformly distributed numerical keys, instead of probing the midpoint, estimate the key’s position using linear interpolation:
index=l+⌊A[r]−A[l]K−A[l](r−l)⌋
Average-Case Complexity: Θ(loglogn) comparisons.
Worst-Case Complexity: Θ(n) (if keys grow exponentially or are clustered).
Euclid’s Algorithm for Greatest Common Divisor (GCD)
Computes gcd(m,n) for non-negative integers where m≥n:
gcd(m,n)=gcd(n,mmodn)with gcd(m,0)=m
The decrease in argument size varies per step, but mmodn<m/2 guaranteed every two steps.
Lamé’s Theorem: The number of division steps is at most 5×(number of digits of n).
Time Complexity: Θ(logn).
Summary of Decrease-and-Conquer Variants
Type
Classic Example
Typical Recurrence
Efficiency Class
Decrease-by-1
Insertion Sort, Johnson-Trotter
T(n)=T(n−1)+Θ(n)
Θ(n2) or Θ(n!)
Decrease-by-factor-2
Binary Search
T(n)=T(n/2)+1
Θ(logn)
Decrease-by-factor-3
Fake-Coin Problem
T(n)=T(n/3)+1
Θ(log3n)
Variable-Size
Euclid’s GCD
T(m,n)=T(n,mmodn)
Θ(logn)
Exercises
Exercise 1
Compute gcd(31415,14142) step-by-step using Euclid’s algorithm and count the division steps.
Show solution ↓Hide solution ↑
Solution
gcd(31415,14142)⟹31415mod14142=3131
gcd(14142,3131)⟹14142mod3131=1618
gcd(3131,1618)⟹3131mod1618=1513
gcd(1618,1513)⟹1618mod1513=105
gcd(1513,105)⟹1513mod105=43
gcd(105,43)⟹105mod43=19
gcd(43,19)⟹43mod19=5
gcd(19,5)⟹19mod5=4
gcd(5,4)⟹5mod4=1
gcd(4,1)⟹4mod1=0⟹gcd=1.
The numbers are coprime (gcd=1). It took 10 division operations.
Exercise 2
Given 27 coins with 1 lighter fake coin, how many weighings on a balance scale are guaranteed to find the fake coin using the 3-pile method?
Show solution ↓Hide solution ↑
Solution
Using the ternary decrease-by-factor-3 approach:
Weighing 1: Divide 27 into three piles of 9 (9,9,9). Compare two piles → isolate the fake coin in a pile of 9.
Weighing 2: Divide 9 into three piles of 3 (3,3,3). Compare two piles → isolate the fake coin in a pile of 3.
Weighing 3: Divide 3 into three single coins (1,1,1). Compare two coins → locate the exact fake coin.