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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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 shortest path algorithm | Greedy Algo-7
- Graph Coloring | Set 2 (Greedy Algorithm)
- K Centers Problem | Set 1 (Greedy Approximate Algorithm)
- Set Cover Problem | Set 1 (Greedy Approximate Algorithm)
- Boruvka's algorithm | Greedy Algo-9
- Greedy Algorithm to find Minimum number of Coins
- Minimum number of subsequences required to convert one string to another using Greedy Algorithm
- Dijkstra’s Algorithm for Adjacency List Representation | Greedy Algo-8
- Convert decimal fraction to binary number
- Fraction module in Python
- Largest proper fraction with sum of numerator and denominator equal to a given number
- as_integer_ratio() in Python for reduced fraction of a given rational
- First occurrence of a digit in a given fraction
- Maximum rational number (or fraction) from an array
- Represent the fraction of two numbers in the string format
- Expressing a fraction as a natural number under modulo 'm'
- Print first N terms of series (0.25, 0.5, 0.75, ...) in fraction representation