Eindhoven University of Technology

BACHELOR

On the maximum problem a new 0.5-

de Quincey, Martin G.

Award date: 2019

Link to publication

Disclaimer This document contains a student thesis (bachelor's or master's), as authored by a student at Eindhoven University of Technology. Student theses are made available in the TU/e repository upon obtaining the required degree. The grade received is not published on the document as presented in the repository. The required complexity or quality of research of student theses may vary by program, and the required minimum study period may vary in duration.

General rights Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights.

• Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain Department of Mathematics and Computer Science

On the maximum cut problem: A new 0.5-approximation algorithm

Bachelor Thesis

Martin de Quincey

Supervisor: Dr. J. Nederlof

Committee member: Dr. J.C.M. Keijsper

Eindhoven, June 2019

Abstract

Given a graph, the maximum cut problem consists of finding a way to split the vertices of the graph into two sets such that it maximises the amount of edges between the two sets. In this Bachelor’s thesis, we explore this problem. Many approaches from different fields of mathematics can be utilised to solve this problem, each with its advantages and disadvantages. These approaches are described and analysed. Furthermore, we introduce a new algorithm for the maximum cut problem, which has an approximation ratio of at least 0.5. Whether this algorithm has an approximation ratio better than 0.5 is an open question. Additionally, we also investigate a new way of generating graphs, which allows us to estimate the value of the maximum cut using probability theory.

On the maximum cut problem: A new 0.5-approximation algorithm iii

Preface

This Bachelor’s thesis has been written as a completion of the three years Bachelor’s program of Applied Mathematics at the Eindhoven University of Technology.

I would like to thank my friends and family for their support throughout my Bachelor’s degree, as well as all the others who have helped me along the way.

Lastly, I would like to personally thank my supervisor, Jesper Nederlof, for helping me during the writing of this Bachelor’s thesis. His academic input and support were of great value to me.

On the maximum cut problem: A new 0.5-approximation algorithm v

Contents

Contents vii

1 Introduction 1 1.1 Applications of the Maximum Cut Problem...... 1 1.2 The Nature of the Maximum Cut Problem...... 2 1.3 Previous Contributions...... 2 1.4 Our Contribution...... 2

2 Preliminaries 3

3 Previous Contributions7 3.1 Exact Algorithms...... 7 3.1.1 Brute-Force Approach...... 7 3.1.2 Approach Using Matrix Multiplication...... 8 3.2 Approximation Algorithms...... 14 3.2.1 Random Approach...... 14 3.2.2 Greedy Approach...... 15 3.2.3 Local Search Approach...... 16 3.2.4 Linear Algebra Approach [24]...... 18 3.2.5 Semi-Definite Programming Approach [9]...... 21 3.3 A minimum cut algorithm: Karger’s algorithm...... 26

4 A new algorithm for Max-Cut 31 4.1 Description...... 31 4.2 Approximation Ratio...... 33 4.3 Instances of graphs where our algorithm performs well...... 36 4.3.1 Connected Bipartite graphs...... 36 4.4 Uniform Spanning Trees...... 36

5 pq-Graphs 39 5.1 Generating pq-graphs...... 39 5.2 Analysis of the maximum cut in pq-graphs...... 40 5.2.1 Attempt 1: using the binomial distribution...... 40 5.2.2 Attempt 2: using a strict Chernoff bound...... 41 5.2.3 Attempt 3: using a looser Chernoff bound...... 43 5.3 Approximation ratio of our algorithm on pq-graphs...... 45 5.4 Results on pq-graphs...... 47 5.4.1 Results when p = 0.01, q = 0.50 ...... 47 5.4.2 Results when p = 0.10, q = 0.50 ...... 48 5.4.3 Results when p = 0.25, q = 0.50 ...... 48

6 Conclusions 49

On the maximum cut problem: A new 0.5-approximation algorithm vii CONTENTS

List of Figures 51

List of Tables 53

Bibliography 55

Appendix 57

A Python code 57

B R code 68

viii On the maximum cut problem: A new 0.5-approximation algorithm Chapter 1

Introduction

In the introduction, we informally present the maximum cut problem, as well as some exciting applications discovered over the years. After this, we briefly touch upon the nature and the complexity of the problem and previous contributions to this problem. Subsequently, we describe in short what our contributions are to the maximum cut problem.

1.1 Applications of the Maximum Cut Problem

The maximum cut problem (or in short Max-Cut) has been around for many years, and nowadays, it is still a problem of great importance to solve. Applications of the maximum cut problem range from the circuitry industry to statistical physics. The maximum cut problem lies in the realm of graph theory and is precisely defined in the next Chapter. In essence, the maximum cut problem seeks a way to split the vertices of a graph into two disjoint sets such it maximises the number of edges between two sets. This problem can be translated to an equivalent problem that has been around for a long time, albeit a bit far-fetched. Consider a group of people, and each vertex represents a vertex, and we denote that two people do not like each other by creating an edge between the corresponding vertices. Finding a split such that we put the lowest amount of people who do not like each other in the same group, is equivalent to solving the maximum cut problem in the graph. Nowadays, there are more sophisticated and complex applications of the maximum cut problem. Intriguing to us is that the problem can be translated to problems from entirely different fields. First of all, finding a maximum cut is vital in the circuitry industry, in a process called Very- Large-Scale Integration (VLSI) [1]. This process consists of creating an integrated circuit by combining hundreds of thousands of transistors onto one single chip. These transistors must be wired together, and in certain circumstances, a so-called via must be placed. Vias are integrated on a circuit to create an electronic connection between different layers of an electronic circuit. In the physical world, vias are obstacles that take additional space, often contributing to the failure of the circuitry. Furthermore, creating these vias is costly work, since chips and circuits are manufactured on a microscopic scale nowadays. Thus, the number of vias in a circuitry must be minimised. As described in [1], the minimisation of the number of vias can be translated to a weighted maximum cut problem. The weighted maximum cut problem (weighted max-cut) is the general case of the problem we address in this Bachelor’s Thesis, where each edge has a weight. Another surprising application is in the field of statistical physics, in the branch of magnetism [1]. In this field of physics, there are so-called spin glasses. These are systems which are neither ferromagnetic nor anti-ferromagnetic [19]. The ground state of these spin glasses is an important question. As it turns out, one of the most successful models to determine the ground state turned this question into an optimisation problem of Ising spins [16]. Consequently, this problem can be translated to a weighted maximum cut problem. Thus, the weighted maximum cut problem can be used to determine the ground state of a particular category of systems, namely spin glasses.

On the maximum cut problem: A new 0.5-approximation algorithm 1 CHAPTER 1. INTRODUCTION

1.2 The Nature of the Maximum Cut Problem

Above, we have seen that there are indeed essential applications of the maximum cut problem, and thus solving this problem is of great importance to various fields of research. Unfortunately, the main obstacle for solving the maximum cut problem is that it is computationally exhaustive. In 1972, Richard M. Karp proved, among 20 other famous problems, that the weighted maximum cut problem is NP-complete [14]. A problem being NP-complete means that the problem belongs to a group of other problems that are not solvable in polynomial time unless P = NP . In practice, that means that these problems are unsolvable for inputs of considerable size. The NP-completeness of weighted max-cut did, however, not necessarily mean that the simpler variant was also NP- complete. In 1974, the maximum cut problem that we address in this Bachelor’s Thesis was also proven to be NP-complete by Garey et al. [8]. Thus, the problem is practically impossible to solve exactly. As a consequence, the main focus shifted to trying to find fast algorithms that approximate the maximum cut as close as possible. In general, these algorithms run in polynomial time, meaning that they are suitable for large inputs, with the trade-off that they do not give the exact solution. However, even approximating this problem has its limits; getting approximations that run in polynomial time, and are better 16 than 17 th of the optimal value has also proven to be NP-complete, which would imply that P = NP [10]. Furthermore, it has been proven that the best approximation algorithm can only approximate the optimal solution to a factor of 0.878..., but only if a conjectured called the is true. The unique games conjecture is an unproven statement in mathematics and computer science, first mentioned in [15] by Khot. Interestingly, the academic world seems to be divided on this matter; “Half of the people are working on proving it, and the other half is working on disproving it, and they are both failing.", says R O’Donnell in [17].

1.3 Previous Contributions

What is both intriguing and also the beauty of mathematics is that previous contributions find their foundations in completely different research fields. Clever approaches have been found in the field of linear algebra [24], randomised algorithms, semi-definite programming [9], matrix multiplication [26] and more. These contributions are explained in greater detail in the coming Chapters.

1.4 Our Contribution

What arguably is the most interesting about this problem are the approximation algorithms. As we will see, there is a straightforward algorithm that, on average, returns a solution half as good as the optimal solution. However, coming up with an algorithm that has an even slightly better so-called approximation ratio than a half turns out to be extremely difficult. Complex algorithms requiring a deep understanding of their mathematical principles are needed. As of now, there do not exist simple algorithms with an approximation ratio better than a half. This intriguing observation inspired this Bachelor’s Thesis; can we develop a simple algorithm which has a better approximation ratio than a half? Furthermore, we also give an extensive survey of previous contributions, trying to include contributions ranging from different fields of mathematics. We also investigate possibilities of creating graphs of large input size for which we know the maximum cut to conduct experimental analyses.

2 On the maximum cut problem: A new 0.5-approximation algorithm Chapter 2

Preliminaries

As mentioned in the introduction, the maximum cut problem lies in the field of graph theory. In order to properly explain the concepts, theoretical background is needed. In this Chapter, we start by explaining the basics of graph theory, after which we can formally explain the maximum cut problem.

We start by defining some of the fundamental definitions of graph theory, and their consequences.

Definition 2.1. [Simple undirected graph.] A simple undirected graph G = (V,E) is an ordered pair, consisting of a finite set V called the vertex set, and a finite set E called the edge set. Throughout this thesis, we will interchangeably use n and |V | for the cardinality of the vertex set V , and m and |E| for the cardinality of the edge set E. Each element in the edge set is an unordered pair of V × V , which we denote by {u, v}, u, v ∈ V . When there is an edge between vertices u and v, we say that u and v are adjacent. Furthermore, there are no so-called self-loops, meaning that in any edge {u, v}, we always have that u 6= v and between each unordered pair of vertices {u, v}, there can only be one edge at most.

Note that, unless stated otherwise, all graphs G = (V,E) we consider in this thesis are simple undirected graphs. Furthermore, all other following definitions given are to be applied on simple undirected graphs.

Definition 2.2. [Degree.] Given a simple undirected graph G = (V,E), each vertex v ∈ V has a degree, which is defined by the number of vertices that v is adjacent to, and we denote this by d(v).

Definition 2.3. [Neighbourhood of a vertex.] Given a simple undirected graph G = (V,E), we define the neighbourhood of a vertex v by N(v) = {u ∈ V | {u, v} ∈ E}. These are all the vertices that v is incident to. We have that N(v) = d(v) ∀v ∈ V Now, since each edge connects two vertices, we can formulate our first lemma.

Lemma 2.4. Handshaking Lemma. Given a simple undirected graph G = (V,E) with |V | vertices and |E| edges, we have that X d(v) = 2|E| v∈V Meaning that the sum of all degrees in the graph is equal to twice the number of edges in the graph G.

Definition 2.5. [Walk / Path.] A walk in a simple undirected graph G = (V,E) from v0 ∈ V to vk ∈ V is defined as a sequence of vertices (v0, v1, ..., vk−1, vk) such that {vi−1, vi} ∈ E for all i = 1, ..., k. The length of this walk is equal to k. If all vertices in the sequence are distinct, then this is called a path of length k.

On the maximum cut problem: A new 0.5-approximation algorithm 3 CHAPTER 2. PRELIMINARIES

Note that this means that if there is a walk from v0 to vk, then there is also a path and vice versa.

Definition 2.6. [Cycle / Circuit.] A cycle of length k is a walk (v0, v1, ..., vk−1, vk) where v0 = vk, and k ≥ 3. A circuit is a cycle where v1, ..., vk are also distinct. We then call this a circuit of length k.

Definition 2.7. [Connectedness.] A simple undirected graph G = (V,E) is defined to be connec- ted if, between every pair of vertices u, v ∈ V , there exists a path (u, ..., v).

Definition 2.8. [(Bi)Partition]. A partition of the vertex set of a graph G = (V,E) is defined to be a set of subsets V1, ..., Vn ⊆ V for some positive integer n, such that the union of these subsets contains exactly all elements of V . Furthermore, each element of V occurs exactly once in the partition. In other words, the intersection of each subset Vi and Vj, i = 1, ..., n, j = 1, ..., n, i 6= j, is the empty set. When n = 2, this partition is called a bipartition.

Definition 2.9. [.] a simple undirected graph G = (V,E) is called a bipartite graph if V is a bipartition {V1,V2} and E ⊆ {{v1, v2} | v1 ∈ V1, v2 ∈ V2}. If E = {{v1, v2} | v1 ∈ V1, v2 ∈ V2}, so all possible edges between vertices from V1 and vertices from V2 are in the edge set, then the graph is called a complete bipartite graph.

Definition 2.10. [Cut.] In a simple undirected graph G = (V,E), a cut is defined as a bipartition {V1,V2} of the vertex set. An edge {u, v} ∈ E is defined to be crossing the cut if u ∈ V1 and v ∈ V2 or vice versa. The value of a cut is defined to be as the total number of edges crossing the  cut, which is {u, v} | u ∈ V1, v ∈ V2 . When there is no confusing, we also sometimes refer to the bipartition or cut as the subset of edges that cross the cut.

With what we know about basic graphs and cuts, we can define the problem we will be studying in this thesis.

Definition 2.11. [Maximum Cut.] The maximum cut problem is defined as follows: Given a simple undirected graph G = (V,E), find a cut {V1,V2} such that the number of edges crossing the cut is maximal for this graph G.

Now we can start defining slightly more complex elements of graph theory which are used in our own algorithm or algorithms that we will describe in greater detail.

Definition 2.12. [Forest / Tree.] A forest is defined to be a graph G = (V,E) that does not contain any circuits. A tree is defined to be a connected forest, thus a connected graph that does not contain any circuits.

Lemma 2.13. [Tree properties.] If G = (V,E) is a simple undirected graph with n vertices, then the following are equivalent:

1. G is a tree.

2. G has n − 1 edges and is also connected.

3. G has n − 1 edges and does not contain a circuit.

4. Between every pair of vertices in G, there is exactly one path.

Definition 2.14. [Spanning Tree.] Given a simple undirected graph G = (V,E), a spanning tree of G is defined to be T = (V,F ), where F ⊂ E and T is a tree.

Having defined some properties in the field of graph theory, we also need to give some definitions about algorithms, in particular of approximation algorithms.

4 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 2. PRELIMINARIES

Definition 2.15. [Approximation algorithm.] An approximation algorithm for a specific problem (for example the maximum cut problem) is an algorithm that approximates the optimal solution of a given problem instance. The optimal solution of a problem instance (say G) is often given by OPT (G). Definition 2.16. [Approximation ratio.] Given an approximation algorithm A for a given prob- lem, and A(G) the outcome of the algorithm for a specific instance G, the approximation ratio is defined to be inf A(G) . Thus, we take the infimum over all possible instances of simple undirected G OPT (G) graphs.

Some people prefer to flip the ratio, such that e.g. an 0.5-approximation becomes a 2-approximation. Then, instead of maximising the approximation ratio (from e.g. 0.5 to 1). we minimise the ap- proximation ratio (from e.g. 2 to 1). Since these two are both used in existing literature, we explicitly defined our notion of the approximation ratio here. In our context, a 2-approximation ratio would be impossible, since the solution of an instance given by an algorithm can never exceed the optimum value by definition. If the approximation ratio is exactly 1, the algorithm is defined to be an exact algorithm to the problem.

On the maximum cut problem: A new 0.5-approximation algorithm 5

Chapter 3

Previous Contributions

3.1 Exact Algorithms

As described in Chapter 2, an exact algorithm finds the exact solution instead of an approximation of the solution. The trade-off is that currently, all exact algorithms have an exponential running time, meaning that it can take incredibly long to get the exact solution for large inputs.

3.1.1 Brute-Force Approach The first exact algorithm is the most straightforward but also takes the longest. The naive ap- proach is to try out all possible cuts, compute their value, and subsequently return the maximum value found. Since we tried out all possible cuts, we know that the maximum value found is also the maximum cut. In pseudocode:

Algorithm 1 Brute-Force algorithm for finding the maximum cut Precondition: G = (V,E) a simple undirected graph

1: for all possible bipartitions {V1,V2} of V do 2: Compute the value of cut {V1,V2} 3: Update the largest cut found if this value is larger 4: end for 5: return the maximum found cut

This straightforward approach indeed works, but the problem of this approach lies in the first line of the pseudocode: all possible bipartitions. Unfortunately, there are a lot of possible bipartitions. n Given n distinct vertices, we can split this up in 2 different subsets V1 and V2. Furthermore, we are currently dealing with ordered pairs, but we are not interested in the order, so we have to 2n n−1 divide by two. This gives 2 = 2 different bipartitions.

