MATHEMATICAL ALGORITHM: MONOVARIANT
05 th March, 2019.
Mathematical algorithm can be expressed as a set of steps within a finite amount of time designed to accomplish some calculation, data processing and automated reasoning tasks. Algorithms can give us a deeper insight into mathematics. For instance, the well-known Euclidean algorithm essentially provides the foundation of number theory. Moreover, algorithms are effective tools in several services that impact our day-to-day lives. For example, the growing complexity of algorithms nowadays contribute to more advanced processors on smartphones or computers or the searching algorithms have improved the Google search applications which is very useful in optimizing traffic flow, etc.
Two of many extremely significant concepts in algorithms are invariants and mono-variants. A mono-variant is a quantity that changes monotonically, either non-increasingly or non-decreasingly, and an invariant is a quantity that remains unchanged. Let see the next example and how mono-variants play crucial role in constructing the algorithm.
In each regular hexagon’s vertices, we write randomly a nonnegative integer such that the sum of these numbers is 2019. We can perform to make moves of the following rule: pick one vertex and replace the number at this vertex by the absolute difference of two numbers at the neighboring vertices. Can we make a sequence of moves forcing all number in the hexagon’s vertices to 0.
Let a, b, c, d, e, f denote the number in 6 vertices in the order.
- sum of three number in vertices 1,3,5 is odd, and sum of numbers in vertices 2,4,6 is even.
- sum of three number in vertices 1,3,5 is even, and sum of numbers in vertices 2,4,6 is odd.
- Exactly one of a, c, e is odd. We assume that a is odd. Then we make the succesive moves at vertices 2, 6, 4, 1, 6. We end up with a situation that only one of 6 number is odd, which is number in vertices 2.
- Three number a, c, e are odd. We will make a sequence of moves at vertices 2, 4, 6, 3, 5. After that, we only get A is odd number.
Now, our numbers include only one odd number assuming a. Note that the sum now is smaller than 2019. At this point, we realize that we can force all the number to 0 by reducing the sum or the maximum of them. It seem to be a lot of cases to consider when you want to choose the mono-variant is the sum of all numbers, but not for the case of choosing the mono-variant as the maximum. Note that the maximum is never increase.
Here is the second sub-algorithm: from a hexagon with exactly one odd number, make the hexagon such as the sum of all number in hexagon’s vertices Is odd and the maximum of these number is strictly smaller than the maximum of the initial hexagon or make all number in the hexagon’s vertices equal to 0.
If the maximum of hexagon now is even, then at least one of b, c, d, e, f. Then if we make moves at vertices 2, 3, 4, 5, 6 in the order, the maximum will be decrease, and still keep the properties of odd sum of all 6 numbers.
If the maximum is odd, then a is the maximum, we have two case:
- if c=e =0 , we perform moves at vertices 2, 6, 4, 1, 2, 6, which makes all numbers equal to 0.
- if at least one of c and e is not 0, suppose c is greater than 0, we perform a sequence of moves at vertices 2, 6, 1, 6. This moves decrease the maximum and still keep the odd sum property.
To sum up, the main algorithm can be defined as following
- If the hexagon has not exactly one odd number.
- Do the first sub algorithm;
- End;
- Do the second sub algorithm; End.
It can be easy to see that the problem can be generalised by replacing 2019 by any odd numbers. How about other factors: can we replace the odd sum with even sum? Here is the counter example.
1. Principles of Algorithmic Problem Solving, Johan Sannemo, October 24, 2018.
2. Algorithmic, Anany Levitin and Maria Levitin, 2011.