Lecture from: 13.03.2025 | Video: Homelab

Recap

Let’s first revisit the concept of graph coloring, which we discussed in the previous lecture, as it provides a good starting point before we delve into the world of algorithms and probability.

k-Färbung (k-Coloring) and Chromatic Number

Definition of k-Coloring:

A k-coloring of a graph with colors is a mapping or function , where represents the set of colors. The essential condition for a valid k-coloring is that for every edge , the colors assigned to vertices and must be different:

for all edges .

In essence, we are assigning one of colors to each vertex such that no two adjacent vertices (connected by an edge) share the same color.

Chromatic Number

The chromatic number of a graph , denoted as , is the minimum number of colors needed to achieve a valid vertex coloring of . It is the smallest integer for which a k-coloring of exists.

Equivalence to k-Partite Graphs:

A graph is k-colorable (i.e., ) if and only if is k-partite. A k-partite graph is one whose vertices can be partitioned into independent sets (stable sets). An independent set is a set of vertices where no two vertices are adjacent. In a k-coloring, vertices of the same color form an independent set.

Special Case: Bipartite Graphs and 2-Colorability:

A graph is bipartite if and only if it is 2-colorable, i.e., . We can efficiently check if a graph is bipartite and find a 2-coloring in linear time using BFS or DFS.

Greedy Coloring Algorithm: A Simple Approach

We discussed the Greedy Coloring Algorithm as a basic heuristic for graph coloring.

GREEDY-FÄRBUNG (G):

  1. Choose a Vertex Ordering: Select an arbitrary ordering of the vertices .
  2. Color the First Vertex: Assign color 1 to the first vertex in the ordering: .
  3. Iterate and Color: For each subsequent vertex (from to ): This means, for each vertex , we assign the smallest positive integer color that is not already used by any of its neighbors that come before it in the chosen vertex ordering.

Observation about Greedy Coloring:

For any vertex ordering, the Greedy Coloring Algorithm will never use more than colors, where is the maximum degree of the graph . This is because, when coloring a vertex , it has at most neighbors, so there is always at least one color available from the first colors.

Heuristic: Smallest Degree Vertex Ordering

To improve the performance of the Greedy Algorithm, we can use a heuristic for vertex ordering:

  1. Find a vertex with the minimum degree in the current graph.
  2. Remove and all incident edges.
  3. Recursively find a smallest-last ordering for the remaining graph, say .
  4. The smallest-last ordering is then .

This heuristic tends to color vertices with fewer constraints (lower degree) later, which often leads to better colorings.

Observation with Smallest-Last Ordering:

If for a chosen vertex ordering , for all , the number of already colored neighbors of is at most (i.e., ), then the Greedy Algorithm will use at most colors.

Corollaries based on Heuristic and Graph Properties:

  • Trees: The heuristic finds a 2-coloring for trees because in any subgraph of a tree (which is a forest), there is always a vertex of degree at most 1 (a leaf, or an isolated vertex). Thus, , and the algorithm uses at most colors.
  • Planar Graphs: For planar graphs, it is known that there’s always a vertex of degree at most 5. Using the smallest-last heuristic, we can often ensure that for each vertex , it has at most 5 already colored neighbors. Thus, the heuristic finds a coloring with at most colors for planar graphs.
  • Connected Graphs with a Low Degree Vertex: If a connected graph has a vertex with degree , then the heuristic (or even BFS/DFS ordering) can provide a vertex ordering for which the Greedy Algorithm uses at most colors.

Color Class Swapping and Block Graphs

In some situations, we can improve a coloring by swapping color classes. If we have a valid coloring, and we decide to swap the vertices colored with color A with vertices colored with color B, we might still have a valid coloring or create a new valid coloring with desired properties.

Application: Block Graphs

Consider a Block Graph. A block of a graph is a maximal 2-connected subgraph, or a bridge, or an isolated vertex. Block graphs have a structure composed of blocks connected at cut vertices (articulation points).