For the rest, the value of a cut can be computed in linear time with respect to the number of edges, and updating the maximum value so far can be done in constant time. This means that we are looking at a running time of O(m2n−1) at best. The reason this algorithm is discussed in this thesis is mainly to provide a natural starting point for the algorithms to come, and also to provide an intuitive upper bound on the running time. If an algorithm somehow performs worse than merely trying out all solutions, then you know that the algorithm under question is not a right approach.

On the maximum cut problem: A new 0.5-approximation algorithm 7 CHAPTER 3. PREVIOUS CONTRIBUTIONS

3.1.2 Approach Using Matrix Multiplication The matrix multiplication constant The next algorithm is also able to find the maximum cut exactly and was first mentioned in [26], as recent as 2004. As the name suggests, this approach relies heavily on matrix multiplication. To be more precise, the fundamental reason why this approach works so well is because of the running time of multiplying an n×n matrix with another n×n matrix, often called square matrix multiplication. As of now, there exists an algorithm that does square matrix multiplication in O(nω) time, where ω < 2.373 [18]. Here, ω is known as the exponent of a matrix multiplication algorithm and is interesting enough to write a whole new Bachelor’s thesis about. The exponent is defined as the smallest constant such two matrices may be multiplied in O(nω+) arithmetic operations, for every  > 0 [4]. The scientific community long thought that there was no better approach than Gaussian Elimination, which takes O(n3) running time. This was the consensus until as recent as 1969 when Volker Strassen published the first algorithm that was asymptotically faster [23], showing that ω < log2(7) ≈ 2.807. Since then, there have been many breakthroughs, improving the bound further and further. This ω-bound has been improved to this new value of 2.373 as recent as 2014. It has been conjectured multiple times [6][5] and is believed by many researchers [25], that the true and final value of ω is equal to two. The reason why square matrix multiplication is so important in this algorithm, is explained in detail in the subsequent Sections.

Finding triangles in a graph An important definition for this approach is the notion of an adjacency matrix, which is a way of how a graph can be represented in matrix form. Definition 3.1. [Adjacency Matrix.] An adjacency matrix is a way to represent a finite graph G = (V,E), and has dimensions |V | × |V |. In the case of a simple undirected graph, entry aij = 1 if there is an edge between vertex vi and vertex vj, and aij = 0 otherwise. In the case of an undirected graph, we have that the adjacency matrix is symmetric, that is, aij = aji for i = 1,... |V |, j = 1,..., |V |. An exciting property of this adjacency matrix lies in its square multiplication. The first time this finding was explicitly mentioned was in 1978 [11].

Theorem 3.2. All triangles in a graph on n vertices can be found in O(nω).

Proof. Let us consider an entry aij in the adjacency matrix A of a simple undirected graph G = (V,E). If aij = 1, then there is a walk of length 1 from vertex vi to vertex vj. Squar- 2 Pn ing the adjacency matrix yields a new matrix B := A , where each entry bik = k=1 aijajk for i = 1, . . . , n. We have that aijajk = 1 if and only if both aij and ajk are equal to one, which means that there must be an edge between vertex vi and vj and there is an edge between vj and vk, which is the same as having a walk of length two between vertex vi and vk. Thus, bik is equal to the number of different walks of length two between vertex vi and vk.

We can extend this even further, we raise the adjacency matrix to the third power. Then, for 3 Pn Pn each entry cil of the new matrix C := A , we have that cil = i=1 j=1 aijajkakl for i = 1, . . . , n and l = 1, . . . , n. This is, in fact, equal to trying all possible walks of length three from vertex vi to vertex vk. Now, aijajkakl is only equal to one if all the three values are equal to one, which is equivalent to having an edge from vi to vj, an edge from vj to vk and an edge from vk to vl, together constituting a walk of length three from vertex vi to vertex vl.

8 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

Let us now consider the diagonal of the matrix C. These are the indices cii, i = 1, . . . , n. As we have shown before, this is equal to the walks of length three, but now the walk must start and end in the same vertex vi, which is defined to be a triangle. There are no other ways to have a walk of length three that also starts and ends in the same vertex. For each triangle, we can start the walk at one of the three vertices, and since we are talking about an undirected graph, we can traverse the walk in both directions. Thus, for each triangle, we have six walks. Dividing the sum of all the diagonal elements of the matrix C by six will give us the total amount of triangles in the graph G = (V,E). For directed graphs, we only have triangles in one direction, so we would only have to divide by three.

Each matrix multiplication takes O(nω) time, so raising the matrix to the third power takes O(nω + nω) = O(nω), and lastly dividing the sum of the diagonal entries of C takes O(n) time, meaning that we can do all this in O(nω). Creating the auxiliary graph We now have an efficient method to find all triangles in a graph, but how can we use this to our advantage to find the maximum cut in a graph? We can achieve this by first creating a so-called auxiliary graph A(G), which is a weighted directed graph.

Definition 3.3. [Weighted directed graph.] A weighted directed graph G = (V,A) is an ordered pair, consisting of a finite set V called the vertex set, and a finite set A called the arc set. Each element in the arc set is an ordered pair of V × V , which we denote by (u, v), u, v ∈ V . We then say that there is an arc going from u to v. Furthermore, there is a weight function w : A −→ R, meaning that each arc gets assigned a real number to be its weight.

So, let us see how to make such an auxiliary graph A(G). For this, the number of vertices in G = (V,E) must be divisible by three. If this is not the case, we can add one or two vertices to the graph, without adding any edges. This does not change the maximum cut in the graph. We then let {V0,V1,V2} be an arbitrary partition of V , where the three sets of the partition all have n size 3 .

n We then create a vertex in the auxiliary graph for every subset of V0. Since there are elements, n 3 there are 2 3 vertices. We then do the same for every subset of V1 and V2, meaning that we have n 3 · 2 3 vertices in the auxiliary graph.

Then, we create the following arcs. We direct arcs from all subsets of V0 to all subsets of V1. There n n n 2n are 2 3 vertices in each set, so this gives us 2 3 · 2 3 = 2 3 arcs. We then also direct arcs from all subsets of V1 to all subsets of V2. Lastly, we also direct arcs from all subsets of V2 to all subsets 2n of V0. This means that we have an auxiliary graph that has 3 · 2 3 arcs.

Lastly, we need to assign weights to each arc. Let X be a subset of the set Vi and let Y be a subset of Vj for i = 0, 1, 2 and j = i + 1 (mod 3). Then, the weight of the arc (X,Y ) is defined as follows:

w(X,Y ) = CUT (X,Vi \ X) + CUT (X,Vj \ Y ) + CUT (Y,Vi \ X) where CUT (U, V ) represents the number of arcs from any vertex u ∈ U to any vertex v ∈ V . More formal,

 CUT (U, V ) = (u, v) | u ∈ U, v ∈ V

On the maximum cut problem: A new 0.5-approximation algorithm 9 CHAPTER 3. PREVIOUS CONTRIBUTIONS

To clarify, let us give an example. Unfortunately, we can only give an example graph consisting of 3 vertices, because we would already have 48 arcs for 6 vertices, which would make things only more confusing. This is already an apparent flaw of the algorithm, which we will discuss later on. Thus, for now, let us take a look at the following graph:

Figure 3.1: Example graph G = (V,E) for matrix multiplication

It is clear that the maximum cut in this graph is the bipartition {{0, 2}, {1}} with a value of 2. Now, we split this graph in a partition of three sets of equal size, so V0 = {0},V1 = {1},V2 = {2}. After that, we get six vertices and create arcs as described above. We then gave all the arcs weights according to the weight function above. The auxiliary graph A(G) looks like this.

Figure 3.2: Auxiliary graph A(G) of the matrix multiplication example graph

A closer look at the weight function Now, let us first take a better look at what the weight function means. As you can see in the graph above, two green triangles have a total weight of two. If we look at the vertices that the triangles pass through, we see that the vertices of the light green triangle yield the vertex {1}, and the vertices of the dark green triangle yield vertices {1, 2}. As we saw before, this was the maximum cut of this graph. Thus, the intuition is that if we can find a triangle that has a certain weight t, then this is equivalent to finding a cut {V1, V2} of value t. To formalise:

Claim: The following two statements are equivalent: 1. There exists a cut {X,V \ X} in the graph G = (V,E) such that its value is equal to t.

2. The auxiliary graph A(G) contains a directed triangle with vertices X0,X1,X2 with X0 ⊆ V0, X1 ⊆ V1 and X2 ⊆ V2, such that the weights of the arcs sum up to t.

10 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

Proof of claim: We first prove 1 =⇒ 2. Assume there exists such a cut {X,V \ X} in G with a value equal to t. We now take X0 ∈ A(G) as the first vertex of the triangle to be X ∩ V0, X1 ∈ A(G) as the second vertex to be X ∩ V1 and X2 ∈ A(G) as the third vertex to be X ∩ V2. Because X,V \ X was a bipartition, all vertices occur exactly once, and thus we also know that X0,X1 and X2 are disjoint. Furthermore, X0 ⊆ V0, X1 ⊆ V1 and X2 ⊆ V2 by construction, thus they all will be vertices in the auxiliary graph. Again, by construction, we know that (X0,X1), (X1,X2) and (X2,X0) are arcs. We get that their sum is equivalent to:

w(X0,X1) + w(X1,X2) + w(X2,X0) = CUT (X0,V0 \ X0) + CUT (X0,V1 \ X1) + CUT (X1,V0 \ X0)

+ CUT (X1,V1 \ X1) + CUT (X1,V2 \ X2) + CUT (X2,V1 \ X1)

+ CUT (X2,V2 \ X2) + CUT (X2,V0 \ X0) + CUT (X0,V2 \ X2)

= CUT (X0,V0 \ X0) + CUT (X0,V1 \ X1) + CUT (X0,V2 \ X2)

+ CUT (X1,V0 \ X0) + CUT (X1,V1 \ X1) + CUT (X1,V2 \ X2)

+ CUT (X2,V0 \ X0) + CUT (X2,V1 \ X1) + CUT (X2,V2 \ X2)   = CUT X0, (V0 \ X0) ∪ (V1 \ X1) ∪ (V2 \ X2)   + CUT X1, (V0 \ X0) ∪ (V1 \ X1) ∪ (V2 \ X2)   + CUT X2, (V0 \ X0) ∪ (V1 \ X1) ∪ (V2 \ X2)   = CUT X0 ∪ X1 ∪ X2, (V0 ∪ V1 ∪ V2) \ (X0 ∪ X1 ∪ X2)   = CUT (X ∩ V0) ∪ (X ∩ V1) ∪ (X ∩ V2),V \ X)   = CUT X ∩ (V0 ∪ V1 ∪ V2),V \ X) = CUT (X ∩ V,V \ X) = CUT (X,V \ X) = t

To prove 1 ⇐= 2, assume the auxiliary graph has a triangle X0,X1,X2, where X0 ⊆ V0,X1 ⊆ V1,X2 ⊆ V2. Furthermore, the sum of the weights of the triangles is equal to t, that is, w(X0,X1)+ w(X1,X2) + w(X2,X0) = t. Now, we again have that X0,X1 and X2 are disjoint. Now, let us define X = X0 ∪ X1 ∪ X2. Clearly, X ⊆ V by assumption. We now show that there exists a cut of value t. By the same reasoning above, we have that

w(X0,X1) + w(X1,X2) + w(X2,X0) = CUT (X0 ∪ X1 ∪ X2,V \ X) = CUT (X,V \ X) = t which proves that, given a cut {X,V \ X}, we can find a triangle in the auxiliary graph A(G) such that the weights of the edges of the triangle together sum up to the value of the cut.

 Finding a triangle of maximum weight Thus, we can finally see now why it was important to be able to quickly find triangles in the graph. After this, all that remains is finding the triangle that has the maximum weight in the auxiliary graph A(G). If you assign labels to the vertices, for example as is done in 3.2, you can also quickly get which cut gives this maximum value. Unfortunately, finding a triangle of maximum weight in a directed weighted graph is also quite a hard problem. There are algorithms that can solve ω n ωn this in O(n ) [7], but now we have 3 · 2 3 vertices, meaning that it would take O(n 3 ). However, this algorithm is quite complicated, and there is another way to achieve this with simpler methods.

The problem is that we can find all triangles of the auxiliary graph A(G) by looking at the trace of the adjacency matrix raised to the third power, which we described before, but we do not know

On the maximum cut problem: A new 0.5-approximation algorithm 11 CHAPTER 3. PREVIOUS CONTRIBUTIONS where the triangle of maximum weight is. However, if we make sure that there are only triangles of a certain value t by leaving out certain arcs in the auxiliary graph. Then, we would know that there is a triangle of value t (and thus a cut of value t) if we then find a triangle, since there we constructed the graph such that there are only triangles of that size.

Unfortunately, it is not the case that, given a desired value t for the sum of the weights of a tri- angle, you can only take the arcs that together constitute such triangles. If you, for example, have the desired weight of 10, you can achieve this by a lot of different ways of adding three numbers. 1 + 1 + 8, 1 + 2 + 7, 1 + 3 + 6, etc. So, what we also need to do, is for every desired value t to check all different ways of adding three numbers to get t. To reiterate, we get for each t all possible 3 triples W = (w01, w12, w20) such that w01 + w12 + w20 = t. There are at most t triples for each t, since the weights are only natural numbers. Now that we have such a triplet, we take the original auxiliary graph A(G) and we only allow the following weight. For each arc going from X0, a subset of V0, to X1, a subset of V1, we only allow arcs of weight w01. For each arc going from X1 to X2, we only allow arcs of weight w12, and for each arc going from X2 to X0, we only allow arcs of weight w02. If we now run the algorithm for finding triangles on this modified auxiliary graph A(G, W ) and we find a triangle, then we know that this triangle must have a value t. If we do this for all values of 0 ≤ t ≤ |E|, we know that we have tried all possible combinations and all possible arcs, and thus also all triangles. We then return the maximum value found and its corresponding labels.

To give a last example, consider again the example of figure 3.1 and its auxiliary graph, given in figure 3.2. Let us attempt to find a cut of value t = 1. To do this, we need to split this t into a triple W = (w01, w12, w20). For example, let us take (0, 1, 0). This means that from the vertices that represent subsets of V0 or V2, we only take outgoing arcs with weight 0. For vertices that represent subsets of V1, we only take outgoing arcs of weight 1. This gives us a modified auxiliary graph, which is given in figure 3.3.

Figure 3.3: Modified auxiliary graph A(G, W ) with W = (0, 1, 0)

If we look at the auxiliary graph, we can only see two triangles, and for both triangles, it holds that its value is w01 +w12 +w20 = 0+1+0 = 1 by construction. On this auxiliary graph A(G, W )

12 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS we can check for triangles, and if we find a triangle we can immediately conclude there is a cut of value 1. If we do this for all triples of all values up to and including the maximum possible value |E|, we know that we will find the maximum cut in a systematic way.

Running time and Memory usage As you might expect, the creation of the auxiliary graph is the bottleneck of this algorithm, in the n sense that this creation of the auxiliary graph takes a long time. Since we have O(2 3 ) vertices 2n n 2n and O(2 3 ) arcs, we know that the creation of this auxiliary graph takes O(2 3 + 2 3 ) in running time. On top of that, we also have to check for triangles in this graph. Given that the auxiliary n n ω ωn ω n n graph has 3 · 2 3 nodes, finding triangles takes O((2 3 ) ) = O(2 3 ) = O((2 3 ) ) < O(1.731 ). Furthermore, we have to check for all possible triples from 1 up to |E|. The total amount of triples P|E| 3 does not grow exponentially, but is at most i=1 i . So, if we only take factors into account that ωn n contribute to the exponential running time, we get a final running time of O(2 3 ) < O(1.731 ).

We can see that this is clearly an improvement with respect to the brute force approach. Although we are talking about asymptotic running times, it does not hurt to mention that for n = 50, 250 is over 1.400 times larger than 1.73150, which is a huge difference.

Although the algorithm has a significantly better running time, it does have a drawback compared to the brute force approach. Albeit that the running time is better, it performs much worse with respect to another resource, memory. As we have seen in the example for matrix multiplication, we saw that the auxiliary graph grew exponentially with respect to the original vertices and edges. Even a graph on just thirty vertices will yield an auxiliary graph on 3072 vertices and over nine mil- lion arcs! This enormous auxiliary graph also needs to be stored. Thus, we see that this algorithm 2n requires at least O(2 3 ) memory space. The big problem with memory space in comparison to time is that you simply cannot run the algorithm if you do not have enough memory. The memory will overflow and the algorithm will not be able to produce any meaningful output. An algorithm that has a long running time, on the other hand, is less of a problem than an algorithm that takes up too much memory. You can simply wait, albeit for quite a long time, but the algorithm will still be able to produce a meaningful output whereas the algorithm can never give useful output if it does not have enough memory.

On the maximum cut problem: A new 0.5-approximation algorithm 13 CHAPTER 3. PREVIOUS CONTRIBUTIONS

3.2 Approximation Algorithms

