0% found this document useful (0 votes)
21 views2 pages

Greedy Algorithms and Invariants Explained

The document discusses various examples of greedy algorithms and their proofs, including selecting numbers from a 2 × n array, finding an induced subgraph in a graph, and covering nonnegative integers with historic sets. It also explores invariants and monovariants with an example involving a chessboard and conditions for achieving zero in all squares. The proofs demonstrate the underlying principles and conditions necessary for the algorithms to function correctly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Greedy Algorithms and Invariants Explained

The document discusses various examples of greedy algorithms and their proofs, including selecting numbers from a 2 × n array, finding an induced subgraph in a graph, and covering nonnegative integers with historic sets. It also explores invariants and monovariants with an example involving a chessboard and conditions for achieving zero in all squares. The proofs demonstrate the underlying principles and conditions necessary for the algorithms to function correctly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithms

W EERAWAT P.
23 January 2025

§1 Greedy Algorithms

Example 1.1 (Russia 2005, France 2006, India TST 2012)


In a 2 × n array we have positive reals s.t. the sum of the numbers in each of the n columns
is 1. Show that we can select a number in each column s.t. the sum of the selected numbers
in each row is at most n+1
4 .

Proof. Let the numbers in the top row in non-decreasing order be a1 , a2 , . . . , an and let b1 , b2 , . . . , bn
be the corresponding numbers in the bottom row. Note that b1 ≥ b2 ≥ . . . ≥ bn . To have the desired
conclusion, select a1 , a2 , . . . , ak such that a1 + a2 + . . . + ak ≤ n+1 n+1
4 but a1 + a2 + . . . + ak+1 > 4 .
Consider the inequality
n+1
bk+1 + bk+2 + . . . + bn ≤
4
3n − 4k − 1
⇐⇒ ak+1 + ak+2 + . . . + an ≥
4
n+1 (n+1)(n−k)
Note that an ≥ an−1 ≥ . . . ≥ ak+1 > 4(k+1) . Thus, ak+1 + ak+2 + . . . + an > 4(k+1) . It suffices
to prove that
(n + 1)(n − k) 3n − 4k − 1

4(k + 1) 4
⇐⇒ (n − 2k − 1)2 ≥ 0

which is true.

Example 1.2
In a graph G with V vertices and E edges, show that there exists an induced subgraph H
with each vertex having degree at least VE . (In other words, a graph with average degree d
has an induced subgraph with minimum degree at least d2 .)

Proof. Label the vertices “bad” if their degree is less than VE . To get the induced subgraph H,
delete any of the bad vertex of G, one at a time. We claim that the induced subgraph H is
guaranteed. This is because the ratio of edges and vertices after deleting n bad vertex is greater
E− nE
than V −nV = VE . Therefore, it is impossible to reach a stage when only 1 vertex is remaining
where the ratio of edges and vertices is zero. Hence, at some point, the algorithm will terminate,
leaving us with our desired induced subgraph H.

1
Weerawat P. — 23 January 2025 Algorithms

Example 1.3 (IMO Shortlist 2001, C4)


A set of three nonnegative integers {x, y, z} with x < y < z satisfying
{z − y, y − x} = {1776, 2001} is called a historic set. Show that the set of all nonnegative
integers can be written as a union of pairwise disjoint historic sets.

Proof. Let a = 1776 and b = 2001. A historic set is either of the form {x, x + a, x + a + b} or
{x, x + b, x + a + b}. Call these sets small sets and big sets respectively. We reframe the problem
as follows: Let the set of all nonnegative integers be written on a line. In each move, choose a
historic set and cover the corresponding numbers on the number line. We wish to show that all
numbers on the line could be covered where there are no repetitions. To do so, in each turn, we
cover the smallest number (which is also the smallest number in the set) that is not yet covered.
Use the small set if possible. Otherwise, use the big set. It suffices to show that this algorithm
can run indefinitely. Assume the contrary that there exists a move which terminates the algorithm.
Suppose it fails in the nth step where either the big set or the small set would cover the numbers
that has already been covered. Denote the smallest number covered in the ith turn by xi . We have
that xn + b = xi + a + b for some i. That is, xi = xn − a. This means that the number xn should
have been covered in the ith move, a contradiction.

§2 Invariants and Monovariants

Example 2.1 (IMO Shortlist 1989)


A natural number is written in each square of an m × n chess board. The allowed move is to
add an integer k to each of two adjacent numbers in such a way that non-negative numbers
are obtained. (Two squares are adjacent if they have a common side.) Find a necessary and
sufficient condition for it to be possible for all the numbers to be zero after finitely many
operations.