Property: If every block of a graph can be colored with colors, then the entire graph can also be colored with colors.

Reasoning: We can color each block independently with colors. When blocks share vertices (at articulation points), we might need to adjust the color classes within some blocks (by swapping colors) to ensure that at the articulation points, the colorings are consistent across different blocks. Since each block is k-colorable, and we can manage color assignments at articulation points using color swapping, we can extend the k-coloring to the whole graph.

Four-Color Theorem

4-Farben-Theorem: Every planar graph (a graph that can be drawn in the plane without edge crossings) can be colored with at most 4 colors.

This is a famous theorem in graph theory.

Algorithm for Coloring Planar Graphs with 5 Colors (Sketch):

While the 4-Color Theorem is complex to prove, there is a simpler algorithm to color planar graphs with 5 colors.

  1. Find a Vertex of Degree : In any planar graph, there is always at least one vertex with degree at most 5. Let’s find such a vertex .
  2. Recursively Color : Remove and its incident edges to get a smaller planar graph . Recursively color with 5 colors.
  3. Color Vertex : Consider the neighbors of in the original graph .
    • Case 1: Neighbors use colors: If the neighbors of in use at most 4 different colors in the coloring of , then we can simply color with the 5th color (or any color not used by its neighbors).
    • Case 2: Neighbors use 5 colors: If the neighbors of , say (in cyclic order), use all 5 colors (say colors 1, 2, 3, 4, 5, respectively).
      • Consider the subgraph induced by vertices colored with colors 1 or 3 in . Similarly, consider for colors 2 and 4.
      • Subcase 2a: If and are in different connected components in , then we can swap colors 1 and 3 in the component of containing . After swapping, and both have color 3 (or both color 1, depending on swap direction), so color 1 becomes available for . Color with color 1.
      • Subcase 2b: If and are in the same component in , then and must be in different components in (otherwise, paths from to and from to would cross in a planar graph, forming a Kempe chain contradiction). Swap colors 2 and 4 in the component of containing . Color 2 becomes available for . Color with color 2.

This algorithm recursively colors planar graphs with 5 colors.

Observation: Dependence on Vertex Ordering

As we’ve seen, the performance of the Greedy Coloring Algorithm is heavily dependent on the chosen vertex ordering. While for some orderings, it can achieve the optimal chromatic number, for others, it can perform significantly worse, even for simple graphs like bipartite graphs.

Improved Greedy Coloring with Heuristics

To mitigate the dependency on arbitrary vertex orderings and improve the practical performance of the Greedy Coloring Algorithm, we can employ heuristics to guide the selection of vertex orderings.

Smallest-Last Vertex Ordering Heuristic (Revisited)

We discussed the smallest-last vertex ordering as a heuristic. Let’s reiterate its benefits:

  • Intuition: Delay coloring vertices with lower degrees until later. These vertices have fewer constraints and are more likely to be easily colorable with already used colors.
  • Procedure: Repeatedly find and remove a vertex of minimum degree from the remaining graph, placing it last in the ordering.

Heuristic Algorithm

  1. Initialize an empty vertex ordering list .
  2. While the graph is not empty: a. Find a vertex with the minimum degree in the current graph. b. Append to the beginning of . c. Remove and its incident edges from the graph.
  3. Reverse the list to get the final vertex ordering .
  4. Apply the Greedy Coloring Algorithm using the vertex ordering .

Benefits of Smallest-Last Ordering

  • Trees: Guarantees a 2-coloring for trees.
  • Planar Graphs: Often produces colorings with 6 or fewer colors for planar graphs (though 4 colors are always sufficient by the Four-Color Theorem).
  • General Graphs: Generally performs better than arbitrary orderings, especially for sparse graphs.

Brooks’ Theorem

Brooks’ Theorem: For a connected graph , if is not a complete graph and not an odd cycle , then the chromatic number of is at most its maximum degree :

If , , and is connected, then .

Furthermore, such a -coloring can be found in time .