As mentioned before, in Section 1.2, the maximum cut problem was shown to be NP-Hard, meaning that our best exact solution runs in exponential time. As a result, the focus of many researchers interested in Max-Cut has shifted to approximation algorithms. These algorithms generally run in polynomial time but do not provide the optimal solution with certainty. Thus, we have a trade-off between the running time of the algorithms and how close the output of the algorithm is to the optimal output, which is often denoted by the approximation ratio. In this section, we first take a look at a straightforward approach with the lowest approximation ratio of this section. After that, we take a look at algorithms with better approximation ratios, but as mentioned before, the algorithms get increasingly more complicated to achieve a better approximation ratio.

3.2.1 Random Approach The first approximation algorithm is also the simplest one, relying on randomness. Perhaps the most intuitive random approach is to randomly assign vertices to one of the two sets of the bipartition. Here, randomly means that the vertex is sent to either one of the two sets of the bipartition with equal probability as if a coin toss determines the assignment of the vertex. In pseudocode,

Algorithm 2 Random approach for approximating the maximum cut Precondition: G = (V,E) a simple undirected graph

1: V1 ←− ∅ 2: V2 ←− ∅ 3: for all vertices v ∈ V do 4: assign v uniformly at random to either V1 or V2 5: end for 6: return the bipartition {V1,V2}

From the pseudocode, we can conclude that this algorithm runs in O(n), since the algorithm loops over all n vertices, and assigns each vertex in constant time to either one of the two sets.

Now, the most important question regarding this approach is: how well does the algorithm per- form? To derive the approximation ratio, we first require some new notation. Let A(G) denote the edges in the cut outputted by the random algorithm for a given graph G = (V,E). Furthermore, let I{u,v} denote the random variable, which is equal to 1 if {u, v} ∈ A(G), and 0 otherwise. Then,

  h X i E |A(G)| = E I{u,v} {u,v}∈E X = E[I{u,v}] {u,v}∈E X = Pr (I{u,v} = 1) {u,v}∈E

Analysing Pr (I{u,v} = 1), we can consider four different cases. In the first case, u and v are both 1 1 1 in V1. The probability that this occurs is equal to 2 · 2 = 4 . Analogously, the probability that u 1 and v are both in V2 is equal to 4 , and the probability of having u and v in different sets is equal 1 to 2 , because there are two ways to do so with equal probability. These are all possible outcomes, 1 1 and we see that there {u, v} ∈ A(G) with probability 2 , meaning that Pr (I{u,v} = 1) = 2 .

14 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

This leaves us to conclude that

X |E| |A(G)| = Pr (I = 1) = E {u,v} 2 {u,v}∈E

Since OPT (G) ≤ |E|, we can derive that the approximation ratio is

    |E| E |A(G)| E |A(G)| 1 ≥ = 2 = OPT (G) |E| |E| 2

1 So we know that the approximation ratio of this randomised algorithm is equal to 2 .

3.2.2 Greedy Approach We have seen that there is a basic randomised algorithm that can already achieve an approxima- 1 tion ratio of 2 . The question arises what would happen to the approximation ratio if we choose a more sophisticated way of finding a cut. One of those more sophisticated ways is a so-called greedy approach, where each vertex is assigned either one of the two sets in the bipartition that seems to be the best fit at that moment.

So as described above, each vertex is assigned to the set that at that moment in time would maximise the number of edges added to the cut. The set that would be the best fit for a given vertex is the set with which the vertex has the least number of vertices incident. If a vertex v has the least number of edges in common with vertices in V1, then we know that v has more edges in common with vertices in V2, meaning that we gain more edges in the maximum cut if we assign the vertex to V1. Again, let I{u,v} denote a random variable, which is equal to 1 if {u, v} ∈ E, and 0 otherwise. Here A(G) is the greedy algorithm applied on an undirected graph G = (V,E). In pseudocode,

Algorithm 3 Greedy approach for approximating the maximum cut Precondition: G = (V,E) a simple undirected graph

1: V1 ←− ∅ 2: V2 ←− ∅ 3: for all vertices v ∈ V do 4: if P I ≥ P I then u∈V2 {u,v} u∈V1 {u,v} 5: V1 ←− V1 ∪ {v} 6: else 7: V2 ←− V2 ∪ {v} 8: end if 9: end for 10: return the bipartition {V1,V2}

We see that this algorithm is still easy to grasp. In the pseudocode, over all the vertices are looped, and we count for each vertex v all edges that v is incident to. By the handshaking Lemma, we know that we have iterated over each edge twice. Thus, we have a running time of O(m).

On the maximum cut problem: A new 0.5-approximation algorithm 15 CHAPTER 3. PREVIOUS CONTRIBUTIONS

Furthermore, we see that at each iteration, for a fixed v ∈ V ,

   {u, v} | u ∈ V1, v ∈ V2 ≥ {u, v} | u ∈ V1, v ∈ V1 + {u, v} | u ∈ V2, v ∈ V2 . This also holds after the final iteration and also upon the termination of the for loop. Furthermore, it also holds upon the termination of the for loop that

   |E| = {u, v} | u ∈ V1, v ∈ V2 + {u, v} | u ∈ V1, v ∈ V1 + {u, v} | u ∈ V2, v ∈ V2 . From this, we can conclude that

   |E| = {u, v} | u ∈ V1, v ∈ V2 + {u, v} | u ∈ V1, v ∈ V1 + {u, v} | u ∈ V2, v ∈ V2

  ≤ {u, v} | u ∈ V1, v ∈ V2 + {u, v} | u ∈ V1, v ∈ V2

 = 2 {u, v} | u ∈ V1, v ∈ V2 . Consequently, we have

|E| OPT (G) A(G) = {u, v} | u ∈ V , v ∈ V ≥ ≥ . 1 2 2 2 1 From this, we can conclude that this greedy algorithm also has an approximation ratio of 2 .

3.2.3 Local Search Approach We can further improve the greedy algorithm described in Section 3.2.2. One flaw of this greedy algorithm is that assigning the first few vertices to either V1 and V2 is not done in a sophisticated way. In fact, the very first vertex is always assigned to V1 since both V1 and V2 are still empty. We can improve this. Instead of terminating the algorithm after we assigned each vertex, we keep moving vertices as long as the maximum cut strictly improves. Since the maximum cut is at most |E|, we know that the algorithm terminates after at most |E| iterations. Since we keep iterating over all vertices until no improvements can be found, we can also initialise V1 and V2 such that all vertices have already been assigned to exactly one of the two sets. To keep the algorithm deterministic, meaning that the algorithm always returns the same cut for the same graph, we initialise V1 as the complete vertex set and V2 as the empty set. In pseudo code,

Algorithm 4 Local Search approach for approximating the maximum cut Precondition: G = (V,E) a simple undirected graph

1: V1 ←− V 2: V2 ←− ∅ 3: while There exists a vertex v ∈ V such that shifting v improves the cut value do 4: if v ∈ V1 and |N(v) ∩ V1| > |N(v) ∩ V2| then 5: V1 ←− V1 \{v} 6: V2 ←− V2 ∪ {v} 7: else if v ∈ V2 and |N(v) ∩ V1| < |N(v) ∩ V2| then 8: V1 ←− V1 ∪ {v} 9: V2 ←− V2 \{v} 10: end if 11: end while 12: return the bipartition {V1,V2}

16 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

So we see that the algorithm keeps switching vertices from V1 to V2 or the other way around until there does not exist a vertex anymore that improves the cut value by shifting the vertex. Since the maximum cut value is at most |E|, we know that the algorithm terminates after at most |E| iterations. Checking whether there exists a vertex v such that shifting v improves the cut value can be done in O(n) time, meaning that the algorithm has a running time of O(mn).

What would the approximation ratio of this local search approach be? Given that the greedy 1 approach has an approximation ratio of at least 2 , and local search seems to have a ‘more soph- isticated’ way of computing a cut, we would hypothesise that the local search approach has an 1 approximation ratio of at least 2 , if not better. So, let us attempt to compute the approximation ratio of the local search algorithm. Here, we define A(G) as the outcome produced by the local search algorithm on a simple undirected graph G = (V,E).

Important to see is that, upon the termination of the algorithm, there are no vertices that can be shifted such that the cut value improves. Thus, we know that for each vertex, it holds that at least half of its neighbours are in the other set. If this would not have been the case, then we could have shifted this vertex to improve the cut value, which would be a contradiction. Thus,

∀ v ∈ V1 : |N(v)| ≤ 2 {{u, v} | {u, v} ∈ E ∧ u ∈ V2}

∀ v ∈ V2 : |N(v)| ≤ 2 {{u, v} | {u, v} ∈ E ∧ u ∈ V1}

So if we sum over all the vertices in V , we have that

P d(v) |E| = v∈V 2 P |N(v)| = v∈V 2 P |N(v)| + P |N(v)| = v∈V1 v∈V2 2 P P 2 {{u, v} | {u, v} ∈ E ∧ u ∈ V2} + 2 {{u, v} | {u, v} ∈ E ∧ u ∈ V1} ≤ v∈V1 v∈V2 2 = 2|A(G)|

|A(G)| |A(G)| 1 1 And thus, we have that |E| ≥ 2|A(G)| = 2 , meaning that we have a 2 -approximation. Now, 1 the question is whether this local search algorithm has a better approximation ratio than 2 ? Unfortunately, this is not the case. To see this is not the case, let us consider an undirected graph G = (V,E), that acts as a counterexample. The local search approach always returns only half of the edges of the maximum cut value, meaning that the approximation ratio is not strictly better 1 than 2 . So, let us consider the complete bipartite graph G = (V,E), where V = {A, B} and |A| = |B| = 2n, which is often denoted by K2n,2n. Initially, we would have the cut {V, ∅}. Now, suppose that we alternatingly shift vertices from A and B to the other set of the partition. For a vertex v of A, we have after 2ith iterations that |N(v) ∩ V1 = 2n − i > i = |N(v) ∩ V2|, which holds for until the 2nth iteration. Analogously for a vertex v of B, we have after the 2i + 1th iteration that |N(v) ∩ V1| = 2n − i > i = |N(v) ∩ V2, which also holds until the 2nth iteration. Thus, after 2n iterations, we have 2n vertices in each set of the bipartition; n from A, and n from B.

Let A1 = A ∩ V1, A2 = A ∩ V2, B1 = B ∩ V1, and B2. Thus, after 2n iterations, we can have the cut {A1 ∪ B1,A2 ∪ B2}, which is depicted in figure 3.4. Here, the green edges represent edges the will be in the cut, and the red edges represent edges that will not be in the cut.

On the maximum cut problem: A new 0.5-approximation algorithm 17 CHAPTER 3. PREVIOUS CONTRIBUTIONS

Figure 3.4: Possible final cut of the local search approach

For each vertex v ∈ A1, we have that v is incident with n vertices in B1 and with n vertices in B2. Thus, no vertex from A1 can be shifted such that the cut value improved. This holds analogously for all vertices in A2, B1, and B2 and thus for all vertices. This means that local search terminates, and thus the cut returned is {A1 ∪ B1,A2 ∪ B2}.

Looking at the value of the cut {A1 ∪ B1,A2 ∪ B2}, we see that we have every vertex in A1 is incident with n vertices in B2, and every vertex in A2 is incident with n vertices in B1. Since A1 2 and A2 both have n vertices, the total number of vertices in the cut is 2n . Now, the total number of edges in the graph is 4n2, since each vertex from A is incident with every vertex in B, and thus the total number of edges is |A||B| = 4n2. Furthermore, we have that the value of the maximum cut is also 4n2, when we have the cut {A, B}. From this, we can conclude that the ratio of vertices 2n2 1 in the cut is 4n2 = 2 , and thus we see that there is an instance and an order of the vertices such that the algorithm returns a cut with only half the number of edges of the maximum cut. Thus, 1 the algorithm does not have a better approximation ratio than 2 .

The main takeaway of this is that although the greedy approach and the local search approach have a significantly more sophisticated strategy of forming a cut than the random approach, the approximation ratio is not even better. Let us see another approach that is much more difficult and requires much more mathematical knowledge.

3.2.4 Linear Algebra Approach [24] We have seen that the previous three approximation algorithms have gotten increasingly more complicated, without increasing the approximation ratio. In this Section, we discuss an algorithm developed by Trevisan, which he published in [24], in 2009. The algorithm utilises a complex field of mathematics called spectral partitioning. In short, spectral partitioning means finding a partition using spectral methods. These spectral methods require analysing the eigenvalues and eigenvectors of matrices. As mentioned in Section 3.1.2, we can describe a graph using a matrix, for example an adjacency matrix. On these matrices, we can apply theory from linear algebra, such as finding eigenvalues, decompositions of the matrix, and other tools that helped Trevisan develop his algorithm. In the following Section, we briefly explain what strategy Trevisan utilised, after which we derive the approximation ratio of the algorithm, for which we used [24], [27] and [28] as our sources.

18 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

One call of the recursive algorithm There is one main reason why Trevisan’s algorithm works, and that is because the algorithm uses spectral partitioning to find a good partition {L, R} of S ⊂ V of a given graph G = (V,E). Note that this is not a partition of the full vertex set V . Let ALG(G) be the size of the cut outputted by the algorithm on a graph G = (V,E). In one call of the algorithm, the algorithm finds a partition {L, R} of S ⊂ V . We do, however, require a bipartition of the full vertex set. For this, we recursively apply the algorithm on the remaining vertices V \ S. A visualisation of this process is given in Figure 3.5.

Figure 3.5: A visualisation of two recursive calls of Trevisan’s algorithm

Edges added in one recursive call of the algorithm So, seeing how the algorithm gets its partition from a general perspective, to analyse the approx- imation ratio, we need to see how many edges are added in one such recursive call. We have three types of edges that are in the cut computed by the algorithm: 1. First of all, we have that all edges between L and R will be in the cut, which we denote by δ(L, R). 2. Secondly, we have not counted any edges {u, v}, u, v ∈ V \ S. On this set, we will call our algorithm recursively. Thus the number of edges that will be in the cut is equal to ALGG0 = (V \ S, E0), where E0 is the subset of all edges of E between the vertices of V \ S.

3. Lastly, there are also edges between vertices S and V \ S, but how many of those are in the cut? Trevisan showed that the algorithm is always capable of creating a cut such that at least half of the edges between S and V \ S are included in the cut. We denote this by 1 2 δ(S, V \ S). In total, this yields the recursive formula 1 ALG(G) ≥ |δ(L, R)| + |δ(S, V \ S)| + ALGG0 = (V \ S, E0) 2

On the maximum cut problem: A new 0.5-approximation algorithm 19 CHAPTER 3. PREVIOUS CONTRIBUTIONS

Edges in the optimal cut To compute the approximation ratio, we also need to have an upper bound on the value of the maximum cut. We can define OPT (G) in the maximum cut by the following types:

1. All the edges that have both endpoints in L, which we denote by E(L).

2. All the edges that have both endpoints in R, which we denote by E(R).

3. All edges with one endpoint in L, and one endpoint in R, which we denote by δ(L, R).

4. All edges with one endpoint in {L ∪ R} = S, and one endpoint in V \ S, which we denote by δ(S, V \ S).

