Given a semicircle of radius r, we have to find the largest rectangle that can be inscribed in the semicircle, with base lying on the diameter.
Input : r = 4 Output : 16 Input : r = 5 Output :25
Let r be the radius of the semicircle, x one half of the base of the rectangle, and y the height of the rectangle. We want to maximize the area, A = 2xy.
So from the diagram we have,
y = √(r^2 – x^2)
So, A = 2*x*(√(r^2 – x^2)), or dA/dx = 2*√(r^2 – x^2) -2*x^2/√(r^2 – x^2)
Setting this derivative equal to 0 and solving for x,
dA/dx = 0
or, 2*√(r^2 – x^2) – 2*x^2/√(r^2 – x^2) = 0
2r^2 – 4x^2 = 0
x = r/√2
This is the maximum of the area as,
dA/dx > 0 when x > r/√2
and, dA/dx < 0 when x > r/√2
Since y =√(r^2 – x^2) we then have
y = r/√2
Thus, the base of the rectangle has length = r/√2 and its height has length √2*r/2.
So, Area, A=r^2
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live