Significance of Brooks’ Theorem:

  • Tight Bound: Brooks’ Theorem provides a tighter upper bound on the chromatic number than the bound given by the Greedy Coloring Algorithm with an arbitrary ordering. It shows that in most cases, we can color a graph using at most its maximum degree of colors, not necessarily one more.
  • Exceptions: The exceptions ( and ) are necessary. For a complete graph , . For an odd cycle , , while , so .
  • Algorithmic Implication: Brooks’ Theorem not only gives a bound but also implies that there is an efficient algorithm (running in time) to find such a -coloring (under the given conditions).

Algorithm Sketch for Brooks’ Theorem

Here’s a sketch of an algorithm to find a -coloring for graphs satisfying the conditions of Brooks’ Theorem, running in time .

  1. Case: :

    • If and is connected and not an odd cycle, then must be either a path or an even cycle.
    • In this case, we can color with just two colors. (Paths and even cycles are bipartite and 2-colorable).
  2. Case: with :

    • If there exists a vertex in whose degree is strictly less than the maximum degree , we can use the Greedy Coloring Algorithm with the Smallest-Last Heuristic.
    • As discussed earlier, in this scenario, the Greedy Algorithm with a good heuristic (like smallest-last) is guaranteed to use at most colors.
  3. Case: Articulation Point (Cut Vertex) Exists:

    • If has an articulation point (cut vertex) , we can decompose into its blocks.
    • Color each block of (which are 2-connected components, bridges, or isolated vertices) with colors using a suitable heuristic. Note that within each block (except possibly the block containing the vertex with maximum degree in G), vertices will have a degree less than in the original graph .
    • After coloring all blocks, we might need to perform color class swapping to ensure that the coloring is consistent at the articulation point . Since is in multiple blocks, we need to make sure it has the same color in all blocks it belongs to. We can achieve this by swapping color classes within blocks, if necessary.
  4. Case: Determine Vertices with and :

    • If none of the above cases apply, we need to find vertices such that and are neighbors of (), but and are not adjacent to each other (). Such vertices must exist because is connected and not a complete graph.
  5. Construct :

    • Consider a new graph obtained by removing vertices and from , i.e., .
  6. Subcases based on Connectivity of :

    • Case 6a: is connected ( zshgd):

      • Pre-color and : Since and are not adjacent, we can initially consider coloring them with the same color. However, for the algorithm’s structure, it’s more convenient to handle them as the first two vertices to be colored in a specific ordering of .
      • Color with Greedy Algorithm: We now need to color the connected graph . We can use the Greedy Coloring Algorithm combined with a suitable Heuristic (like the smallest-last vertex ordering) for .
    • Case 6b: is not connected ( nicht zshgd):

      • Consider Connected Components of : If removing and disconnects , let be the connected components of .
      • Analyze Neighbors of and in Components: For each component , consider the neighbors of and within .
      • Subcase 6b(i): Limited Neighbors in at least one Component: If for at least one component, say , both and have at most neighbors in . This implies that when we consider coloring , even if we force and to have the same color, the maximum degree condition within (considering neighbors within ) is still manageable for the Greedy Algorithm to work within colors.
      • Subcase 6b(ii): Many Neighbors in Components, but Specific Structure: If for every component , either or (or both) have close to neighbors in . Brooks’ theorem algorithm uses a more detailed argument here, possibly involving considering only two components () and analyzing the degrees of and in these components to carefully assign colors and possibly swap color classes to avoid using more than colors. For the entire proof look at the script…
  7. Final Coloring: By carefully handling all these cases, particularly Case 6 and its subcases, and potentially using color class swaps or specific ordering strategies within the Greedy Algorithm, Brooks’ Theorem guarantees that we can color the graph using at most colors, provided is not a complete graph or an odd cycle . The algorithm can be implemented to run in time by efficiently managing the graph structure and color assignments.