5. All edges that have both endpoints in V \S, which is upper bounded by OPT (G0 = (V \S, E).

In total, this yields the recursive formula

OPT (G) ≤ |E(L)| + |E(R)| + |δ(L, R)| + |δ(S, V \ S)| + OPT G0 = (V \ S, E)

Lower bounding the approximation ratio To compute the approximation ratio, let us solve the recursive formula for

ALG(G) |δ(L, R)| + 1 |δ(S, V \ S)| + ALGG0 = (V \ S, E) ≥ 2 OPT (G) |E(L)| + |E(R)| + |δ(L, R)| + |δ(S, V \ S)| + OPT G0 = (V \ S, E)

We can rewrite this recursive formula to

ALG(G) n |δ(L, R)| + 1 |δ(S, V \ S)| ALG(G0) o ≥ min 2 , OPT (G) |E(L)| + |E(R)| + |δ(L, R)| + |δ(S, V \ S)| OPT (G0)

Now, this is where Trevisan’s analyses in spectral partitioning can be applied. Using theory from linear algebra which unfortunately is beyond the scope of this Bachelor’s thesis, Trevisan showed that

ALG(G) n √ 1 o ≥ min 1 − 2 , , OPT (G) 2(1 − ) where  is a nonnegative real number. The two functions are graphed in Figure 3.6, and we see that the minimum of the two functions attains the maximum value of 0.529 at  ≈ 0.056. From this, we can conclude that the approximation ratio of Trevisan’s algorithm is indeed 0.529. Later research improved on the approximation bound, first to 0.531 by Trevisan himself in [24] and then to 0.614 by Soto in [22].

20 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

Figure 3.6: Graph visualising the approximation ratio of Trevisan’s algorithm using Desmos

The main conclusion we can draw from this section is that, to significantly improve the approxima- tion ratio of an algorithm, much more complicated mathematical theory is required. As mentioned 1 before in Section 3.2.1, we can achieve an approximation ratio of 2 by randomly assigning the vertices to either set of the bipartition. This substantial increase in required mathematical under- standing seems to outweigh the slight 0.029 increase of the approximation heavily. As mentioned before, this was one of the reasons for writing this Bachelor’s thesis, are we able to come up with 1 a straightforward algorithm with an approximation ratio better than 2 ? We discuss this question in greater detail in the next chapters of this Bachelor’s thesis.

3.2.5 Semi-Definite Programming Approach [9] The next approach was undoubtedly the most significant breakthrough in approximating the max- imum cut. Trevisan’s algorithm described in the previous Section was much more complicated than the randomised approach but improved the outcome only by a small factor. In 1995, Goe- mans and Williamson published a paper in which they present their approach [9]. They managed 1 to improve the best approximation ratio from 2 to a staggering 0.87856.

From the maximum cut problem to an integer quadratic program So what was the secret that allowed Goemans and Williamson to come up with an algorithm so much better than all other algorithms out there? They decided to translate the problem of finding the maximum cut to another problem, a so-called integer quadratic program. The corresponding integer quadratic program for finding a maximum cut is

1 X Maximise: (1 − y y ) (3.1) 2 i j {i,j}∈E

Subject to: yi ∈ {−1, 1} ∀ i ∈ V (3.2)

In simpler terms, for each vertex i in the graph, we assign a value of either −1 or 1 to the corres- ponding variable yi. We do this such that the sum of (3.1) is maximised. It might look abstract, but assigning the value −1 to y1 only means that we put the vertex 1 in the first set of the parti- tion, and in the second set of the partition if the value if 1. So, we have that the first set of the partition V1 = {i | yi = 1} and the other set of the partition V2 = {i | yi = −1}.

On the maximum cut problem: A new 0.5-approximation algorithm 21 CHAPTER 3. PREVIOUS CONTRIBUTIONS

Let us now consider (3.1), the function to maximise. We iterate over all edges {i, j} in the graph. We have that 1 − yiyj = 0 if and only if yi and yj have the same value, meaning that vertices i and j are in the same set of the cut. If they are in different sets of the cut, however, then we have that 1 − yiyj = 2. So, all edges that have the vertices in different sets of the cut contribute to (3.1) with value 2, and the other edges contribute to (3.1) with value 0. Then, multiplying by 1 2 means that each edge that crosses the cut contributes with value 1, and all other edges do not contribute to the sum. Thus, (3.1) maximises the total number of edges that cross the cut.

From an integer quadratic program to a linear program Now, we have that (3.1) indeed tries to maximise the number of edges in the cut, and the para- meter yi indicates to which set of the cut vertex i is assigned. We have translated the problem from finding a maximum cut to solving this integer quadratic program.

Unfortunately, solving integer quadratic programs has been proven to be NP-complete in [21], and thus, it does not seem that this translation helps us much further. Fortunately, the integer quadratic program can be more easily rewritten than the maximum cut problem. We can do this by relaxing the constraints of (3.2). Our approach is to transform the integer quadratic program into a linear program. For this, we (perhaps counter-intuitively) increase the dimension space of n 2 yi. Instead of stating that yi ∈ {−1, 1}, we now require that vi ∈ R and kvik = 1, where n is the number of vertices in the graph G = (V,E). This essentially means that all vi need to be n-dimensional vectors of unit distance. In other words, we required vi to be on the n-dimensional unit sphere, which we will by Sn. We also need to change the function to maximise, because we have to define how we multiply two vectors vi and vj. For this, we use the dot product. The relaxed integer quadratic program is now the following linear program:

1 X Maximise: (1 − v · v ) (3.3) 2 i j {i,j}∈E

Subject to: vi ∈ Sn ∀ i ∈ V. (3.4)

2 By definition of the dot product, we have that (3.4) is equivalent to vi · vi = kvik = 1. Now, let us define P = (pij)ij = (vi · vj)ij be the n × n matrix, where each value is the corresponding dot product. This type of matrix is also known as the Gram matrix, named after Jørgen Pedersen Gram.

From a linear program to a semidefinite program Although it might not be evident at first, this matrix turns out to be positive semidefinite, which has powerful consequences. Before we continue, let us first define what a positive semidefinite matrix is.

Definition 3.4. [Positive semidefinite matrix] A symmetric matrix A is positive semidefinite (PSD) if and only if xT Ax ≥ 0 for all x ∈ Rn.

We first show that P is a symmetric matrix. That is, pij = pji. Let 1 ≤ i ≤ n, 1 ≤ j ≤ n, then

pij = vi · vj = vj · vi = pji, and thus we have that P is a symmetric matrix. Another remark is that we can write P as V T V , where V = [v1 v2 . . . vn−1 vn], so simply all vectors written in ascending order. Then, we have that

22 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

 T    v1 v1 · v1 v1 · v2 . . . v1 · vn−1 v1 · vn T  v2   v2 · v1 v2 · v2 . . . v2 · vn−1 v2 · vn      T  .     ......  V V =  .  v1 v2 . . . vn−1 vn =  . . . . .  = P  T    vn−1 vn−1 · v1 vn−1 · v2 . . . vn−1 · vn−1 vn−1 · vn T vn vn · v1 vn · v2 . . . vn · vn−1 vn · vn

Now, let x ∈ Rn. We then have that

xT P x = xT V T V x = (V x)T (V x) = kV xk2 ≥ 0 and thus, P is positive semidefinite. This means that (3.3) is in fact a so-called semidefinite program. The wonderful property of positive semidefinite matrices is that there exist efficient methods to solve semidefinite programs. These methods are outside of the scope of this Bachelor’s thesis; the most important aspect of these methods is that they run in polynomial time.

From a semidefinite program solution to a solution of the maximum cut problem So, we can solve (3.3) using state of the art algorithms for solving semidefinite programs, and we get an optimal set of these vectors vi ∈ Sn. We now need to translate this back to the maximum cut problem.

For this, we pick a random hyperplane that goes through the origin. Then, all vertices repres- enting vectors vi on one side of the hyperplane are in one set of the bipartition, and all vertices represented by vectors vi on the other side of the hyperplane are in the other set of the bipartition. In simpler words, we cut the ball Sn precisely in half, thereby going through the centre. Then, all vertices represented by vectors that are in the first half of the cut will be in the first set of the bipartition. The other vertices will be in the other set of the bipartition.

The approximation ratio Now that we know how the algorithm works, we can ask the most important question of all: what is the approximation ratio of this algorithm? We first require some more insight into the nature of the algorithm to answer this important question.

arccos (vi·vj ) Lemma 3.5. The probability of an edge {vi, vj} being in the maximum cut is equal to π . Proof. We first formalise the notion of “being on one side of the hyperplane". This hyperplane has a normal vector of unit length, which we denote by r. If a vector vi is “below" the hyperplane, then it has a negative inner product with the normal vector of the hyperplane. Thus, the cut consists of  {vi | vi · r < 0}, {vi | vi · r ≥ 0} This allows us to rewrite the probability of an edge being in the maximum cut to

Pr ({vi, vj} in the cut) = Pr (sgn(vi · r) 6= sgn(vj · r)), which is easier to analyse. We also see by symmetry that

Pr (sgn(vi · r) 6= sgn(vj · r)) = Pr (vi · r < 0 and vj · r ≥ 0) + Pr (vi · r ≥ 0 and vj · r < 0)

= 2 Pr (vi · r ≥ 0 and vj · r < 0). We analyse this probability using geometry and checking all possible events with respect to r. Interestingly, we have that the hyperplane separates the vectors vi and vj if the hyperplane inter- sects the volume between the two vectors. In the three-dimensional case, this volume is called a lume and is visualised in figure 3.7. Here, θ is the angle between the two vectors projected on the y = 0 plane.

On the maximum cut problem: A new 0.5-approximation algorithm 23 CHAPTER 3. PREVIOUS CONTRIBUTIONS

Figure 3.7: Visualisation of the area between two vectors vi and vj

The convenience of this geometric approach is that the probability that the hyperplane intersects the light blue volume is equivalent to the ratio of the volume of the lume to the total volume. θ This ratio is equal to 2π .

Given that θ is the angle between the two vectors, projected on the y = 0 plane, we know that θ = arccos (vi · vj). This leaves us to conclude that

θ arccos (v · v ) Pr ({v , v } in the cut) = 2 · = i j i j 2π π

arccos (vi·vj )  2 θ  1−vi·vj Lemma 3.6. π ≥ min0≤θ≤π π 1−cos(θ) · 2

Proof. We change the variable vi · vj to cos(θ) to make the derivation easier to follow, this yields

arccos (cos(θ)) θ = π π θ 1 − cos(θ) = 1 − cos(θ) π  θ 1 − cos(θ) ≥ min 0≤θ≤π 1 − cos(θ) π  2 θ  1 − cos(θ) = min · 0≤θ≤π π 1 − cos(θ) 2 1 − v · v = α · i j , 2 where  2 θ  α := min > 0.87856. 0≤θ≤π π 1 − cos(θ)

2 θ To see that α is indeed greater than 0.87856, we look at the plot of π 1−cos(θ) from θ = 0 to θ = π, which is given in figure 3.8.

24 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

2 θ Figure 3.8: Plot of π 1−cos(θ) from θ = 0 to θ = π, using Desmos

We can indeed see that the minimum is attained at θ ≈ 2.331 and that this minimum is indeed greater than 0.87856. Theorem 3.3. The approximation ratio of Goemans’ and Williamson’s algorithm is equal to α. Proof. Using Lemmas 3.5 and 3.6, we can derive the approximation ratio of the algorithm of Goemans and Williamson. Let C be the cut that is computed by the algorithm. The expected value of this cut is equal to

X E[|C|] = Pr ({i, j} ∈ C) {i,j}∈E

3.5 X arccos (vi · vj) = π {i,j}∈E

3.6 X 1 − vi · vj ≥ α . 2 {i,j}∈E

We now refer back to the maximisation function (3.3). If we look at the expected value of the cut over the value of the maximum cut, we get

1 P 2 {i,j}∈E 1 − vi · vj α 1 P = α. 2 {i,j}∈E 1 − vi · vj This leaves us to conclude that the approximation ratio is indeed α, which is greater than 0.87856.

On the maximum cut problem: A new 0.5-approximation algorithm 25 CHAPTER 3. PREVIOUS CONTRIBUTIONS

3.3 A minimum cut algorithm: Karger’s algorithm

Although the main priority of this Bachelor’s thesis is the maximum cut problem, we also shed light on its counterpart: the minimum cut problem. It is defined as follows: Definition 3.7. [Minimum Cut] Given a simple undirected graph G = (V,E), we want to find the partition {V1,V2} of V such that {{u, v} ∈ E : u ∈ V1, v ∈ V2} is minimised. The minimum cut problem is very comparable to the maximum cut problem. Where maximising was the goal in the maximum cut problem, our goal is now to minimise the value of the cut. Interestingly, the minimum cut is a problem that is not NP-complete, and can easily be solved in polynomial time. One way of solving the minimum cut problem in polynomial time was presented by Ford and Fulkerson in 1952 [20]. Another interesting algorithm for solving the minimum cut is Karger’s algorithm, which he published in 1992 [13]. Karger’s algorithm is a so-called randomised algorithm. Running the algorithm twice on the same input will most likely lead to two different results, due to the randomness of the algorithm. However, the strength of the algorithm lies in the fact that it is simple to understand and can be repeated multiple times. For the algorithm, we require some additional definitions from graph theory. Definition 3.8. [Undirected Multigraph.] An Undirected Multigraph G = (V,E) is an ordered pair, consisting of a finite set V called the vertex set, and a finite set E called the edge multiset. Each element in the edge set is an unordered pair of V × V , which we denote by {u, v}, u, v ∈ V . Furthermore, there are no so-called self-loops, meaning that in any edge {u, v}, we always have that u 6= v. In contrast to simple undirected graphs, it is allowed to have more than one edge between each pair of vertices {u, v}. Definition 3.9. [Contracting edges.] Given an undirected graph G = (V,E), contracting an edge {u, v}, u, v ∈ V is defined by combining the vertices u, v into one new vertex w. The edge multiset of w is the union of the edge multisets of u and v, excluding the edges between u and v initially. Note that we are now talking about a multiset, because there now can be multiple edges between one pair of vertices. An example of how contraction works is given in Figure 3.9.

Fig 1: before contraction Fig 2: after contraction

Figure 3.9: Example of an edge contraction.

We see that contracting edges indeed changes the graph from a simple undirected graph to an undirected multigraph. Because we contracted an edge {u, v} and there was another vertex that was incident to both u and v, a multigraph was created with two edges between two vertices. Now that we have sufficient knowledge of this theory, we can introduce Karger’s algorithm. The pseudocode is given below.

26 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

Algorithm 5 Karger’s minimum cut algorithm [13] Precondition: G = (V,E) an undirected connected simple graph

1: while there are more than two vertices do 2: pick an edge {u, v} ∈ E uniformly at random 3: contract the vertices u and v 4: end while 5: return the partition of the two remaining vertices

As you can see, the algorithm is very straightforward. An example of the algorithm in action on a simple undirected graph is given in Figure 3.10. The minimum cut in the example graph below is equal to one, and in the steps, a sequence of edge contractions is shown that eventually leads to this minimum cut. Each vertex has been assigned a label from 0 to 7, and when an edge is contracted between two vertices, the label is updated to the union of the two vertices. After six edge contractions, we see that what the cut is, as well as its value.

a: example graph b: 1st edge contraction c: 2nd edge contraction d: 3rd edge contraction

e: 4th edge contraction f: 5th edge contraction g: 6th edge contraction h: final cut

Figure 3.10: Example of the algorithm in action.

On the maximum cut problem: A new 0.5-approximation algorithm 27 CHAPTER 3. PREVIOUS CONTRIBUTIONS

Analysing the algorithm, we see that we contract pairs of vertices n − 2 times. When using an appropriate date structure, we can update the graph after a contraction in O(n) time, giving this algorithm a running time of O(n2), where n the number of vertices. There are faster ways to execute this algorithm, even in O(m) time, where m is the number of edges. An example is described in [13]. However, getting an optimal running time here is not the message we are trying to convey.

We now start with identifying some properties of the algorithm and eventually analyse how well the algorithm performs in finding the minimum cut. Lemma 3.10. Edge contractions do not decrease the minimum cut size of a graph G.

Proof. Important to see is that doing an edge contraction does not decrease the size of the minimum cut of the graph; else the algorithm would not be of any good. Luckily, the only thing that edge contracting does is combining two vertices into one, thereby removing the edge between them. However, the minimum cut problem only considers the edges going between the two remaining vertices. These edges were not tampered with. Furthermore, each cut in any stage of Karger’s algorithm is also a cut in the actual graph. The only thing is that some vertices have already been grouped due to contractions. Thus, no new cuts are created by the algorithm, and thus the minimum cut size cannot have been decreased due to the algorithm. As you can see in the example, it is not guaranteed that we will find the minimum cut in the first try. However, since we randomly contract edges, we have a probability greater than zero for the algorithm to return the minimum cut. We will analyse this probability.

kn Lemma 3.11. If the value of the minimum cut in a graph is k, then there are at least 2 edges in that graph Proof. Since we assumed the graph G = (V,E) to be connected, we know that the minimum cut crosses at least one edge. So, we know that the minimum cut has a value k ∈ N+. We first provide an upper bound to the value of the minimum cut. Let v be the vertex with the lowest degree in the graph G. Now consider the cut where we put v in one partition and |V | − {v} to be the other partition. This is a valid cut, and thus we know that the minimum cut is never greater than the degree of the vertex with the smallest degree. We use this upper bound to give a lower bound to the number of edges in the graph. Since we know that each vertex has a degree greater than or equal to the value of minimum cut, namely k, the total sum of degrees is greater than or equal to kn. Then, by the handshaking lemma, we know that the total number of edges is then greater kn than or equal to 2 . In comprehensive mathematical notation, we have

X kn k ≤ min d(v) ⇐⇒ kn ≤ n min d(v) ≤ d(v) = 2m ⇐⇒ m ≥ v∈V v∈V 2 v∈V

Now that we have a lower bound on the total number of edges, and since we are picking edges uniformly at random, we can start looking at the probabilities. Lemma 3.12. The probability of not contracting an edge from a minimum cut in the first con- 2 traction is at least 1 − n . Proof. For Karger’s algorithm to return a minimum cut, we need to make sure that none of the kn k edges in the minimum cut are contracted. Since we have more than 2 edges, we know that k 2 the probability of contracting an edge from a minimum cut is smaller than kn = n , and thus the 2 2 probability of not contracting this first edge is greater than 1 − n .

28 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 3. PREVIOUS CONTRIBUTIONS

Lemma 3.13. The probability of not contracting an edge from the minimum cut in the ith 2 contraction, assuming no edges from the minimum cut are contracted, is at least 1 − n−i+1 Proof. Assume that we have done i − 1 contractions, in which we have not contracted any of the k edges of the minimum cut. This means that we still have k edges from the minimum cut, and only have n − (i − 1) vertices left. This also means that each remaining vertex in the graph has a k(n−(i−1)) degree of at least k, and thus we have at least 2 edges remaining. This is analogous to the proof in lemma 4.5. And thus, when we contract an edge uniformly at random, contracting one k 2 of the k edges out of the remaining edges has a probability of at most k(n−i+1) = n−i+1 , meaning 2 that the probability of not contracting an edge from the minimum cut in this scenario is at least 2 1 − n−i+1 , as was to be shown. Combining the lemmas above, we can now prove the probability of Karger’s algorithm finding a minimum cut.

2 Theorem 3.8. The probability of finding a minimum cut is greater than n(n−1) Proof. Given that we have not contracted any edge from the minimum cut yet, we have shown that the probability of not contracting an edge from the minimum cut at the ith contraction, is 2 greater than 1 − n−i+1 . For Karger’s algorithm to return the minimum cut, the algorithm must not contract an edge belonging to the minimum cut at every step. Note that there of course can be two different cuts both with minimal value, but if there are more minimum cuts in the graph, the probability of finding a minimum cut will not decrease. So, for the lower bound, we assume that there is only one minimum cut. By the previous lemmas, the probability of finding this minimum cut is greater than

n−2 n−2 Y 2 Y n − i − 1 (1 − ) = n − i + 1 n − i + 1 i=1 i=1 n − 2 n − 3 n − 4 3 2 1 = · · ····· · · n n − 1 n − 2 5 4 3 2 = n(n − 1) which proves the theorem. Thus, this means that the probability of Karger’s algorithm returning a minimum cut is of the 1 order n2 . This seems quite small, especially for large n, but it is all a matter of perspective. The number of possible cuts, given a graph with n vertices, is 2n−1 − 1. We namely have 2n ordered ways to partition n elements, but it is not a valid partition two have one subset empty and one subset full or vice versa. That leaves us with 2n − 2 ordered ways, but the order of the partition does not matter. For every partition, there is exactly one other partition that is the same, but in a different order, so we need to divide the amount we had by 2, giving us the total of 2n−1 − 1 possible cuts. Assuming there is only one minimum cut, randomly picking one cut gives us a 2 probability of 2n−2 . Even for n = 10 Karger’s algorithm has a probability which is 10 times as high and for n = 25, Karger’s algorithm has a probability which is about 56.000 times higher.

2 A valid remark is still that a probability greater than n(n−1) can still be low, albeit a much higher probability than random guessing. However, the strength of Karger’s algorithm lies in the fact that the algorithm can be repeated multiple times in a short period of time. Then, you can pick the best instance that you have gotten in those iterations.

On the maximum cut problem: A new 0.5-approximation algorithm 29 CHAPTER 3. PREVIOUS CONTRIBUTIONS

Thus, it is clear that there is a relatively big chance of finding the minimum cut by applying Karger’s algorithm once. Now, can we also quantify this probability if we do it multiple times? With thanks to probability theory, we can.

n2 Lemma 3.9. Karger’s algorithm finds a minimum cut with high probability in 2 ln n iterations, and thus in O(n4 ln n) time. Proof. Due to the independence of each iteration of Karger’s algorithm, the probability of not finding the minimum cut in T iterations can quite easily be estimated as follows.

Pr (Find min-cut in T iterations) = 1 − Pr (Not finding the minimum cut in T iterations) = 1 − Pr (Not finding the minimum cut in one iteration)T  2 T ≥ 1 − 1 − n(n − 1)  2 T ≥ 1 − 1 − n2 Now, some may recognise from real analysis that  1 m lim 1 + = e, m−→∞ m and more particularly, that  1 m 1  1 m 1 lim 1 − = , and also that 1 − < ∀ m ∈ N. m−→∞ m e m e

n2 n2 Thus, setting m = 2 and T = 2 ln n, we get that

 1 m ln n Pr (Find min-cut in T iterations) ≥ 1 − 1 − m 1ln n > 1 − e 1 = 1 − . n This means that the probability of finding a minimum cut in converges to 1 when we the number of vertices in the graph increases. Given the simplicity of this algorithm, this is quite a good lower bound on the success rate of this algorithm. Now, since each iteration takes O(n2), we can easily see that getting this success rate takes O(n4 ln n) time.

30 On the maximum cut problem: A new 0.5-approximation algorithm Chapter 4

A new algorithm for Max-Cut

We have seen that a simple randomised algorithm such as Karger’s algorithm can be very effective. This was the inspiration that we had when we came up with the algorithm that is discussed in this Chapter. We first give a description of the algorithm, after which we analyse the algorithm, mostly concerning the approximation ratio. We also investigate some instances of graphs where the algorithm performs well on, as well as a slight detour on uniform spanning trees.

4.1 Description

As said before, this algorithm is an algorithm for the maximum cut problem as described in definition 2.11. The pseudocode of the algorithm is given below:

Algorithm 6 Our algorithm for the maximum cut Precondition: G = (V,E) an undirected connected simple graph

1: F ←− ∅ 2: while F is not a spanning tree do 3: let E0 be the set of all edges {u, v} ∈ E such that F ∪ {u, v} contains no cycles 4: pick an edge {u, v} ∈ E0 uniformly at random 5: F ←− F ∪ {u, v} 6: end while 7: return the unique bipartition {V1,V2} of V such that F ⊆ {{u, v} ∈ E, u ∈ V1, v ∈ V2}

The algorithm works in the opposite direction of Karger’s algorithm. Instead of contracting an edge at every iteration, it adds an edge at every iteration. We do need to check whether adding an edge to F creates a cycle because else it could be that we cannot return a bipartition G.

Furthermore, the running time of the algorithm is O(mn2), where m is the number of edges and n the number of vertices. This is because a spanning tree has precisely n − 1 edges, and thus the algorithm iterates over the while loop O(n) times. For each iteration, we need to check whether an edge creates a cycle. This can be done by using depth-first search for example. This runs in O(n), since the number of edges in F is upper bounded by n. In the worst case, we need to check O(m) edges before an edge is found that does not create a cycle. In total, this yields a running time of O(mn2).

An example of how the algorithm works is given in Figure 4.1. The grey edges are the edges that are in the graph G = (V,E) that could still be added to the graph T = (V 0,F ). The black edges are the edges that are in the graph T = (V 0,F ), and the red edges are the edges that cannot be added to T anymore because that would create a cycle.

On the maximum cut problem: A new 0.5-approximation algorithm 31 CHAPTER 4. A NEW ALGORITHM FOR MAX-CUT

a: example graph b: first edge added c: second edge added

d: third edge added e: fourth edge added f: fifth edge added

g: sixth edge added h: seventh edge added i: final edge added

j: unique bipartition and cut k: visualisation of the cut

Figure 4.1: Example of the algorithm in action.

32 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 4. A NEW ALGORITHM FOR MAX-CUT

Furthermore, we also do know that the algorithm terminates by construction since the precondi- tion is that the graph G = (V,E) is connected. An undirected connected simple graph always has at least one spanning tree. As is written in the preliminaries (section2), a graph is defined to be connected if, between every pair of vertices, there is at least one path. Now, a graph T = (V 0,F ) is a tree if there is exactly one path. Clearly, if there is at least one path for every pair of vertices, we can take F ⊆ E such that there is exactly one path by leaving out enough edges. By lemma 2.14, we have that T is a spanning tree, which means the algorithm terminates.

At the end of writing this Bachelor’s thesis, we discovered that a similar algorithm has been proposed in [12] by Kahruman et. al. Their approach was to contract edges, thereby merging two vertices into one, until only two vertices remain, which represent the cut that their algorithm 1 returns. They managed to prove that their algorithm has an approximation ratio of 3 , the question is whether our algorithm can improve on this approximation ratio.

4.2 Approximation Ratio

Our intuition is that this algorithm gives a 0.5-approximation, and here we prove this is indeed the case. We first show a more subtle statement which will aid us in proving the approximation ratio.

To check the approximation ratio of the algorithm, we first analyse one iteration of the algorithm. In one such iteration, one edge in the edge set of G = (V,E) is added to F such that no cycle is created.

What is interesting about this algorithm is that for a subset of edges, we can already know which will be in the cut and which will not. As described above, we return the bipartition of the computed spanning tree T = (V,F ) of G = (V,E). We know that if {u, v} is an edge in F , then u and v are in different sets in the partition. By the same reasoning, if we have edges {u, v}, {v, w} ∈ F , then we now that u and w are in the same partition element, and v is in the other partition element. From this, we can conclude that an edge {u, w} would not be in the cut computed by our algorithm, even though we have only three vertices in our current forest yet. So, even halfway through the algorithm, we can already compute how many edges we already have in our cut. We define Ci to be the set of edges in the cut after the ith iteration of the algorithm. These are the cut edges. More formally,  Ci = {u, v} | u ∈ V1, v ∈ V2 at iteration i. Additionally, we can also say with certainty that some edges will be in the cut and some edges will not, since the bipartition is already fixed for the edges that have been considered. We define Di to be the set of decided edges at the ith iteration of the algorithm. More formally,  Di = {u, v} | u, v ∈ V1 ∪ V2 at iteration i.

Initially, we have that |C0| = 0 and |D0| = 0. In the end, we have that Cn−1 is equal to the cut and Dn−1 = E, meaning that all edges have been considered.

Observation 4.10. At each iteration i, Di \ Di−1 is a bipartition.

By our definition, we have that Di \ Di−1 are all the edges between the two forests that we are connecting at iteration i of the algorithm. If we add one edge, that means that we connect two different forests F1,F2 ⊂ F together by that one edge, together creating one bigger forest. One such forest can be a single isolated vertex, for example at the very first iteration of the algorithm. Now, let us condition on two random forests being connected by an edge. We will now see what happens to the edges in G = (V,E), where one vertex is in F1 and one vertex is in F2.

On the maximum cut problem: A new 0.5-approximation algorithm 33 CHAPTER 4. A NEW ALGORITHM FOR MAX-CUT

So, now let F1 and F2 be two different forests created by the algorithm, and condition on that the algorithm has picked an edge {u, v} ∈ E uniformly at random such that u ∈ F1, v ∈ F2. Now, although there can be more than two edges going between F1 and F2 that could be picked, there are only two outcomes. For example, consider the forests in Figure 4.2.

Figure 4.2: Example of connecting two forests in the algorithm

The black edges are edges already in F , and the dashed or dotted are all the edges of G that can be used to directly connect F1 and F2, which is equivalent to the set Di \ Di−1. If we add any of the three brown dotted edges, all three will be in the cut, and all blue dashed edges will not be in the cut. To see this is true, let us assume the edge {3, 6} is used to connect F1 and F2. Then, by the analogy above vertex 2 will be in a different partition element from vertex 3, and vertex 3 will be in a different partition element than vertex 6. Furthermore, vertex 6 will be in a different partition element than vertex 5. This means that vertex 2 and vertex 5 will also be in different partition elements, and thus the brown dotted edge {2, 5} is also in the cut. Vertex 3 and vertex 5 however, are in the same partition element and thus the blue dashed edge will not be in the cut. By the same reasoning, all blue dashed edges would be in the cut when you would add blue dashed edge {3, 5} for example.

h i   |Di\Di−1| Lemma 4.2. E |Ci \ Ci−1| ≥ E 2 for any iteration i

Proof. Using the observation above, we can calculate the expected value of edges added to the cut at iteration i, which is equal to Ci \ Ci−1|. First, we condition on connecting two different forests F1 and F2. Let us denote the two different edge sets of the bipartition Di \ Di−1 by A and B respectively. In the example above, all brown dotted edges would be elements in A and all blue dotted edges would be elements in B. Then,

h i 4.10 E |Ci \ Ci−1| | edge connects F1 and F2 = |A| · Pr (edge from A is chosen) + |B| · Pr (edge from B is chosen) |A| |B| = |A| + |B| |A| + |B| |A| + |B| |A|2 + |B|2 = |A| + |B| (|A| + |B|)2 2|A||B| = − |A| + |B| |A| + |B| 2( |A|+|B| )2 ≥ |A| + |B| − 2 . |A| + |B|

34 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 4. A NEW ALGORITHM FOR MAX-CUT

The last inequality follows from the inequality of arithmetic and geometric means, which is

√ x + y (x + y)2 xy ≤ ⇒ −xy ≥ − . 2 4 Further rewriting this equation yields

|A| + |B| |A| + |B| − 2 |A| + |B| = 2 h|D \ D |i = i i−1 . E 2 Thus, we can expect to add at least half of all the possible edges to the maximum cut. Now, what this essentially means is that we always know that we add at least half of the edges to the cut when we connect two forests. We now need to generalise this such that it covers the expected edges in the cut for the whole algorithm. We can derive the approximation ratio by using the observation and the lemma above. Intuitively, if we always add at least half of the possible edges to the cut, and all edges are considered exactly once, then we can be sure that we have at least half of the edges in the cut at the end of the algorithm. Theorem 4.12. The algorithm has an approximation ratio of at least 0.5.

Proof.

E[edges in cut] = E[|Cn−1|] n−1 X = E[|Ci \ Ci−1|] + |C0| i=1 n−1 4.11 X h|Di \ Di−1|i ≥ E 2 i=1

Furthermore, we have that |Dn−1| = |E| and |D0| = 0, and thus

n−1 X h|Di \ Di−1|i |E| = E 2 2 i=1 OPT (G) ≥ . 2 The last inequality follows from the fact that the optimal value can never exceed the total number of edges in a graph, implying that OPT (G) ≤ |E|.

On the maximum cut problem: A new 0.5-approximation algorithm 35 CHAPTER 4. A NEW ALGORITHM FOR MAX-CUT

4.3 Instances of graphs where our algorithm performs well

So far, we have seen that the algorithm returns a maximum cut that is always at least half of all the edges in the graph. This result is true, given any simple undirected graph. However, there are several types of simple undirected graphs, and for some of these types, our algorithm performs significantly better than for the general case. In this section, we will touch upon certain types of simple undirected graphs, and prove that the algorithm performs strictly better for these cases.

4.3.1 Connected Bipartite graphs One type of simple undirected graphs where our algorithm performs exceptionally well is bipartite graphs. Since our algorithm requires the graph to be connected, the bipartite graph needs to be a connected bipartite graph. Bipartite graphs have already been defined in Chapter2.

So, when a graph is a connected bipartite graph, that means that there is a bipartition {V1,V2} of the vertex set, such that for each edge {u, v}, we have that u ∈ V1, v ∈ V2 or vice versa. Intuitively, if we would pick this bipartition to be our cut {V1,V2}, then we will have that all edges are in the maximum cut. Hence, in a bipartite graph, the value of the maximum cut is |E|.

We now claim that, given a simple undirected bipartite graph G = (V,E) that is also connected, our algorithm will always find the optimal maximum cut. Thus, the approximation ratio for this type of simple undirected graph is exactly 1.

If we look at what our algorithm outputs, then we see that we always return the bipartition of the generated spanning tree T = (V,F ). We know that a connected bipartite graph has one unique bipartition. We know that for each vertex v, there is at least one edge {u, v} with u in the other set of the bipartition. Thus, we can never shift v to the other set in the bipartition, since that would mean that one edge does not cross the bipartition. Thus, a connected bipartite graph has exactly one bipartition. Since the bipartition of V is unique, we know that our algorithm will output the same bipartition of V , and consequently, returns a cut of value |E|. Thus, for a connected bipartite graph, our algorithm is an exact algorithm.

Although the maximum cut for this type of graphs is easily found in polynomial time, it is inter- esting to note that bipartite graphs were the type of graphs where the other simple approximation algorithms performed the worst on. The random approach, the greedy approach, and the local 1 search approach all had an approximation ratio of exactly 2 on the complete bipartite graph K2n,2n, as mentioned in Section 3.2.3. Thus, our algorithm gives an exact solution for these types of graphs, whereas these types of graphs are the worst input you can give to the other approximation algorithms.

4.4 Uniform Spanning Trees

So, as we have seen, the algorithm creates a spanning tree from a given simple undirected graph G = (V,E). Since the algorithm creates these spanning trees randomly by selecting edges uni- formly at random, we also get different spanning trees when we apply the algorithm multiple times on the same graph. This raises the question whether each spanning tree is generated with equal probability, making it a uniform spanning tree. We define this notion here and investigate whether our algorithm helps in generating these uniform spanning trees. Definition 4.13. [Uniform Spanning Tree.] A Uniform Spanning Tree (UST) on a simple undir- ected graph G = (V,E) is a spanning tree, which is chosen uniformly at random from the set of all spanning trees. More formally, let T (G) be the set of all spanning trees of G. If the probability of 1 getting a specific spanning tree is equal to |T (G)| for each spanning tree in T (G), then a uniform spanning tree is any spanning tree in T (G).

36 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 4. A NEW ALGORITHM FOR MAX-CUT

Uniform spanning trees have applications mainly concerning randomly generating objects. For ex- ample, an algorithm that can output spanning trees uniformly at random can be used to randomly generate grid mazes. This can be done by representing each square of the grid by a vertex, and then adding edges between squares that are adjacent. Then, any spanning tree is a configuration of the maze. Uniform spanning trees are a useful way to generate these mazes, since you are guar- anteed that all squares are reachable from any square, because a spanning tree is always connected.

So, the question arises whether our algorithm also generates uniform spanning trees. Our hypo- thesis is that this is not the case, since known algorithms for this problem are of a higher level of complexity, such as Wilson’s algorithm [29]. However, we can only know for sure when we have found a counterexample. Here, we see that the simple graph with its spanning trees in Figure 4.3 is a counterexample.

a: example graph

b: spanning tree 1 c: spanning tree 2 d: spanning tree 3 e: spanning tree 4

f: spanning tree 5 g: spanning tree 6 h: spanning tree 7 i: spanning tree 8

Figure 4.3: A graph with all its spanning trees.

On the maximum cut problem: A new 0.5-approximation algorithm 37 CHAPTER 4. A NEW ALGORITHM FOR MAX-CUT

Now, if we would have uniform spanning trees, then the probability for each spanning tree here 1 to be created by the algorithm should be 8 . However, the spanning trees on the top row are 8 generated with a probability of 60 , whereas the spanning trees on the bottom row are created 7 with a probability of 60 . To see this probability, one could simply branch out all possibilities, and since the edge choices are made uniformly, we can easily calculate the probability of the algorithm picking this sequence of edges. An example of computing the probability of getting the first spanning tree is given in Figure 4.4.

Figure 4.4: Calculation of the probability of generating this spanning tree.

So, from just this example alone, we see that not all spanning trees are generated with equal probability. The reason for this lies behind the fact that the branching possibilities in the above figure are fewer when we are close to creating a cycle. If you look at all the spanning trees with a 1 generating possibility of 40 , we see that this is the case because one of the three final possibilities will create a cycle, and thus this edge cannot be added. In the spanning trees with a generating 1 possibility of 60 , none of the three final possibilities will create a cycle. Thus, the probability of 1 1 that specific edge to be added is 3 instead of 2 for the spanning trees with the diagonal edge added to it. Thus, spanning trees that are closer to a cycle, will have a higher probability of being generated, because fewer edges have the possibility of being added to the spanning tree.

38 On the maximum cut problem: A new 0.5-approximation algorithm Chapter 5 pq-Graphs

5.1 Generating pq-graphs

Apart from proving the approximation ratio of our algorithm, we also apply our algorithm on example graphs to get experimental results, which helps gain a better understanding of the per- formance of our algorithm. Unfortunately, to conduct these experiments, the optimum value of the maximum cut must be verified to know if the algorithm gave a decent output. For graphs with fewer than 25 vertices, this is feasible by for example a brute force approach (see Section 3.1.1). However, we would also like to run our algorithm on graphs with a couple of hundred vertices. Given our resources, we will not be able to find the optimum value of the maximum cut within the writing of this thesis by using any known exact algorithm. Luckily, we are also able to generate graphs with hundreds of vertices such that we can embed a known maximum cut in the graph with high probability.

The generation of these graphs is as follows: given a natural number n, we first create two separ- ated graphs G1 = (R, ∅), G2 = (B, ∅), both on n vertices. Then, for each unordered pair {u, v}, u, v ∈ R or u, v ∈ B, we create an edge with independent probability p. These are the edges such that the two vertices are either both in R or both in B. After that, for each unordered pair {r, b}, r ∈ R, b ∈ B, thus a potential edge going between the two graphs, we create an edge with independent probability q. If we pick p to be much smaller than q, then the maximum cut will most likely be the bipartition {R,B}. In this chapter, we will refer to this cut as the embedded cut, and we will refer to the graph as a pq-graph. A visualisation of a pq-graph is given in Figure 5.1.

Figure 5.1: A visualisation of a pq-graph, where p << q.

On the maximum cut problem: A new 0.5-approximation algorithm 39 CHAPTER 5. PQ-GRAPHS

First of all, the expected maximum cut, which is the cut we attempted to embed in the graph, will be the value of the cut {R,B}. Since both sets have n vertices, we know that there are a total of n2 edges possible in the cut, each with a probability q. Thus, the expected value of the embedded cut will be n2 · q, assuming p < q. For the total number of edges in the graph, we can make use of the expected value. We have n2 · q edges between R and B. Within R, we have n vertices, and n thus a total of 2 possible combinations of edges that can be added, each with a probability of p. n Thus, the expected number of edges in R and B is 2 · p · 2 = n · (n − 1) · p. This gives us a total number of expected edges of n2 · q + n · (n − 1) · p.

We also have to note that at the end of writing this Bachelor’s thesis, we discovered that a similar approach has also been researched in [2]. Our main focus was bipartitions, but their focus was on partitions of more than two sets. They added edges with independent probability r between vertices from different sets of the partition, and edges with probability p between vertices from the same set of the partition.

5.2 Analysis of the maximum cut in pq-graphs

Using pq-graphs, we hope to be able to embed a maximum cut in our graph. If p is sufficiently smaller than q, then one would expect the maximum cut to be {R,B} with cut value n2 · q. However, the question arises how far p and q should be apart. Furthermore, what is the actual probability that the value of the maximum cut is indeed n2 · q? In this section, we attempt to answer these questions using probability theory.

5.2.1 Attempt 1: using the binomial distribution We first investigate what needs to happen for one vertex to shift to the other set of the partition in the maximum cut. If we shift one vertex, then all the edges between this vertex and vertices in the other set of the partition will be removed from the maximum cut. The expected value of this number of edges is n · q. However, the edges that will be added are all the edges between this vertex and other vertices in the same set of the partition, which has an expected value (n − 1) · p. The cut thus shifts if Bin(n, q) < Bin(n − 1, p). Let X ∼ Bin(n, q) and Y ∼ Bin(n − 1, p). Then,

n−1 X Pr (X < Y ) = Pr (X < Y ∩ Y = j) j=1 n−1 X = Pr (X < j) Pr (Y = j) j=1 n−1 j−1 X X = Pr (X = i) Pr (Y = j) j=1 i=0 n−1 j−1 X X n n = qi(1 − q)n−i · pj(1 − p)n−j. i j j=1 i=0

Thus, if we do not want the embedded maximum cut to shift, we require that for all edges incident with a vertex, more edges cross to the other partition than edges going to another vertex in the same partition. This is also needed for all vertices in the graph. Note that these events are not independent of each other, because if an edge is created, this edge is also incident to another ver- tex. Due to this independence, this approach, unfortunately, did not result in the probability of the maximum cut being {R,B}, but it gave us more insight into this strategy of generating graphs.

40 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 5. PQ-GRAPHS

5.2.2 Attempt 2: using a strict Chernoff bound

We attempt an alternative approach, using the so-called Chernoff bound. To be more exact, we will use the multiplicative Chernoff bound. This bound was first derived by Hermann Chernoff, albeit in a slightly different form, in [3]. The bound is stated as follows: let X1,...,Xn be independent Pn random variables attaining values in {0, 1}. Let X = i=1 Xi, let µ = E(X). Then, for any δ > 0,

!µ eδ Pr (X > (1 + δ)µ) < (1 + δ)1+δ

Summing over all possible cuts We can utilise this to analyse the probability of the actual cut being very different from the cut that we embedded. The probability of this cut being the maximum cut is equal to

Pr (Embedded cut is maximum cut) = 1 − Pr (Embedded cut is not maximum cut) = 1 − Pr (Cut 1 bigger ∪ Cut 2 bigger ∪ · · · ) X ≥ 1 − Pr (Cut {x, y} is bigger) all cuts {x, y}

Pn Because Pr (E1 ∪ E2 ∪ · · · ∪ En) ≤ i=1 Pr (Ei) for events Ei, i = 1, ··· , n. Now let us consider only one single cut, and analyse the probability that any cut will yield a value larger than the expected value of the embedded cut.

Expected value of a single cut Thus, let {x, y} be an arbitrary cut in a pq-graph. Consequently, we have that a vertices of R are in set x and n − a are in set y, and b vertices of B are in set x and n − b are in set y.A visualisation of such a cut {x, y} is given in Figure 5.2.

Figure 5.2: A visualisation of a cut {x, y} with corresponding edge probabilities

On the maximum cut problem: A new 0.5-approximation algorithm 41 CHAPTER 5. PQ-GRAPHS

Thus, the expected number of edges in the cut {x.y} is

E(edges between x and y) = E(edges between x ∩ R and y ∩ R) + E(edges between x ∩ B and y ∩ B) + E(edges between x ∩ R and y ∩ B) + E(edges between x ∩ B and y ∩ B) = a · (n − a) · p + b · (n − b) · p + a · (n − b) · q + b · (n − a) · q = pa · (n − a) + b · (n − b) + q · a · (n − b) + b · (n − a)

Probability of a single cut Given these a and b, the probability that this is greater than the expected value of the embedded maximum cut, which is n2 · q, is equivalent to

Pr (Cut {x, y} > n2 · q) = Pr (Cut {x, y} > (1 + δ)µ)

  n2·q for µ(a, b) = p a · (n − a) + b · (n − b) + q · a · (n − b) + b · (n − a) and δ(µ) = µ(a,b) − 1 > 0 for q > p. Then, by the Chernoff bound

!µ(a,b) eδ(µ) Pr (Value of cut {x, y} > n2 · q) < (1 + δ(µ))1+δ(µ) for any partition {x, y}. So, given an n, p, and q, we can now bound from above the probability of any cut exceeding the expected value of the embedded maximum cut.

Rewrite the sum with respect to a and b We require a way to sum up all these possible bipartitions with respect to a and b in order to analyse this bound properly. For this, we use Newton’s binomium.

n Assume we have a vertices of R in the first set of our partition. There are a different ways for n this. Analogously, if we have b vertices of B in the first set of our partition, then there are b ways to have this. Since the order of the two sets in the partition is irrelevant, we have to divide by two. Furthermore, since the number of vertices from R is independent of the number of vertices from B, we have that

1nn 2 a b is the total number of partitions with a vertices of R and b vertices of B in one set of the partition, and n − a vertices of R and n − b vertices of B in the other set of the partition.

42 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 5. PQ-GRAPHS

Putting it all together So, if we put all these parts of the derivation together, we have that

Pr (Embedded cut is maximum cut) = 1 − Pr (Embedded cut is not maximum cut) = 1 − Pr (Cut 1 bigger ∪ Cut 2 bigger ∪ · · · ) X ≥ 1 − Pr (Cut {x, y} is bigger) all cuts {x, y} n n 1 X X nn = 1 − Pr (Cut {x, y} is bigger) 2 a b a=0 b=0 n n ! µ(a,b) 1 X X nn eδ(µ) > 1 − 2 a b (1 + δ(µ))1+δ(µ) a=0 b=0 . Practical evaluation Using this derivation, we see that for example using n = 100, p = 0.10 and q = 0.50, for all biparti- tions {x, y} with 25 ≤ a ≤ 75 and 25 ≤ b ≤ 75, their probability of having a value greater than the maximum cut is smaller than 10−100. So, a large portion of all bipartitions can practically be ex- cluded from potentially being a maximum cut, since they are too different from the embedded cut.

However, this estimation is not tight enough for bipartitions {x, y} that very much resemble the embedded cut, as their respective probabilities have a high lower bound. For example, for a = 99 and b = 0, so a partition with only one vertex shifted, the probability of its cut exceeding the value of the embedded cut has an upper bound of 0.851, meaning that if we sum over all these partitions, the estimated probability of having that the embedded cut is the maximum cut is lower bounded by 0, which is an obvious and meaningless lower bound.

Asymptotic behaviour An interesting analysis would still be how the lower bound

n n !µ(a,b) 1 X X nn eδ(µ) 1 − (5.1) 2 a b (1 + δ(µ))1+δ(µ) a=0 b=0 behaves as n approaches infinity. However, we were unable to investigate this asymptotic behaviour in this Bachelor’s thesis due to time constraints.

5.2.3 Attempt 3: using a looser Chernoff bound The main problem with the strict Chernoff bound is that there are too many cuts that attain values close to the value of the embedded cut. To counter this, we require that the value of all cuts remains below a looser 1.05 · n2 · q, instead of n2 · q.

On the maximum cut problem: A new 0.5-approximation algorithm 43 CHAPTER 5. PQ-GRAPHS

Another variant of the Chernoff bound Furthermore, we also make use of another variant of the Chernoff bound. The other variant is stated as follows. Again, let X1,...,Xn be independent random variables attaining values in Pn {0, 1}. Let X = i=1 Xi, let µ = E(X). Then, for any 0 ≤ δ ≤ 1,

−δ2µ Pr (X ≥ (1 + δ)µ) < e 3 (5.2) Now, let G A pq-graph on n vertices with p < q. Let EMB(G) be the embedded cut. Then, we have that µ = n2 · q is the expected value of the embedded cut. Then, by the looser Chernoff bound,

 0.052 · n2 · q  Pr EMB(G) ≥ (1 + 0.05) · n2 · q ≤ exp − 3 n2 · q = exp(− ). 1200 In order to give any conclusions about the maximum cut exceeding 1.05 · n2 · q, we need to sum over all possible cuts. Since p < q, we know that all cuts have an expected value less than the embedded cut. From this, we can conclude that

X Pr OPT (G) ≥ (1 + 0.05) · n2 · q ≤ Pr (Value of cut {x, y} ≥ 1.05 · n2 · q) all cuts {x,y} X  0.052 · n2 · q  ≤ exp − 3 all cuts {x,y} n2 · q = 2n−1 exp(− ). 1200 Lower bounding the approximation ratio So as an example, if we pick n = 200, p = 0.20 and q = 0.50. Then, the outcome of the summation above is 3.181845e − 07. This allows us to conclude that 1.05 · n2 · q is an upper bound to the maximum cut with a certainty of 1 − 3.181845e − 07 ≈ 0.9999997. We can use this to lower bound the approximation ratio of our algorithm on a pq-graph. Let A(G) be the cut that our algorithm outputs, given a pq-graph G = (V,E). For this, we need to sum over all possible cuts. Then,

! ! |A(G)| |A(G)| |A(G)| |A(G)| Pr > = 1 − Pr ≤ (5.3) OPT (G) 1.05 · n2 · q OPT (G) 1.05 · n2 · q = 1 − Pr (OPT (G) ≥ 1.05 · n2 · q) (5.4) n2 · q > 1 − 2n−1 exp(− ). (5.5) 1200 And thus, we can use this to give a confident lower bound on the approximation ratio of our algorithm for a given n, p, and q.

Asymptotic behaviour What the asymptotic behaviour of (5.3) is, is also an interesting question to ask. Intuitively, we would expect that (5.3) would converge to the value 1. In other words, if our graph is large enough, then we can be fully sure that the approximation ratio is not overestimated.

We have seen that (5.3) is strictly larger than

 n2 · q  1 − 2n−1 exp − , 1200

44 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 5. PQ-GRAPHS so let us first see how that equation behaves in the limit. We have that

 n2 · q   q −n2 2n−1 exp − = 2n−1 exp 1200 1200 1 2 ≤ 2nc−n 2

  n where c = exp q > 1. We know that 1 2 converges to zero as n tends to infinity, since 1200 2 cn2 c > 1. Furthermore, since we have that ! |A(G)| |A(G)| 1 2n 1 ≥ lim Pr > ≥ 1 − lim , n−→∞ OPT (G) 1.05 · n2 · q n−→∞ 2 cn2 we know that ! |A(G)| |A(G)| lim Pr > = 1. n−→∞ OPT (G) 1.05 · n2 · q

5.3 Approximation ratio of our algorithm on pq-graphs

1 As mentioned in Section 4.2, we know that our algorithm is a 2 -approximation. However, we would like to prove that our algorithm has an even better approximation ratio. As mentioned in the introduction, this bachelor thesis was inspired by the question whether we could develop a 1 simple algorithm with an approximation ratio better than 2 . Unfortunately, we were not able to prove nor disprove this for any type of graph, but perhaps we can either prove or disprove this for pq-graphs.

Our approach utilises a so-called recurrence relation. At every iteration of our algorithm, we add exactly one edge to the forest, until we have a spanning tree with n − 1 edges. If we can state the recurrence relation such that we can deduce the value of the next term in the sequence, using the terms we already know, we can use this to get the expected approximation ratio. Furthermore, we have already shown in Section 4.2 that halfway through the algorithm, we can already say which edges are in the cut. Thus, for a given tree T , we can already say what the bipartition {V1,V2} will look like. Using the incremental nature of the algorithm, we attempt to give an approximation ratio using recurrence relations.

First of all, we need parameters for each term in the recurrence relation. Given a pq-graph with {R,B} being the embedded cut, we pick the following four parameters:

1. r1: the number of vertices from V1 ∩ R

2. b1: the number of vertices from V1 ∩ B

3. r2: the number of vertices from V2 ∩ R

4. b2: the number of vertices from V2 ∩ B

For this, let us define

Ti[r1, b1, r2, b2] := Pr (a tree of size i occurs with these parameters) (5.6)

The power of a recurrence relation lies in the fact that you can deduce the value Tn−1 by using the previous values Tn−2 of the recurrence relation. We can then sum over all possible Tn−1 and multiply each Tn−1 with their respective expected values, which results in the total expected value of the cut.

On the maximum cut problem: A new 0.5-approximation algorithm 45 CHAPTER 5. PQ-GRAPHS

More formally, let G = (V,E) be a pq-graph, and A(G) be the cut returned by our algorithm. Then,

  X   E |A(G)| = Tn−1[r1, b1, r2, b2] (r1 · b2 + b1 · r2) · q + (r1 · r2 + b1 · b2) · p r1,b1,r2,b2

Having seen the potential of the recurrence relation, let us attempt to solve it. We first look at what happens when we condition on adding an edge between two trees, denoted by the recurrence variables ˆ ˆ ˜ ˜ Tˆi[ˆr1, b1, rˆ2, b2] and T˜j[˜r1, b1, r˜2, b2] . We can distinguish two cases, namely:

1. An edge is added between two vertices from the same set of the partition, so either both are in V1 or both are in V2. Connecting two vertices of the same partition means that they cannot be in the same set of the partition. Hence, we have that one must be in V1 and one must be in V2. In order to cope with this, all vertices of one of the trees must change from V1 to V2 and vice versa. This would give the new variable

ˆ ˜ ˆ ˜ Ti+j[ˆr1 +r ˜2, b1 + b2, rˆ2 +r ˜1, b2 + b1].

Conditioned an adding an edge between these trees Tˆi and T˜j, the probability that this occurs is equivalent to the number of edges between vertices in the same set of the partition over the total number of edges. The expected number of edges remaining in one set of the partition is equal to ˆ ˜ ˆ ˜ ˜ ˆ ˜ ˆ p(ˆr1 · r˜1 + b1 · b1 +r ˆ2 · r˜2 + b2 · b2) + q(ˆr1 · b1 + b1 · r˜1 +r ˆ2 · b2 + b2 · r˜2)

2. An edge is added between two vertices from different sets of the partition, so one vertex is in V1 and one vertex is in V2. Adding such an edge does not break the bipartition, so we do not have to shift any vertices. This would give the new variable

ˆ ˜ ˆ ˜ Ti+j[ˆr1 +r ˜1, b1 + b1, rˆ2 +r ˜2, b2 + b2].

Conditioned an adding an edge between these trees Tˆi and T˜j, the probability that an edge is added between two vertices from different sets of the partition is equal to the expected number of edges between vertices in different sets of the partition divided over the total number of edges between these trees. The expected number of edges between the different sets of the partition is equal to ˆ ˜ ˆ ˜ ˜ ˆ ˜ ˆ p(ˆr1 · r˜2 + b1 · b2 +r ˆ2 · r˜1 + b2 · b1) + q(ˆr1 · b2 + b1 · r˜2 +r ˆ2 · b1 + b2 · r˜1)

Now that we know what the recurrence variable can be when we connect to trees Tˆi and T˜j, we need to generalise this. Unfortunately, we were not able to do this in this Bachelor’s thesis. We see that solving the recurrence relation would indeed give us the approximation ratio of our algorithm on pq-graphs, but attempting to solve the recurrence relation did not lead us to any conclusions.

46 On the maximum cut problem: A new 0.5-approximation algorithm CHAPTER 5. PQ-GRAPHS

5.4 Results on pq-graphs

So, in the previous Section 5.2.3, we described an approach to give an upper bound to the max- imum cut. This upper bound tells us with high probability that the maximum cut will not exceed this value, which implies that we have a lower bound on the approximation ratio with high prob- ability. Using this, we can derive some experimental results from our algorithm in action.

These experimental results are presented here. The variable δ represents the buffer added to the value of the embedded maximum cut, which is used to compute a lower bound on

Pr (OPT (G) ≤ n2 · q · (1 + δ)).

This probability expresses our confidence in the approximation ratio being greater than the ratio given in the tables.

The experimental results were gathered by ourselves. Using the graph library NetworkX for python, we have programmed the the creation and visualisation of pq-graphs, as well as our own algorithm. The code can be found in appendixA. Furthermore, the δ values were also computed by ourselves inR. The code can be found in appendixB. Each experiment has been done one hundred times for each entry, after which we took the average of the one hundred outputs.

5.4.1 Results when p = 0.01, q = 0.50 Our first batch of tests was run with p = 0.01 and q = 0.50. These graphs are in practice almost bipartite, with only a few edges that have both endpoints in the same set of the partition. In terms of the approximation ratio, our δ is chosen such that we are incredibly confident that the approximation ratio is not lower than we have estimated. We see that the ratios are mostly better than 0.70. However, for n = 150 and n = 250, we get approximation ratios lower than 0.60. The results are given in Table 5.1.

n p q δ ratio confidence 100 0.01 0.50 0.075 0.7443 1 − 1e-5 150 0.01 0.50 0.05 0.5920 1 − 3e-5 200 0.01 0.50 0.04 0.7156 1 − 4e-6 250 0.01 0.50 0.03 0.5827 1 − 1e-4 300 0.01 0.50 0.03 0.7450 1 − 5e-8 350 0.01 0.50 0.025 0.7096 1 − 3e-7 400 0.01 0.50 0.02 0.7199 1 − 3e-5

Table 5.1: Experimental results for p = 0.01, q = 0.50

On the maximum cut problem: A new 0.5-approximation algorithm 47 CHAPTER 5. PQ-GRAPHS

5.4.2 Results when p = 0.10, q = 0.50 The second batch of tests was run with p = 0.10 and q = 0.50. These graphs are not that close to being bipartite, but there is still a clear preference for {R,B} being the maximum cut. We see that the ratios are considerably worse than the previous batch of tests. All ratios are consistently smaller than 0.60. These experimental results suggest that our algorithm performs poorly on pq- graphs with p = 0.10 and q = 0.50. A reason for this is that the expected maximum cut remains n2 · q, but the total number of edges increases when p increases. The results are given in Table 5.2.

n p q δ ratio confidence 100 0.10 0.50 0.075 0.5873 1 − 1e-4 150 0.10 0.50 0.05 0.5935 1 − 5e-4 200 0.10 0.50 0.04 0.5898 1 − 1e-4 250 0.10 0.50 0.04 0.5904 1 − 2e-9 300 0.10 0.50 0.03 0.5944 1 − 2e-6 350 0.10 0.50 0.025 0.5941 1 − 1e-5 400 0.10 0.50 0.025 0.5940 1 − 8e-9

Table 5.2: Experimental results for p = 0.10, q = 0.50

5.4.3 Results when p = 0.25, q = 0.50 The third batch of tests was run with p = 0.25 and q = 0.50. These graphs are far from being bipartite, but there remains a slight preference for {R,B} being the maximum cut. We see that the ratios are considerably better than the previous batch of tests. All ratios are very close to each other and slightly larger than 0.70, with the exception when n = 100. For that instance, the ratio is just slightly better than 0.60. The results are given in Table 5.3.

n p q δ ratio confidence 100 0.25 0.50 0.10 0.6186 1 − 5e-7 150 0.25 0.50 0.075 0.7064 1 − 1e-9 200 0.25 0.50 0.05 0.7203 1 − 1e-4 250 0.25 0.50 0.04 0.7262 1 − 1e-3 300 0.25 0.50 0.04 0.7258 1 − 7e-10 350 0.25 0.50 0.03 0.7320 1 − 7e-4 400 0.25 0.50 0.03 0.7316 1 − 1e-8

Table 5.3: Experimental results for p = 0.25, q = 0.50

48 On the maximum cut problem: A new 0.5-approximation algorithm Chapter 6

Conclusions

In this thesis, a new approximation algorithm for the maximum cut was proposed. We have proven 1 that this algorithm is indeed at least a 2 -approximation. If we compare our algorithm to the ran- 1 domised, greedy, and local-search algorithm, which are all a 2 -approximation, we can conclude that our algorithm returns the optimal cut in situations where these other algorithms return a cut only half as good. This gave rise to the big question whether our algorithm would have an 1 approximation ratio better than 2 . The algorithm is quite similar to an algorithm proposed in 1 [12], of which they proved that the approximation ratio was 3 . The question whether we could 1 find a simple algorithm with an approximation ratio better than 2 was also the inspiration of this Bachelor’s thesis, as mentioned in the introduction. Unfortunately, we were neither able to prove 1 nor able to disprove that our algorithm has an approximation ratio better than 2 . This remains one of the open questions that this Bachelor’s thesis raises.

Because the maximum cut problem is NP-hard, it was not possible to randomly create graphs to test our algorithm on, since the value of the maximum cut would be impossible to compute. To counter this, we came up with a method of generating special graphs, which we call pq-graphs, such that we could embed a maximum cut with high probability. A very similar method is also discussed in [2], which we discovered while writing this Bachelor’s thesis.

We analysed these pq-graphs, and we were able to use the Chernoff bound to estimate the probab- ility of the maximum cut exceeding the value of the embedded cut. We have concluded that this probability converges to zero as the number of vertices goes to infinity. Using this probability ana- lysis, we could run our algorithm on these pq-graphs, and were able to estimate the approximation ratios with great accuracy. We can conclude that these experimental results were in accordance 1 with the statement that the approximation ratio of our algorithm is at least 2 . The experimental 1 results suggested that the approximation ratio might be greater than 2 , although this remains one of the open questions of this Bachelor’s thesis.

Another open question posed in this Bachelor’s thesis is the question whether our algorithm has 1 an approximation ratio better than 2 on pq-graphs. We proposed an approach using a recurrence relation on the tree computed by our algorithm, and how the solution of that recurrence relation can be used to compute the approximation ratio of our algorithm on pq-graphs. Although progress has been made on this recurrence relation, a final solution was not found, and thus we encourage others to attempt to solve this recurrence relation.

On the maximum cut problem: A new 0.5-approximation algorithm 49

List of Figures

3.1 Example graph G = (V,E) for matrix multiplication...... 10 3.2 Auxiliary graph A(G) of the matrix multiplication example graph...... 10 3.3 Modified auxiliary graph A(G, W ) with W = (0, 1, 0) ...... 12 3.4 Possible final cut of the local search approach...... 18 3.5 A visualisation of two recursive calls of Trevisan’s algorithm...... 19 3.6 Graph visualising the approximation ratio of Trevisan’s algorithm using Desmos. 21 3.7 Visualisation of the area between two vectors vi and vj ...... 24 2 θ 3.8 Plot of π 1−cos(θ) from θ = 0 to θ = π, using Desmos...... 25 3.9 Example of an edge contraction...... 26 3.10 Example of the algorithm in action...... 27

4.1 Example of the algorithm in action...... 32 4.2 Example of connecting two forests in the algorithm...... 34 4.3 A graph with all its spanning trees...... 37 4.4 Calculation of the probability of generating this spanning tree...... 38

5.1 A visualisation of a pq-graph, where p << q...... 39 5.2 A visualisation of a cut {x, y} with corresponding edge probabilities...... 41

On the maximum cut problem: A new 0.5-approximation algorithm 51

List of Tables

5.1 Experimental results for p = 0.01, q = 0.50 ...... 47 5.2 Experimental results for p = 0.10, q = 0.50 ...... 48 5.3 Experimental results for p = 0.25, q = 0.50 ...... 48

On the maximum cut problem: A new 0.5-approximation algorithm 53

Bibliography

[1] Francisco Barahona, Martin Grötschel, Michael Jünger, and Gerhard Reinelt. An application of combinatorial optimization to statistical physics and circuit layout design. Operations Research, 36(3):493–513, 1988.1

[2] B. Bollobás and A. D. Scott. Max cut for random graphs with a planted partition. Combin- atorics, Probability and Computing, 13(4-5):451–474, 2004. 40, 49

[3] Herman Chernoff. A measure of asymptotic efficiency for tests of a hypothesis based on the sum of observations. Ann. Math. Statist., 23(4):493–507, 12 1952. 41

[4] Luca Chiantini, Jonathan D. Hauenstein, Christian Ikenmeyer, Joseph M. Landsberg, and Giorgio Ottaviani. Polynomials and the exponent of matrix multiplication. Bulletin of the London Mathematical Society, 50(3):369–389, jun 2018.8

[5] Henry Cohn, Robert Kleinberg, Balázs Szegedy, and Christopher Umans. Group-theoretic algorithms for matrix multiplication. volume 2005, pages 379– 388, 11 2005.8

[6] Don Coppersmith and Shmuel Winograd. Matrix multiplication via arithmetic progressions. Journal of Symbolic Computation, 9(3):251 – 280, 1990. Computational algebraic complexity editorial.8

[7] Artur Czumaj and Andrzej Lingas. Finding a Heaviest Vertex-Weighted Triangle Is not Harder than Matrix Multiplication. SIAM Journal on Computing, 39(2):431–444, jun 2009. 11

[8] M. R. Garey, David S. Johnson, and Larry J. Stockmeyer. Some simplified np-complete problems. In STOC, 1974.2

[9] Michel X. Goemans and David P. Williamson. Improved approximation algorithms for max- imum cut and satisfiability problems using semidefinite programming. J. ACM, 42(6):1115– 1145, November 1995. vii,2, 21

[10] Johan Håstad. Some optimal inapproximability results. J. ACM, 48(4):798–859, July 2001. 2

[11] Alon Itai and Michael Rodeh. Finding a minimum circuit in a graph. SIAM J. Comput., 7:413–423, 11 1978.8

[12] Sera Kahruman, Elif Kolotoglu, Sergiy Butenko, and I Hicks. On greedy construction heur- istics for the max-cut problem. Int. J. of Computational Science and Engineering, 1, 04 2007. 33, 49

[13] David R. Karger. Global min-cuts in rnc, and other ramifications of a simple min-cut al- gorithm, 1992. 26, 27, 28

[14] Richard M. Karp. Reducibility among Combinatorial Problems, pages 85–103. Springer US, Boston, MA, 1972.2

On the maximum cut problem: A new 0.5-approximation algorithm 55 BIBLIOGRAPHY

[15] Subhash Khot. On the power of unique 2-prover 1-round games. In Conference Proceedings of the Annual ACM Symposium on Theory of Computing, pages 767–775, 2002.2 [16] Wolfgang Kinzel. Static and dynamic properties of short range Ising spin glasses, pages 113– 126. 01 2006.1

[17] Erica Klarreich. Approximately Hard : The Unique Games Conjecture. Simons Foundation, pages 1–11, oct 2015.2 [18] François Le Gall. Powers of Tensors and Fast Matrix Multiplication. arXiv e-prints, page arXiv:1401.7714, Jan 2014.8 [19] Giorgio Parisi. Order parameter for spin-glasses. Phys. Rev. Lett., 50:1946–1948, Jun 1983.1

[20] Lester R Ford Jr and Delbert R Fulkerson. Maximal flow through a network. Canadian Journal of Mathematics, 8:399–404, 01 1956. 26 [21] Sartaj Sahni. Computationally Related Problems. SIAM Journal on Computing, 3(4):262– 279, 2005. 22

[22] José Soto. Improved analysis of a max cut algorithm based on spectral partitioning. SIAM Journal on Discrete Mathematics, 29, 01 2015. 20 [23] Volker Strassen. Gaussian elimination is not optimal. Numerische Mathematik, 13:354–356, 08 1969.8

[24] Luca Trevisan. Max cut and the smallest eigenvalue. Proceedings of the 41st annual ACM symposium on Symposium on theory of computing - STOC 09, 2009. vii,2, 18, 20 [25] Virginia Vassilevska Williams. Multiplying matrices faster than coppersmith-winograd. pages 887–898, 05 2012.8 [26] Ryan Williams. A new algorithm for optimal 2-constraint satisfaction and its implications. Theoretical Computer Science, 348(2):357 – 365, 2005. Automata, Languages and Program- ming: Algorithms and Complexity (ICALP-A 2004).2,8 [27] David P. Williamson. Lecture notes on Trevisan’s Inequality, September 2016. 18 [28] David P. Williamson. Lecture notes on Spectral Patitioning, September 2016. 18

[29] David Bruce Wilson. Generating random spanning trees more quickly than the cover time. Proceedings of the twenty-eighth annual ACM symposium on Theory of computing - STOC 96, page 296–303, 1996. 37

56 On the maximum cut problem: A new 0.5-approximation algorithm Appendix A

Python code

Python code, which was used for all graph related computations. Using networkNX, we pro- grammed algorithms for solving the maximum cut, as well as our own algorithm. Furthermore, we also programmed the creation of many different graphs to facilitate testing of different types o graphs.

# Imports # Import the time to get running times import time # Import random to allow for randomized output import random # Import os.path to get the path to input/ output folders import os.path # Import plt to plot graphs import matplotlib.pyplot as plt # Import numpy for numerical calculations import numpy as np

# Import nx to allow all graph related things from networkx import nx # Import bipartite to createa bipartition of the spanning tree from networkx.algorithms import bipartite

# Functions """ Givena set ns, compute allm-partitions This isa fast way to compute all possible bipartitions ofa graph. We will call this with all vertices and ask the algorithm to compute all 2-partitions We can use this for brute force""" def algorithm_u(ns, m): def visit(n, a): ps = [[] for i in range(m)] for j in range(n): ps[a[j + 1]].append(ns[j]) return ps

def f(mu, nu, sigma, n, a): if mu == 2: yield visit(n, a)

On the maximum cut problem: A new 0.5-approximation algorithm 57 APPENDIX A. PYTHON CODE

else: for v in f(mu - 1, nu - 1, (mu + sigma) % 2, n, a): yield v if nu == mu + 1: a[mu] = mu - 1 yield visit(n, a) while a[nu] > 0: a[nu] = a[nu] - 1 yield visit(n, a) elif nu > mu + 1: if (mu + sigma) % 2 == 1: a[nu - 1] = mu - 1 else: a[mu] = mu - 1 if (a[nu] + sigma) % 2 == 1: for v in b(mu, nu - 1, 0, n, a): yield v else: for v in f(mu, nu - 1, 0, n, a): yield v while a[nu] > 0: a[nu] = a[nu] - 1 if (a[nu] + sigma) % 2 == 1: for v in b(mu, nu - 1, 0, n, a): yield v else: for v in f(mu, nu - 1, 0, n, a): yield v

def b(mu, nu, sigma, n, a): if nu == mu + 1: while a[nu] < mu - 1: yield visit(n, a) a[nu] = a[nu] + 1 yield visit(n, a) a[mu] = 0 elif nu > mu + 1: if (a[nu] + sigma) % 2 == 1: for v in f(mu, nu - 1, 0, n, a): yield v else: for v in b(mu, nu - 1, 0, n, a): yield v while a[nu] < mu - 1: a[nu] = a[nu] + 1 if (a[nu] + sigma) % 2 == 1: for v in f(mu, nu - 1, 0, n, a): yield v else: for v in b(mu, nu - 1, 0, n, a): yield v if (mu + sigma) % 2 == 1: a[nu - 1] = 0 else:

58 On the maximum cut problem: A new 0.5-approximation algorithm APPENDIX A. PYTHON CODE

a[mu] = 0 if mu == 2: yield visit(n, a) else: for v in b(mu - 1, nu - 1, (mu + sigma) % 2, n, a): yield v

n = len (ns) a = [0]* (n + 1) for j in range(1, m + 1): a[n-m+j]=j-1 return f(m, n, 0, n, a)

""" Givena sets, return the powerset ofs""" def powerset(s): x = len (s) masks = [1 << i for i in range(x)] for i in range(1 << x): yield [ss for mask, ss in zip(masks, s) ifi& mask]

""" Generate graph with placed max cut""" def generate_max_cut_graph(n, p,q): # GetG_1 H = nx. erdos_renyi_graph(n, p) # GetG_2 I = nx.erdos_renyi_graph(n, p)

# Convert labels I = nx.convert_node_labels_to_integers(I, first_label = n) # Combine graph G = nx.compose(H,I)

# Add edges between the graphs for h in H.nodes(): for i inI.nodes(): # For each edge between nodes fromH,I: # If

# Return the graph returnG

""" The brute force algorithm that solves max cut optimally Only runs when there are 20 vertices or fewer to keep running time below 36 seconds""" def brute_force(G): if G.number_of_nodes() <= 20: # Get time for running time analysis t= time.time()

# Generate the list of all partitions

On the maximum cut problem: A new 0.5-approximation algorithm 59 APPENDIX A. PYTHON CODE

partitions = list(algorithm_u(list(G.nodes()), 2))

# Variables to keep track of the largest cut max_cut=0 max_cut_par = []

# Iterate over every partition for par in partitions: # Compute the cut size and compare it to the largest cut so far if nx.cut_size(G, par[0]) > max_cut: # If larger, replace the currently found max cut by the larger cut max_cut = nx.cut_size(G, par[0]) max_cut_par= par[0]

# Output display ([max_cut_par, set(G.nodes) - set(max_cut_par)],’ brute force algo’)

# Report time print("\n---%s seconds for brute force---"%(time.time() -t)) else: # Report that the number of nodes is too large print("\nThere are%s number of nodes, which is too large to brute force"% int(G.number_of_nodes()))

""" The algorithm implemented. It randomly adds edges until it isa spanning tree Only runs when the graph is connected, because elsea spanning tree can never occur""" def random_edge_algo(G, iterations): if nx.is_connected(G): # Initiate time for running time analysis t= time.time()

# Initialize variables to keep track of best val and cut best_cut_val = 0 best_cut = []

# Do the algorithm’iteration’ times for i in range(iterations): # Generate the partition partition = random_edge_algo_one_it(G)

# Check if the found partition is better if nx.cut_size(G, partition[0]) > best_cut_val: # If so, update the variables best_cut_val = nx.cut_size(G, partition[0]) best_cut = partition

# Display the partition display(best_cut,’randomized edge adding algo’)

60 On the maximum cut problem: A new 0.5-approximation algorithm APPENDIX A. PYTHON CODE

# Report time print("\n---%s seconds for random edge adding algo---"% (time.time()-t)) else: # Notify the user that the algorithm cannot be used print("\nThe graph is not connected, so we cannot implement the random_edge_algo")

""" One iteration of the random edge algo above""" def random_edge_algo_one_it(G): # Create an empty graph X = nx.Graph()

# Seta seed for the random generator random.seed()

# Get number of nodes n = G. number_of_nodes() # Put all the edges ina list lst = list(G.edges) # Shuffle the list to geta random order random.shuffle(lst)

# Check if it isa spanning tree for i in range(int(n - 1)): # Add an arbitrary edge such that it does not causea cycle # Pick an arbitrary edge from the edge set bool = False

while bool is False: # Pick an edge uniformly at random chosen_edge = lst.pop()

# Add the edge toX X.add_edge(chosen_edge[0], chosen_edge[1]) # Check ifa cycle is created try: # Try to finda cycle nx.find_cycle(X) # Remove ifa cycle is found X.remove_edge(chosen_edge[0], chosen_edge[1]) except : # No cycle is found, we break the while loop and adda new edge bool = True

# Compute the unique bipartition ofX return bipartite.sets(X)

""" that adds vertices rnadomly to one of the two partitions""" def dumb_random_algo(G): # Initiate time for running time analysis

On the maximum cut problem: A new 0.5-approximation algorithm 61 APPENDIX A. PYTHON CODE

t= time.time()

V1 = []# Initialize partition1 V2 = []# Initialize partition2

# For every vertex in the graph for vertex in G.nodes: # We flipa coin assign = random.choice([0, 1]) if assign == 0: # If it is heads, we append the vertex to V1 V1.append(vertex) else: # Else, we append it to V2 V2.append(vertex)

# Display partition display([V1, V2],’dumb random algo’)

# Report time print("\n---%s seconds for dumb random algo---"%(time.time ()-t))

""" Greedy algorithm that maximizes the maximum cut at each step Assumes that there are at least two vertices note by the way that this is not the greedy algorithm discussed in the thesis""" def greedy_algo(G): # Initiate time for running time analysis t= time.time()

V1 = [list(G.nodes())[0]]# Initialize partition1 V2 = [list(G.nodes())[1]]# Initialize partition2

# Assign each vertex to the smallest partition for vertex in list(G.nodes)[1:]: if len(V1) < len(V2): V1.append(vertex) else: V2.append(vertex)

display([V1, V2],’greedy algo’)

# Report time print("\n---%s seconds for greedy algo---"%(time.time()-t ))

""" Given the two partitions ofG, display the cut inG""" def display(par, title): # First draw the graph pos = dict() # Update the graph position with respect to the vertices in par 0 pos.update( (n, (1, i)) for i, n in enumerate(par[0]) )

62 On the maximum cut problem: A new 0.5-approximation algorithm APPENDIX A. PYTHON CODE

# Update the graph position with respect to the vertices in par 1 pos.update( (n, (2, i)) for i, n in enumerate(par[1]) )

# Draw the graph, can be commented out if running large tests #nx.draw(G, pos, with_labels= True)

# Variable for keeping track of the cut edges cut_edges = []

# Iterate over all edges for edge in G.edges: # Check if it isa cut-crossing edge if (edge[0] in par[0] and edge[1] in par[1]) or (edge[0] in par[1] and edge[1] in par[0]): # If so, append this to the set cut_edges.append(edge)

# Draw the cut, can be commented out if running large tests # Draw the normal edges red #nx.draw_networkx_edges(G, pos, edge_color=’r’) # Draw the edges in the cut green #nx.draw_networkx_edges(G, pos, edgelist= cut_edges, edge_ color=’g’) # Give title #plt.title(title) # Plot the graph #plt.show()

# Refeerence the global cut global cut # Assign the value of the cut to the global variable cut cut = len(cut_edges)

# If desired, add the value of the cut to the output file #file1.write(str(len(cut_edges))+"\n")

# Output the cut and its size print("The size of cut%s is%s"%(par[0], len(cut_edges)))

""" Givena graph_name in the imports folder, load this graph""" def import_graph(graph_name): # Create an empty graph G = nx.Graph() # Open filef with respect to the location with open(import_map + graph_name) as f: # For every line for num, line in enumerate(f, 1): # First line is the nodes, other lines are edges if num == 1: G.add_nodes_from(range(1,int(line.split()[0]))) else: G.add_edge(int(line.split()[0]), int(line.split() [1]) )

On the maximum cut problem: A new 0.5-approximation algorithm 63 APPENDIX A. PYTHON CODE

# Return the edges returnG

""" Create graph based on user input We can have: -A graph from the input files of bigmaq -A bipartite np graph =A regular nm graph - pq graph -a random regular graph""" def create_graph(): # Initialize graph to be created G = nx.Graph()

# Request type of graph from user input_graph = input("Type file name of graph or no:")

if input_graph!="no": # If file is given, import it G = import_graph(input_graph) else: # Generate random seed seed = 7251886649227049791#random.randrange(sys.maxsize) # Print random seed print("Seed for random generating:", seed)

# Request random type of graph from user type_random_graph = int(input("Choices: Bipartite np (1), Regular nm (2)")) if type_random_graph == 1: # Request vertices and edge chance vertices1 = int(input("How many vertices of partition 1?")) vertices2 = int(input("How many vertices of partition 2?")) edgechance = float(input("Edge chance?"))

# Generate graph G = bipartite.generators.random_graph(vertices1, vertices2, edgechance, seed)

elif type_random_graph == 2: # Request vertices and edges vertices = int(input("How many vertices?")) edges = int(input("How many edges?"))

# Generate graph G = nx. gnm_random_graph(vertices, edges, seed) elif type_random_graph == 3: # Request vertices and edges vertices = int(input("How many vertices in each partition?")) p = float(input("Edge chance in one partition?")) q= float(input("Edge chance between partitions?"))

64 On the maximum cut problem: A new 0.5-approximation algorithm APPENDIX A. PYTHON CODE

# Generate graph G = generate_max_cut_graph(vertices, p,q) elif type_random_graph == 4: # Vertices n = int(input("How many vertices?")) # Regular d = int(input("How many degrees for each vertex?")) # Create ifn* round(n**(1/2)) % 2 == 0: G = nx.random_regular_graph(round(n**(1/2)), n) else: G = nx.random_regular_graph(round(n**(1/2) + 1), n)

# Set the correct layout and display the graph nx. draw (G, pos=nx.fruchterman_reingold_layout(G), with_labels= True ) plt .title("Generated graph") plt .show()

returnG

"""STARTOFTHEMAINROUTINE""" # Get starting time start_time= time.time()

""" Get import and export locations""" import_map =’C:/Users/s165048/Desktop/KWARTIEL3/2WH40/Python/ Inputs/’ export_map =’C:/Users/s165048/Desktop/KWARTIEL3/2WH40/Python/ Outputs/’

# create export file file1 = open(os.path.join(export_map,"graph.txt"),"a")

# Create graph G = nx.Graph() scores = []

# Request vertices and edges vertices = float(input("How many vertices in eacht set of the partition?")) p = float(input("Edge chance in one set of the partition?")) q= float(input("Edge chance between different sets of the partition?")) delta = float(input("Delta value?"))

# Writep,q, delta to file file1 .write("p=" + str(p) +",q=" + str(q) +", delta="+ str(delta) +".\n\n")

# Initiate cut variable cut=0

On the maximum cut problem: A new 0.5-approximation algorithm 65 APPENDIX A. PYTHON CODE

# Amount of iterations the test should do for i in range(100): # Generate graph, can be commented out if different graphs are required G = generate_max_cut_graph(400, p,q)

# Createa graph based in input, can be commented out ifa fixed graph is desired #G= create_graph()

# Ask the desired amount of iterations for the random algo #iterations= int(input("How many iterations?"))

# Do the random edge adding algorithm onG random_edge_algo(G, 1)

# If one graph hasa bad approximation ratio, show it to see how it looks if((float(float(cut))/(float(400*400*q*(1 + delta)))) < 0.51): nx. draw (G, pos=nx.fruchterman_reingold_layout(G), with_ labels = True) plt .title("Generated graph") plt .show()

# Run the dumb random algo inG dumb_random_algo(G)

# Run the greedy algo onG greedy_algo(G)

# Do the brute force algorithm onG brute_force(G)

# Show the estimated max cut for iteration, if we use pq graphs print("estimated max cut is%s for iteration%s\n"%(int(( vertices*vertices*q)), (i + 1)))

# Show the estimated approximation ratio, based on delta andq print("estimated approximation ratio%s\n"%(float(float(cut)) /(float(i*i*q*(1 + delta)))))

# Write to file #file1.write(str(i)+","+ str(float(float(cut))/(float(i*i*q *(1+ delta))))) #file1.write("\n")

# Append the approximation ratio to the scores scores .append((float(float(cut))/(float((1 + delta)*i*i*q)))) # Write it to file #file1.write(str((float(float(cut)))))

# Print total duration print("\n---%s seconds---"%(time.time()- start_time))

66 On the maximum cut problem: A new 0.5-approximation algorithm APPENDIX A. PYTHON CODE

# Show the mean of all scores print(np.mean(scores))

# Write the mean to file file1 .write("\nAverage:") file1 .write(str(np.mean(scores))) file1 .write("\n------\n")

# Close the file file1 .close()

On the maximum cut problem: A new 0.5-approximation algorithm 67 Appendix B

R code

We used R to compute probability related problems. Below is the R code used to compute the chernoff bound values for pq-graphs, given an n, p, and q.

#R code used to compute the chernoff bound values for pq graphs, given ann,p, andq. # For both the loose and strict chernoff bound

# Variables used in the graph # The amount of vertices in each set of the partition ofa pq graph n = 200 # The edge change between vertices in the same set(both inR or both inB) of the partiton p = 0.001 # The edge change between vertices from different sets(one inR and one inB) of the partition q = 0.50

# Variable for the total probability using the strict chernoff bound total = 0 # Variable for the total probability using the loose chernoff bound totalloose = 0 # The total amount of partitions considered totalparts = 0

# Variable to keep track of the amount of vertices ofR in the first set of the cut a = 0

# We sum froma=0 ton while (a <= n) { # Variable to keep track of the amount of vertices ofB in the first set of the cut b = 0 # We sum fromb=0 ton while (b <= n) { # We calculate the corresponding mu value mu = p* (a*(n-a)+b* (n - b)) +q* (a*(n-b)+b*(

68 On the maximum cut problem: A new 0.5-approximation algorithm APPENDIX B. R CODE

n - a))

