Every positive fraction can be represented as sum of unique unit fractions. A fraction is unit fraction if numerator is 1 and denominator is a positive integer, for example 1/3 is a unit fraction. Such a representation is called Egyptian Fraction as it was used by ancient Egyptians.
Following are few examples:
Egyptian Fraction Representation of 2/3 is 1/2 + 1/6 Egyptian Fraction Representation of 6/14 is 1/3 + 1/11 + 1/231 Egyptian Fraction Representation of 12/13 is 1/2 + 1/3 + 1/12 + 1/156
We can generate Egyptian Fractions using Greedy Algorithm. For a given number of the form ‘nr/dr’ where dr > nr, first find the greatest possible unit fraction, then recur for the remaining part. For example, consider 6/14, we first find ceiling of 14/6, i.e., 3. So the first unit fraction becomes 1/3, then recur for (6/14 – 1/3) i.e., 4/42.
Below is implementation of above idea.
Egyptian Fraction Representation of 6/14 is 1/3 + 1/11 + 1/231
The Greedy algorithm works because a fraction is always reduced to a form where denominator is greater than numerator and numerator doesn’t divide denominator. For such reduced forms, the highlighted recursive call is made for reduced numerator. So the recursive calls keep on reducing the numerator till it reaches 1.
This article is contributed by Shubham. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Boruvka's algorithm | Greedy Algo-9
- Graph Coloring | Set 2 (Greedy Algorithm)
- K Centers Problem | Set 1 (Greedy Approximate Algorithm)
- Set Cover Problem | Set 1 (Greedy Approximate Algorithm)
- Greedy Algorithm to find Minimum number of Coins
- Dijkstra's shortest path algorithm | Greedy Algo-7
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2
- Dijkstra’s Algorithm for Adjacency List Representation | Greedy Algo-8
- Minimum number of subsequences required to convert one string to another using Greedy Algorithm
- Fraction module in Python
- First occurrence of a digit in a given fraction
- Convert Binary fraction to Decimal
- Find Recurring Sequence in a Fraction