# Completing the Square — Fun with Maths

## Solve quadratic equations of the form ax² + bx + c 😎

**Completing the Square**, one of the important and easiest methods to solve a quadratic equation of the form ** ax² + bx + c. **It is an application of the famous algebraic formula

**Please check out my previous **article**

*(a + b)².***to understand the visual explanation for ***(a + b)²

***

Why quadratic equations are that difficult to solve?🤔 Because ** x **appears twice in the equation. Is that worse? Let us consider an example equation

*and rearrange it to make*

**x2 + 2x + 1= 0***appear once.*

**x**How hard we try, we end up having 2 ** x**’s in our equation.

**Completing the Square **💁

Here comes our friend. Let us rearrange our equation a bit ** x² + 2x = -1** and visualize in the form of shapes

We can set aside ** -1 **(constant) and concentrate only on the LHS. The LHS consists of

- A square with area
(*x²***length =**)*x* - A rectangle with area
(*2x***length =**,*x***breadth =**)*2*

The dashed line in the rectangle indicates that we can divide the rectangle into 2 halves. Now have

- A Square with area
(*x²***length =**)*x* - 2 Rectangles with area
(*x***length =**,*x***breadth =**) each.*1*

Now, we rearrange our shapes to form a single square

Along with our Square (** x²**) and two Rectangles (

**), we also get an unwanted square (**

*1x + 1x = 2x***). So our equation becomes**

*1² = 1*** x2 + 2x +1 = (x + 1)² **according to

*a² + 2ab + b² = (a + b)²*To remove the unwanted square with area ** 1**, we subract the above equation with

**on either side**

*1**x² + 2x = (x + 1)² - 1*

By substitute the above value in our actual equation ** x² + 2x = -1** we get

** (x + 1)² - 1 = -1**, by sending

**to the RHS and taking square root we come up with**

*-1*** x = -1 **which solves the equation

**x² + 2x = -1**This method can be very useful in Competitive Programming. You can solve **Arranging Coins **problem in LeetCode using this method.
**Arranging Coins - LeetCode**
*You have a total of n coins that you want to form in a staircase shape, where every -th row must have exactly k coins…*leetcode.com

## Thank you 🤘

To know more about me, visit ganeshkumarm.me