# Mu is equal to zero ifa=b=0 ora=b=n, so we leave these out if ((a > 0 || b > 0)&& (a

# We calculate the single probability of the strict chernoff bound singleprob = (exp(delta)/ (1 + delta)^(1+delta))^mu # We calculate the single probability of the looser chernoff bound singleprobloose = exp((-delta^2* mu)/ (2 + delta))

# We calculate the total probability of the strict chernoff bound # for one given tuple(a,b) totalprob = choose(n, a)* choose(n, b)* singleprob/2

# We calculate the total probability of the loose chernoff bound # for one given tuple(a,b) totalprobloose = choose(n, a)* choose(n, b)* singleprobloose/2

totalparts = totalparts + choose(n, a)* choose(n, b)/2

# We add the added probability to the total of all probabilities # for the strict chernoff bound total = total + totalprob # We add the added probability to the total of all probabilities # for the loose chernoff bound totalloose = totalloose + totalprobloose } # We incrementb b = b + 1 } # We incrementa a = a + 1 }

# We output the total probability of the strict chernoff bound total # We output the total probability of the loose chernoff bound totalloose

# We output the lower bound on the probability ofa maximum cut # givenn,p,q, remaining belown^2q* (1+ delta) # for the strict chernoff bound 1 - total

# We output the lower bound on the probability ofa maximum cut

On the maximum cut problem: A new 0.5-approximation algorithm 69 APPENDIX B. R CODE

# givenn,p,q, remaining belown^2q* (1+ delta) # for the looser chernoff bound 1 - totalloose

70 On the maximum cut problem: A new 0.5-approximation algorithm