The concept of auxiliary algorithm Part 1
Imagine that you are in a summer camp of work and rest, you were appointed on duty in the dining room and you want to consider the order of their actions. Clearly, some person on duty will have during the day to execute several times. For example:
- To clear the table dishes
- Wipe the tables
- Arranging the chairs
- To leave.
This sequence of actions have to perform three times duty: after Breakfast, lunch and dinner. We call the corresponding algorithm "Duties", and when writing the routine will replace these four actions in one command:
To execute the algorithm "Duties"
- Then the routine duty in the dining room will take the form:
- Into the cafeteria at 7: 00.
- To lay the table for Breakfast.
- To wait until after Breakfast.
To execute the algorithm "Duties".
- Come to the dining room at 13.00.
- To lay the table for dinner.
- To wait until after lunch.
To execute the algorithm "Duties".
- Come to the dining room at 18.00.
- To lay the table for dinner.
- To wait until after dinner.
To execute the algorithm "Duties".
It is easy to understand that the use of the "Perform algorithm" allowed almost two times to reduce the length of our instructions.
Similarly, the act often, when the construction of the algorithm there is a need for repeated use of the same set of actions.
This set of actions is isolated as a standalone algorithm and give the algorithm name. From that moment he becomes a subsidiary algorithm, there is the possibility of its use in other algorithms. A set of commands that comprise the auxiliary algorithm is replaced with a single command.
Accounting for subsidiary by the algorithms, we would "teach" by the new action. Exactly the same occurs and in-school training. Initially, students are taught addition and subtraction, and then using these skills, are trained to the operations of multiplication and division, which, in turn, are used further for solving more complex tasks.
Since we are talking about school, remember material VIII class - the solution of quadratic equations. If you studied computer science, you could write the solution to the quadratic equation ах2 + bx + c = Q (assuming a≠0) by the following algorithm:
- Find the discriminant d = b2 - 4ac.
- If d<0, then:
- Let "Equation has no roots".
- Otherwise:
- To find the square root of d and denote it by the letter R.
- Find x1 by the formula.
- To find x2 in the formula.
- The end of branching.
We give the algorithm of solving quadratic equations the name "RECUR" (though you can name this algorithm in a different, more harmonious).
In the X class, you are, of course, faced with square equations while solving various tasks. But now the solution of quadratic equations was for you is as elementary as a multiplication of numbers (it is possible that we wishful thinking). We can say that "RECUR" has become your auxiliary algorithm.