This algorithm sketch outlines how to find a -coloring for graphs satisfying Brooks’ Theorem conditions in time. The details, especially for handling disconnected cases and color class swapping, are more involved but are based on careful application of the Greedy Algorithm and color adjustments.

Further Algorithmic Ideas

Heuristic: Smallest Degree Vertex Ordering (Revisited):

We have discussed the smallest-last vertex ordering heuristic. The underlying principle is:

“Save the easy-to-color vertices for last.”

Opposite Idea

An alternative, sometimes useful, idea is the opposite:

“Start with a simple subgraph and color it first. Use new colors for the rest.”

Coloring 3-Colorable Graphs with Colors:

  1. Iterative Removal of High-Degree Vertices (max iterations): While there exists a vertex with more than uncolored neighbors:

    • Color with a new color.
    • Color all uncolored neighbors of with 2 additional new colors (which we can since is two colorable).
    • Remove all newly colored vertices from the graph.
  2. Greedy Coloring on Remaining Graph: The remaining graph will have a maximum degree . Color the remaining vertices using the Greedy Coloring Algorithm, which will use at most new colors.

This algorithm combines the idea of dealing with “complex” (high-degree) parts of the graph first using new colors and then using a simpler greedy approach for the remaining, “simpler” part.

Randomness in Computer Science

Let’s now shift our focus to the crucial role of probability in algorithms and computer science.

Why Should Every Computer Scientist Understand Probability Theory?

Randomness and probability are not merely abstract mathematical concepts. They are, in fact, powerful and practical tools that computer scientists use to design algorithms that are both efficient and effective. The introduction of randomness into algorithms can often lead to solutions that are simpler, faster, or even possible when deterministic approaches fall short.

Examples of Algorithms Utilizing Randomness

Let’s explore several key examples where randomness is not just an add-on, but a core component enabling the algorithm’s success.

1. QuickSort Algorithm: Random Pivot Selection

Question: What truly makes QuickSort live up to its name, “QuickSort”?

Answer: The defining characteristic of QuickSort, and the key to its efficiency, especially in average-case scenarios, is the random selection of the pivot element.

In QuickSort, a pivot element is chosen to partition the array. A naive, deterministic choice of the pivot (like always picking the first or last element) can lead to worst-case time complexity when the input array is already sorted or nearly sorted.

However, by selecting the pivot element randomly from the array, we drastically reduce the probability of consistently encountering these worst-case scenarios. Randomization ensures that, on average, the pivot will be reasonably close to the median, leading to balanced partitions and a much faster sorting process. This randomized pivot selection “averages out” the performance across all possible input arrays, resulting in an expected time complexity of for sorting elements. This is the reason behind QuickSort’s celebrated “quick” performance in practice.

2. Primality Testing: Randomized Probabilistic Tests

Problem: Given a natural number , we want to determine efficiently whether is a prime number.

Importance: Primality testing is a fundamental problem with immense practical significance, particularly in the field of cryptography. Public-key cryptography systems like RSA rely heavily on the generation and use of large prime numbers. The ability to efficiently test if a large number is prime is thus critical for secure communication and data protection.

Randomized Algorithm for Primality Testing (Probabilistic Tests):

For very large numbers, deterministic primality tests can be computationally expensive. Randomized primality tests offer a much more efficient alternative. A typical approach is as follows:

  • Random Witness Selection: Choose a random integer within a specific range (e.g., ).
  • Probabilistic Test: Perform a probabilistic primality test, such as the Miller-Rabin test, to check if acts as a “witness” for the compositeness of .
    • If is found to be a witness, we can definitively conclude that is composite (not prime).
    • If is not a witness after the test, we can say that is likely prime. There is a small probability of error, but we cannot be absolutely certain based on a single test.

Reducing Error Probability through Repetition:

The power of randomized primality testing lies in the fact that by repeating the test multiple times with independently chosen random values of , we can dramatically reduce the probability of error. Each independent test provides additional evidence. If is composite, the probability of a randomly chosen not being a witness is bounded, meaning that with enough repetitions, the chance of incorrectly declaring a composite number as prime becomes negligibly small. Randomized primality tests like Miller-Rabin are significantly faster than deterministic methods, making them indispensable for cryptographic applications dealing with very large numbers.

