An algorithm is a procedure for solving a given problem step by step. It is a set of steps or a formula used in problem-solving. There are two major algorithms used in mathematics for evaluating a given algebraic expression. They are BEDMAS / PEDMAS and FOIL. The BEDMAS is used for evaluating an algebraic expression and FOIL is used to multiply binomials. After reading this article you will be able to:
1. Know what is an algorithm.
2. Understand BEDMAS algorithm.
3. Evaluate a given algebraic expression.
4. Understand FOIL algorithm.
5. Multiply two binomials.

Definition

An algorithm is a set of steps or a procedure given to solve a problem. An algorithm has an input and an output and a process which will change the input to the output. In mathematics, to evaluate some expressions we need an algorithm which gives the right procedure to evaluate.

For example, if we have to evaluate 3(x + 2) we will follow the given steps:

1. Multiply 3 by x

2. Multiply 3 by 2

3. Add the results of step 2 and 3

BEDMAS

The BEDMAS rule is the algorithm for evaluating an algebraic expression with respect to a certain order of operations.  The BEDMAS stands for bracket, exponent, division, multiplication, addition and subtraction. The BEDMAS can also be written as PEDMAS where P stands for parenthesis. The steps of BEDMAS algorithm can be explained as given:

1. Take the algebraic expression.

2. Solve the expression within the brackets first.

3. Solve the exponents.

4. Solve the division.

5. Solve the multiplication part.

6. Add the relevant parts.

7. Subtract the relevant parts.
Example: Let us see an expression $\frac{(2\ -\ 4)\ \times\ 8}{2\ +\ 7}$.

Solution: The algorithm to solve the expression is

1. Solve the bracket: (2 - 4) = -2. The expression becomes $\frac{-2\ \times\ 8} {2\ +\ 7}$

2. Solve the division part: ($\frac{8}{2}$) = 4. The expression becomes -2 $\times$ 4 + 7

3. Solve the multiplication part: (-2 $\times$ 4) = -8. The expression becomes -8 + 7

4. Solve the subtraction: (7 - 8) = -1

5. As no more operators are left, the resultant is -1.

FOIL

The FOIL algorithm is used for multiplication of binomials. It stands for First Outside Inside Last. A binomial is a polynomial having only two terms. While multiplying two binomials, the FOIL algorithm follows the given steps:

1. Multiply the first terms of both the binomials

2. Multiply the first term of the first binomial and second term of the other one, that is, multiply the outside terms.

3. Multiply the second term of the first binomial and first term of the other one, that is, multiply the inside terms.

4. Multiply the last terms of both the binomials.

Example: Multiply (x + 2)(y - 1) and explain the steps.

Solution: These binomials can be multiplied using the given steps:

1. First: x $\times$ y = xy

2. Outside: x $\times$ -1 = -x

3. Inside: 2 $\times$ y = 2y

4. Last: 2 $\times$ -1 = -2

5. Adding all the terms : xy - x + 2y - 2

Examples

Let us see some examples and understand:
Example 1: Simplify the expression $\frac{(2\ -\ 7)}{5}$ $\times$ 2 + (8 - 2) $\times$ 3 and explain the steps.

Solution: The rules of BEDMAS will be used to simplify the given expression.

1. Brackets: (2 - 7) = -5 and (8 - 2) = 6

The expression will be $\frac{5}{5}$ $\times$ 2 + 6 $\times$ 3

2. Exponent: No exponent term is there.

3. Division: $\frac{5}{5}$ = 1

The expression will be 1 $\times$ 2 + 6 $\times$ 3

4. Multiplication: (1 $\times$ 2) = 2 and (6 $\times$ 3) = 18

The expression will be 2 + 18

5. Addition: 2 + 18 = 20

6. As no more operations are there, the expression simplifies to 20.
Example 2: Multiply the binomials (y - 11) and ($log_{x}$+ z).

Solution: Using the FOIL algorithm we can multiply these binomials.

First: Multiplying the first terms, y$\times$ $log_{x}$ = y$log_{x}$

Outside: Multiply the outer terms, y$\times$z = yz

Inside: Multiply the inner terms, -11$\times$ $log_{x}$ = -11 $log_{x}$

Last: Multiply the last terms, -11  $\times$ z = -11z

Adding all the terms we get, y$log_{x}$ + yz - 11 $log_{x}$ -11z.