Proof. We color the board black and white alternately, starting from black in the first cell (first
row and column), where every adjacent cells are of different colors. Denote the sum of numbers
on black and white squares Sb and Sw respectively. In each move, we add the same number on
two squares, one of which is white and one is black. Thus, Sb − Sw is an invariant. At the end,
Sb − Sw = 0, that means Sb = Sw at the beginning as well. Therefore, this is a necessary condition.
Next, we prove that this is a sufficient condition.

Common questions

Powered by AI

The algorithm achieves no overlapping by covering integers in a strict order starting with the smallest uncovered number by scheduling small or big sets where numbers have not yet been covered. This precise ordering circumvents overlaps shown by the contradiction that any premature overlap implies a prior occurrence of a number in another step, thus ensuring the sequence of operations respects non-repetition in set coverage .

By defining vertices with a degree less than \( \frac{E}{V} \) as 'bad', and iteratively removing these from the graph, an induced subgraph is formed. This induced subgraph will eventually ensure the minimum degree is at least \( \frac{E}{V} \). The process continues until the ratio of edges to vertices, \( E-nE/V \) to \( V-n \), never drops below \( \frac{E}{V} \), proving that such an induced subgraph must exist .

Monovariants, by their consistent increase or decrease, act as guiding constraints ensuring that the trajectory of states maintains feasibility towards desired outcomes, such as equating all numbers to zero or meeting a balance condition. They provide assurance over continuity and control, operating within allowed operations to steer towards comprehensive state changes without violating inherent structural rules .

The problem is reframed to cover all the nonnegative integers using either 'small sets' \( \{x, x+a, x+a+b\} \) or 'big sets' \( \{x, x+b, x+a+b\} \). In each move, the smallest uncovered number is chosen, using a small set if possible, otherwise a big set. This ensures no repetition and the strategy can be indefinitely continued. Assuming termination contradicts that all possible numbers are covered in each step by showing \( x_n+b = x_i+a+b \) implies \( x_i = x_n-a \), proving \( x_n \) must have been included earlier .

Strategy-proofing in the 2x\( n \) array example shows that the greedy approach of selecting numbers ensures solutions that avoid intentionally bad choices leading to suboptimal sums. The method of picking \( a_1,a_2,...,a_k \) such that their sum stays \( \le \frac{n+1}{4} \) without crossing it unless another \( a_{k+1} \) is picked, guarantees that exchanges or deviations won't improve the outcome, thus the initial strategy remains optimal .

The selection process involves ordering numbers in the top row in non-decreasing order (\( a_1,a_2,...,a_n \)), and in the bottom row in non-increasing order (\( b_1,b_2,...,b_n \)). Numbers \( a_1,a_2,...,a_k \) are selected such that their sum is up to \( \frac{n+1}{4} \) while adding another number \( a_{k+1} \) surpasses this threshold. By considering inequality \( b_{k+1}+b_{k+2}+...+b_n \le \frac{n+1}{4} \), it implies \( a_{k+1}+a_{k+2}+...+a_n \ge \frac{3n-4k-1}{4} \). Thus, the sum \( a_{k+1}+a_{k+2}+...+a_n \) exceeds \( \frac{(n+1)(n-k)}{4(k+1)} \) proving that \( (n-2k-1)^2 \) is non-negative, satisfying the condition .

Removing 'bad' vertices, those with a degree below \( \frac{E}{V} \), iteratively, results in an induced subgraph where each vertex achieves or surpasses this average degree threshold. Since the process stops where the edge-to-vertex ratio never dips below the threshold, the key implication is helping form a subgraph that retains stronger connectivity and degree properties aligned with average metrics from the original graph .

Invariant conditions centralize on values remaining unchanged despite transformations, forming a backbone for allowable modifications. They embody integral balances or sums, such as \( S_b - S_w \), conserved perpetually, dictating whether and how transformations can occur without disrupting foundational parameters. By determining feasibleness, these invariants underpin solution paths aligning with the initial conditions and adjust potential strategies .

A necessary and sufficient condition is that the difference between the sum of numbers on black squares \( S_b \) and white squares \( S_w \) is invariant and equals zero initially. This is ensured by alternately coloring the chessboard starting with black and using moves that either add or subtract from differently colored adjacent squares, maintaining \( S_b - S_w \). Thus, achieving zero for all is possible, if initially \( S_b = S_w \).

Invariants such as \( S_b - S_w \) (difference between sum of numbers on black and white squares) guide the transformation process by ensuring conditions are met that preserve the overarching goal. Through strategic moves based on adding to adjacent squares of different colors, the invariant helps regulate whether it is possible for total numbers to become zero while maintaining a consistent value for \( S_b - S_w \) throughout transformations .

You might also like