3. Cryptography: Leveraging Randomness for Security

Randomness is not just about efficiency in cryptography; it’s often about security itself. Let’s look at two examples:

Visual Cryptography:

Visual cryptography is an intriguing cryptographic technique that cleverly uses randomness to encrypt visual information (like images). The beauty of visual cryptography is that decryption can be performed by the human visual system, simply by overlaying or stacking encrypted shares, without the need for complex computations.

The process typically involves:

  • Image Splitting: An original image is split into multiple “shares” (often two).
  • Random Share Generation: These shares are generated using random processes in such a way that:
    • Individual shares reveal absolutely no information about the original image when viewed in isolation. They appear as random noise.
    • When the shares are combined correctly (e.g., overlaid), the original image magically reappears.

Randomness is absolutely crucial in the share generation process to ensure that individual shares leak no information, and that only the correct combination of shares reveals the secret image.

Zero-Knowledge Protocols:

Zero-knowledge protocols are a fascinating concept in cryptography. They enable one party (the prover, often called Alice) to convince another party (the verifier, often called Bob) that a statement is true, without revealing any information beyond the mere truth of the statement. Randomness is a fundamental building block in the design of many zero-knowledge protocols.

Let’s consider two illustrative examples of zero-knowledge protocols:

Example 1: Graph Isomorphism Zero-Knowledge Proof

Imagine Alice knows that two graphs, and , are isomorphic (they have the same structure, just possibly with different vertex labels). She wants to prove this to Bob, but without revealing the actual isomorphism (the mapping of vertices between and ). A zero-knowledge protocol allows her to do this:

  1. Random Permutation by Alice: Alice takes her graph and applies a random permutation to its vertices, creating a new graph . She then sends this permuted graph to Bob. Crucially, Bob does not know the permutation used.
  2. Random Challenge by Bob: Bob, upon receiving , randomly chooses one of two challenges for Alice to prove:
    • (a) Isomorphism to Original G: Prove that is isomorphic to the original graph (i.e., ).
    • (b) Isomorphism to G’: Prove that is isomorphic to the graph (i.e., ).
  3. Alice’s Proof: Alice, because she knows the isomorphism between and , and she created by permuting , can fulfill either challenge:
    • If Bob chooses (a): Alice simply sends Bob the permutation she used to create from . Bob can easily verify that applying this permutation to indeed results in .
    • If Bob chooses (b): Alice uses her knowledge of the isomorphism between and and the inverse of the permutation she used. She can construct and send Bob a permutation that demonstrates the isomorphism between and .
  4. Bob’s Verification: Bob verifies the permutation he receives against the chosen challenge (either (a) or (b)).

Iteration and Increasing Confidence:

Bob only receives a proof for one of the two possibilities (a) or (b) in a single round. However, if Alice truly knows the isomorphism between and , she can successfully respond to either challenge. If Alice did not know the isomorphism, she could at best guess correctly with a 50% probability in each round. By repeating this protocol multiple times (e.g., 1000 rounds), Bob’s confidence that Alice genuinely knows the isomorphism grows exponentially. After many rounds, the probability of Alice successfully cheating becomes astronomically small. Yet, Bob learns nothing about the actual isomorphism itself – only that Alice can consistently prove isomorphism to either or when challenged randomly.

Example 2: Zero-Knowledge Proof for Solving

