Simplification of running times of algorithm

16 Views Asked by At

Noob question but can someone explain the method used to simplify the equation on the first line to the equation on the second line? I'm rusty, is it polynomial factoring?

Sum of instruction times

TIA

1

There are 1 best solutions below

0
On

When you multiply out the first line, you get

$$c_1n+c_2n-c_2+c_4n-c_4+c_5n-c_5+c_8n-c_8\,.$$

You can then collect the multiples of $n$ and factor out the $n$ to get

$$c_1n+c_2n+c_4n+c_5n+c_8n=\color{red}{(c_1+c_2+c_4+c_5+c_8)n}\,.$$

Finally, you can combine the constants and factor out the minus sign to get

$$-c_2-c_4-c_5-c_8=\color{red}{-(c_2+c_4+c_5+c_8)},.$$

Now just add the two (red) final forms to get

$$(c_1+c_2+c_4+c_5+c_8)n-(c_2+c_4+c_5+c_8)\,.$$