First, the drawer algorithm
Drawer algorithm, aka pigeon nest principle, it is the German mathematician Dirichlet first explicitly put forward to prove some problems in number theory, therefore, also known as the Dirichlet principle. It is an important principle in combinatorial mathematics.
The specific algorithm is about:
First drawer algorithm: If n+1 objects are placed into N boxes, then at least one box contains two or more objects.
Proof (Disprove): If each drawer can only be placed in one object, then the total number of objects is n, rather than the N+k (k≥1), it is impossible.
The second drawer algorithm: put more than Mn (M times n) of objects into N drawers, then at least one drawer has not less than m+1 objects.
Proof (Counter-method): If each drawer at most into M objects, then n drawers at most put into MN objects, and the problem set is not possible.
Third Infinity set drawer algorithm: Put an infinite number of objects into N drawers, at least one drawer has an infinite object.
Principle 1, 2, 3 are the first drawer of the principle of the expression. Algorithm 3, for the infinite Itemsets, the learning of the real variable function is very clear, it is meaningless to say an algorithm alone.
Second, Quorom algorithm
Quorom algorithm is commonly used in distributed systems to ensure data redundancy and eventual consistency of the voting algorithm, the main mathematical ideas derived from the pigeon nest principle.
In distributed storage systems with redundant data, redundant data Objects store multiple copies between different machines. But at the same time multiple copies of a data object can only be used for reading or for writing.
The algorithm can guarantee that multiple copies of the same data object will not be read and written by more than two Access objects.
The algorithm is derived from [Gifford, 1979]. Each copy of the data in the distributed system is given a vote. Each operation must be given a minimum number of reads (vR) or a minimum number of writes (vw) to read or write. If a system has a v -ticket (meaning a data object has a v redundant copy), then this minimum read-write ticket must satisfy:
- Vr + Vw > V
- Vw > V/2
The first rule guarantees that a data is not read and written at the same time. When a write request comes in, it must be licensed for a Vw redundant copy. The remaining number is v-vW is not enough VR, so there is no more reading request coming in. Similarly, when a read request has been licensed for a Vr redundant copy, the write request is not licensed.
The second rule guarantees the serialization of data modification. A redundant copy of a piece of data cannot be modified by two write requests at the same time.
III. Benefits of the algorithm
In distributed system, redundant data is the means of guaranteeing reliability, so the consistency maintenance of redundant data is very important. In general, a write operation must update all redundant data to be called a successful end. For example, a data on 5 devices have redundancy, because do not know the reading data will fall on which device, then a write operation, must be 5 devices are updated to complete, write operations to return.
For systems with frequent write operations, the bottleneck of this operation is very large. Quorum The algorithm allows the write operation to be completed as long as 3 The station will return. The rest is done in slow synchronization within the system. Read operations, you need to read at least 3 , to ensure that at least one can read the latest data.
Quorum 's read-write minimum number of votes can be used as an adjustable parameter for the system in terms of read and write performance. the larger the number of votes in vW, the smaller the number of read votes vR, when the system writes a large overhead. Conversely, the cost of writing is small.
Iv. several sets of examples
Example 1: at least 2 Peopleborn in the same year have the same birthday.
Example 2: Kindergarten bought a lot of white rabbits, pandas, giraffes plastic toys, each child arbitrarily choose two pieces, then anyway selected, in any seven children always have two each other toys are the same, try to explain the truth .
Example 3: From 2,4,6、...、 An even number, whichever is 9 , proves that there must be a sum of two .
1 , 2 3 , 4 、...、 19 , 20 this 20 12
Example 5: From 1 to three of the number, any one of the number, there must be two numbers, one number is a multiple of another number.
Example 6: A school anniversary, came N Alumni, mutual understanding of the handshake Greetings . please prove that no matter what the situation, in this N at least two of the alumni shook hands as many times as they could.
Example 7: The tennis is divided into 4 piles of different numbers , the largest number of a bunch of at least how many balls?
Example 8 proves that: any 8 Natural number, must have two number of the difference is a multiple of 7.
Example 9: For any of the five natural numbers, it is proved that there must be 3 of the number and can be divisible by 3 .
Example 9′: For any of the integers, it is proved that there must be 6 number, and their and can be divisible by 6 .
Example 10: Any given 7 different natural numbers, proving that there must be two integers, whose and or difference is a multiple of ten .
Example 11: Each line in nine straight lines divides the square into a trapezoid with an area ratio of 2:3 , proving that at least three of the nine lines go through the same point .
Example 12: The breeder gives ten monkeys an apple, in which at least one of the monkeys gets 7 apples, and how many apples will the breeder bring at least?
Example 13: From the number of natural numbers, you can find two numbers, their difference is a multiple of three .
Example 14: A class has nine students, now have extra-curricular books . Give these books to the students, will anyone get 4 or 4 or more extracurricular books?
Example 15:42 pigeons fly into 5 Cages to ensure that there are at least a few pigeons in the most pigeon cages?
Let's think about it and see why did answer.
To highlight the copyright, after each algorithm, fill in the original word. Hey!
Chai tou Feng · Nostalgia
Hometown is far, the years are many, the full face tear-stained sentiment is difficult to fall,
Childhood laugh, this is not yesterday, a cup of nostalgia, ten years being
Hide! Hide it! Hide it!
The temple has been white, people have been thin, bubble reputation difficult to heart
West cold, night dim, alone according to the door, tearful pretending Huan,
Difficult! It's hard! It's hard!
Zookeeper (i) from the drawer algorithm to the quorum (NRW) algorithm