Suppose Alice knows a solution to the modular exponentiation equation . She wants to prove this to Bob, but without revealing the secret value .

  1. Random Value Generation by Alice: Alice chooses a random number from the multiplicative group modulo , denoted as (numbers coprime to ). The randomness of is key.
  2. Commitment Sending: Alice computes and sends this value to Bob. This is her “commitment” – a value derived from her random choice.
  3. Random Challenge by Bob: Bob then randomly challenges Alice to reveal one of two things:
    • (a) Reveal : Bob asks Alice to reveal the random number she chose.
    • (b) Reveal : Bob asks Alice to reveal the product of her secret solution and her random number , modulo .
  4. Alice’s Response: Alice provides the value requested by Bob.
  5. Bob’s Verification: Bob verifies the response:
    • If Bob chose (a): Bob checks if Alice’s revealed , when raised to the power modulo , indeed matches the value that Alice sent in step 2.
    • If Bob chose (b): Bob checks if the revealed value, say , satisfies . This verification uses the commitment and the original equation .

Security and Zero-Knowledge Property:

Again, by repeating this protocol multiple times with fresh random choices of , Bob gains high confidence that Alice genuinely knows a solution to the equation. However, in each round, Bob only learns either or . Neither of these values alone reveals the secret solution . The protocol is carefully constructed to be zero-knowledge – Bob learns nothing about itself, only that Alice can consistently prove she knows a solution when challenged randomly.

4. Distributed Computing and Swarm Computing: Breaking Symmetry

Distributed Computing: In distributed computing systems, multiple independent computers or nodes must cooperate and coordinate their actions to solve a common problem. A significant challenge in distributed algorithms is breaking symmetry. In many scenarios, nodes might have identical initial states and perceive the network symmetrically. Deterministic algorithms, in such cases, can lead to all nodes making the same decisions, which can hinder progress or lead to suboptimal outcomes.

Swarm Computing: Swarm computing draws inspiration from collective behaviors observed in natural swarms, such as bird flocks, fish schools, and insect colonies. These systems are characterized by decentralized control, local interactions, and often, the use of randomness to achieve complex collective behaviors. Swarm computing algorithms often employ randomized strategies for coordination and problem-solving in multi-agent systems.

Example: Distributed Algorithm for Finding a Large Stable Set

Consider a line graph or a grid graph. We want to design a distributed algorithm for finding a large stable set (a set of vertices with no edges between them) in such a graph. If all nodes were to follow a deterministic algorithm in a symmetric graph, nodes in equivalent positions might end up making identical decisions, potentially leading to a small or inefficiently constructed stable set.

Using Randomness to Break Symmetry in Stable Set Algorithm:

Randomness provides a powerful mechanism to break symmetry in distributed algorithms. For finding a large stable set, a randomized approach can be as follows:

  1. Round-Based Deletion: The algorithm proceeds in rounds. In each round, consider every edge in the current graph.
  2. Random Node Deletion: For each edge , nodes and independently and randomly decide with a certain probability (e.g., 1/2) whether to “delete” themselves. “Deleting” a node means deciding not to include it in the stable set. If a node decides to delete itself, it informs its neighbors about this decision.
  3. Graph Reduction: After each round, remove all nodes that decided to delete themselves and all edges incident to these deleted nodes.
  4. Iteration: Repeat steps 1-3 for a predetermined number of rounds or until no more edges remain.
  5. Resulting Stable Set: The nodes that survive after these rounds, i.e., those that were not deleted, will, with high probability, form a stable set. The randomness ensures that in each round, the decisions of neighboring nodes are not perfectly correlated, leading to a more diverse and ultimately larger stable set compared to deterministic approaches.

Why Deterministic Algorithms Fail in Symmetric Scenarios:

Deterministic algorithms in distributed settings, especially in symmetric graphs, often struggle to achieve good solutions because of the inherent symmetry. Without randomness, nodes in equivalent positions tend to make identical decisions, leading to a lack of diversity and potentially suboptimal global outcomes. Randomness introduces the necessary asymmetry to break these deadlock situations and allows distributed algorithms to explore a wider range of possibilities, leading to better average-case performance and the ability to find good solutions in scenarios where deterministic algorithms are limited.

Continue here: 09 Discrete Probability Space, Properties of Probability, Union of Events, Laplace Space, Composite Probability, Combinatorics