Version: 0.6.22

Problem Set#

Objectives:

Practice the concepts introduced in the Graphs module

This problem set is optional practice. Work on it wherever you like, alone or in groups, and with any resources you find useful. Unless a problem says otherwise, answer with pen and paper or in pseudocode; implementation tasks can be done in any programming language.

Problems are roughly ordered by difficulty, from ★ (warm-up) to ★★★★ (challenging). The last problem introduces a topic that is not covered in the lectures: It starts with a short background that gives you everything you need.

Every problem comes with a solution, hidden in a dropdown below it. Give the problem a real try before you open it: Most of the learning happens while you are stuck.

The set closes with three case studies. These are not exercises with a single right answer, but open-ended explorations of famous graph problems: Easy to state, sometimes very hard (or even impossible, as far as anyone knows) to solve. Go as far as your curiosity takes you. Instead of a solution, each one comes with a dropdown of resources and ideas to help you dig further.

Core Problems#

Exercise 1 (Handshakes ★)

Seven people meet at a party, and some of them shake hands. We model the party as a simple graph, where vertices are people and an edge means that two people shook hands, as shown on Fig. 26. Recall from Lecture 6.1 that the degree of a vertex is the number of edges incident to it.

../_images/handshakes.svg

Fig. 26 Who shook hands with whom#

  1. Give the degree of every vertex. Add them up, and compare the sum with the number of edges. Explain why, in any simple graph \(G = (V, E)\), we have

    \[\sum_{v \in V} \mathrm{degree}(v) = 2 \cdot |E|\]
  2. Deduce that every graph has an even number of vertices with an odd degree. Check it on the party. Could seven people each shake hands with exactly three others?

  3. At the next party, everyone shakes hands with everyone else exactly once. Which graph from the lecture’s jargon is this? How many handshakes happen with seven people? With \(n\) people?

  4. Now consider a directed graph, for instance the food web of Fig. 1.31. What becomes of the formula from Question 1 when we count in-degrees and out-degrees?

  5. Show that at any party with at least two people, two people shook the same number of hands.

    Hint: With \(n\) people, which degrees are possible? Can someone who shook no hands be at the same party as someone who shook everyone’s hand?

Exercise 2 (Reading the Matrix ★)

Lecture 6.1 describes a graph by its adjacency matrix: The cell \(a_{ij}\) holds the number of edges from vertex \(i\) to vertex \(j\). Consider the following two matrices, where the vertices are ordered alphabetically, \((A, B, C, D, E)\) and \((P, Q, R, S)\):

\[\begin{split}A = \begin{bmatrix} 0 & 1 & 0 & 0 & 1 \\ 1 & 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & 1 & 0 \\ 0 & 0 & 1 & 0 & 1 \\ 1 & 1 & 0 & 1 & 0 \end{bmatrix} \qquad M = \begin{bmatrix} 0 & 1 & 1 & 0 \\ 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 0 \end{bmatrix}\end{split}\]
  1. Draw the graph of \(A\). Without drawing anything, how can you tell from the matrix alone that it is undirected, and that it has no loop? How do you read the degree of a vertex from the matrix?

  2. Draw the graph of \(M\). What do the sum of a row and the sum of a column tell you? Which features of \(M\) prevent it from describing a simple graph? What would an entry equal to 2 mean?

  3. Compute the matrix product \(A^2 = A \times A\). What does the entry in row B, column D count? What about the entries on the diagonal?

    Hint: Write down the formula for the entry \((i, j)\) of the product, \(\sum_k a_{ik} \cdot a_{kj}\), and ask when a term \(a_{ik} \cdot a_{kj}\) equals 1.

  4. Generalise: What does the entry \((i, j)\) of \(A^k\) count? Use \(A^3\) to count the triangles (three vertices that are all adjacent to each other) in the graph of \(A\).

    Hint: You only need the diagonal of \(A^3\). How many times does each triangle show up there?

Exercise 3 (Mind the Map ★)

In 1933, Harry Beck redrew the map of the London Underground. The new map ignored geography: Stations sit on a grid, lines only run horizontally, vertically, or at 45°, and the distances between stations are all roughly equal. It was a huge success, and most subway maps today, including the one of Oslo shown on Fig. 1.29, follow the same idea. A subway map is really a drawing of a graph.

  1. What information does such a map keep, and what does it throw away? Give at least two advantages and two drawbacks of drawing a transit network as a graph rather than as a geographic map.

Consider now the fictional network shown on Fig. 29, with three lines: Red (A–B–C–D–E), Green (A–F–J), and Blue (G–F–E–H). Riding between two neighbouring stations takes 2 minutes, and changing lines at a transfer station (double circles) takes 5 minutes.

../_images/subway.svg

Fig. 29 A fictional subway with three lines: Red (solid), Green (dashed), and Blue (dotted)#

  1. Model the network as a simple graph whose vertices are the stations. Which algorithm finds the route from A to E with the fewest stops? Which route does it find, and how long does that trip really take? Is there a faster one?

  2. The station graph forgets which line an edge belongs to, so it cannot account for transfers. Design a better graph, where every vertex is a platform, that is, a pair (station, line). Which edges does it need, and with which weights? Use it to find the quickest trip from A to E, and from A to H. Which algorithm do you use?

    Hint: You may start your trip at A on any line, without paying for a transfer. How can the graph capture that?

  3. Real networks raise more modelling questions. For each of the following situations, explain how you would change the graph:

    • a circle line that runs in one direction only;

    • two lines that share the same track between two stations;

    • two stations that are far apart on the map, but a two-minute walk apart in the street;

    • waiting for the next train, which depends on how often each line runs.

Exercise 4 (Lost in Traversal ★★)

Consider the undirected graph shown on Fig. 31.

../_images/traversal.svg

Fig. 31 An undirected graph with ten vertices#

  1. Run the depth-first and the breadth-first traversals from Lecture 6.1, starting from A, and give the order in which they visit the vertices. When several neighbours are pending, visit them in alphabetical order (for the depth-first traversal, push them on the stack in reverse alphabetical order, as in the lecture’s example).

    For each traversal, draw its traversal tree: The tree whose edges are the ones through which each vertex was first reached. Add the other edges of the graph as dashed lines.

  2. Look at the dashed edges of each tree. In the breadth-first tree, how far apart can the two ends of a dashed edge be, in levels? In the depth-first tree, is one end of a dashed edge always an ancestor of the other? Explain why.

  3. Neither traversal reaches H, I, or J. Write a procedure components(graph) that returns the number of connected components of an undirected graph, in \(O(|V| + |E|)\) time.

  4. A classmate suggests a way to detect cycles: “Run a traversal, and as soon as we meet a vertex that is already visited, there is a cycle”. Run their idea on the component {H, I, J}, which is a tree. What goes wrong? Write a procedure hasCycle(graph) that works for any undirected graph, connected or not.

  5. Does your procedure still work on a directed graph? Find a small directed graph with no cycle on which it reports one.

Exercise 5 (Pick Your Path ★★)

Lecture 6.2 presents four shortest-path algorithms: Breadth-first search (BFS), Dijkstra, Bellman-Ford, and Floyd-Warshall. This problem is about choosing between them, not about running them.

  1. For each of the following situations, pick the algorithm you would use, and justify your choice. Estimate the number of basic operations it needs.

    1. A social network with \(10^8\) users and \(10^{10}\) friendships wants to tell you how many “handshakes” separate you from another user.

    2. A car navigation app looks for the quickest route from your position to a destination, on a road network with \(10^6\) junctions and \(2.5 \cdot 10^6\) road segments, weighted by their travel times.

    3. A ferry company serves 15 ports and prints, in its timetable, the quickest connection between every pair of ports.

    4. An electric car spends energy driving uphill, but recovers some when it drives downhill (regenerative braking). We weigh each road segment by the energy it costs, which is negative downhill, and look for the route from Trondheim to Bergen that drains the battery the least.

    5. In the subway of Exercise 3, a traveller does not care about time, but wants as few transfers as possible.

    6. An online game wants the number of hops between every pair of its 500 servers, which are connected by 2000 links.

  2. All four algorithms rely on relaxation, but they relax the edges in different orders. For each algorithm, explain in one or two sentences in which order it relaxes the edges, and why this order is enough to find the shortest paths.

  3. Run Dijkstra’s algorithm on a graph where every edge has weight 1. Show that its priority queue then behaves exactly like the plain queue of BFS: Vertices come out in the same order.

    Hint: Show that, at any time, the priorities in the queue differ by at most 1, and that new vertices always enter with the largest priority.

  4. A classmate argues: “Bellman-Ford handles everything Dijkstra handles, and more. Floyd-Warshall even gives all the pairs at once. Why not always use Floyd-Warshall?” Answer them, using Situation b as an example. Assume a computer that relaxes \(10^8\) edges per second.

Exercise 6 (When Dijkstra Lies ★★)

Lecture 6.2 warns that Dijkstra’s algorithm fails with negative weights, and that negative cycles break the very notion of shortest path. Let us look at both warnings more closely.

  1. Assume that, once Dijkstra’s algorithm extracts a vertex from the queue, its distance is final and never changes again. Find a directed graph with as few vertices as possible on which the algorithm returns a wrong distance. Which step of the correctness proof in the lecture breaks?

    The pseudocode of the lecture keeps relaxing edges towards vertices that are already extracted, so it may still fix your example. Find a graph on which even that version returns a wrong distance.

  2. Consider the graph shown on Fig. 33. For each vertex, give its shortest distance from S, which is either a number, \(-\infty\), or \(+\infty\) (unreachable). What does the Bellman-Ford algorithm of the lecture report from S?

    ../_images/negative.svg

    Fig. 33 A directed graph with negative weights#

    Describe how to extend Bellman-Ford so that it computes the three kinds of answers, for every vertex, instead of stopping at “negative cycle detected”.

  3. A classmate wants to find shortest paths with negative weights in an undirected road network, by replacing every undirected edge with two arcs, one in each direction, and running Bellman-Ford. Why is this hopeless as soon as a single edge has a negative weight?

  4. Another classmate wants to get rid of negative weights altogether: “Add the same constant to every edge, large enough to make all the weights non-negative, then run Dijkstra”. Show, with a small example, that this does not work. Why does it fail?

  5. Here is a trick that does work. Give every vertex \(v\) a number \(h(v)\), and replace the weight of each arc \((u, v)\) with

    \[w'(u, v) = w(u, v) + h(u) - h(v)\]

    Show that, for any two vertices \(s\) and \(t\), every path from \(s\) to \(t\) changes by the same amount. Deduce that the shortest paths stay the same.

    Hint: Write the new length of a path \(s = v_0, v_1, \ldots, v_k = t\), and look at what happens to the \(h\) terms.

Exercise 7 (Prim and Kruskal by Hand ★★)

Consider the weighted graph shown on Fig. 35.

../_images/spanning_exercise.svg

Fig. 35 A weighted graph with six vertices#

  1. Trace Prim’s algorithm, starting from A. List the edges in the order in which the algorithm adds them to the tree.

  2. Trace Kruskal’s algorithm. List the edges in the order in which it adds them, and say which ones it skips.

  3. Do the two algorithms produce the same tree? Why, or why not?

Exercise 8 (Cheapest Cables ★★★)

A company wants to connect six offices with network cables. The possible cables and their costs are shown on Fig. 37. The cheapest network that connects all the offices is a minimum spanning tree (MST), as explained in Lecture 6.3.

../_images/cables.svg

Fig. 37 Possible cables between six offices, with their costs#

  1. Run Prim’s algorithm from A, then Kruskal’s algorithm. Give the edges in the order in which each algorithm adds them, and the total cost. Do they find the same tree? How many different MSTs does this graph have?

  2. The tree connects A and D. Is the path between them in the tree a shortest path from A to D in the graph? What does this tell you about the difference between an MST and the shortest paths of Lecture 6.2?

  3. Show that, when all the weights are different, the graph has exactly one MST.

    Hint: Assume two different MSTs \(T_1\) and \(T_2\), and consider the lightest edge \(e\) that belongs to one of them but not to the other. What happens if you add \(e\) to the other tree?

  4. The lecture states the cycle property: The heaviest edge of a cycle cannot belong to an MST (if it is the only heaviest one). This suggests a third algorithm, sometimes called reverse-delete: Go through the edges from the heaviest to the lightest, and delete each one, unless deleting it would disconnect the graph. Run it on the offices. Explain why the result is an MST, and give its time complexity. How does it compare with Kruskal’s?

  5. The network is built. A supplier now offers a new cable between two offices \(u\) and \(v\), at cost \(w\). Explain how to update the MST in \(O(|V|)\) time, without running Kruskal or Prim again. Apply it to a new cable A–D at cost 4, then to a new cable A–E at cost 5.

Exercise 9 (Network Design ★★★)

A city wants to connect eight neighborhoods, A to H, with fiber optic cables. The table below gives the cost (in millions) of laying a cable directly between two neighborhoods. A dash means that no cable can be laid between them.

A

B

C

D

E

F

G

H

A

·

13

8

26

27

14

–

21

B

13

·

–

–

–

3

2

28

C

8

–

·

–

–

–

25

18

D

26

–

–

·

19

–

29

–

E

27

–

–

19

·

–

4

–

F

14

3

–

–

–

·

–

–

G

–

2

25

29

4

–

·

–

H

21

28

18

–

–

–

–

·

Find a minimum spanning tree using Prim’s algorithm, starting from A, and then using Kruskal’s algorithm. What is the minimum total cost?

Exercise 10 (Why Is the Cheapest Tree Unique? ★★★)

If all the edge weights in a connected graph are different, then there is only one minimum spanning tree. Explain, in your own words, why this is the case.

Hint: Suppose there are two different minimum spanning trees, and think about swapping one edge for another.

Exercise 11 (Who’s in Charge? ★★★)

Kruskal’s algorithm needs to know whether two vertices already belong to the same component. Lecture 6.3 introduces the disjoint sets abstract data type for this, with two operations: find(x) returns a representative of the set that contains \(x\), and union(x, y) merges the sets of \(x\) and \(y\). Let us implement it on the elements \(1, \ldots, n\).

The simplest idea, called quick-find, stores in an array the label of the set of every element: find reads the label, and union relabels every element of one set with the label of the other.

  1. What are the time complexities of find and union with quick-find? What does this give for Kruskal’s algorithm?

A better idea is a forest: Each set is a tree, whose root is the representative, and each element only stores its parent. A root is its own parent.

find(x):
   while parent[x] ≠ x:
      x = parent[x]
   return x

union(x, y):
   rx = find(x)
   ry = find(y)
   if rx ≠ ry:
      parent[rx] = ry
  1. Start with eight singletons, and run union(1, 2), union(1, 3), union(1, 4), and so on, up to union(1, 8). Draw the forest at the end. How many parent links does each call to find(1) follow? What is the total cost of these unions, for \(n\) elements?

  2. Union by size changes one thing: Each root keeps the size of its tree, and union always attaches the root of the smaller tree under the root of the larger one (on a tie, rx goes under ry). Run the same unions again, and draw the forest. Then find a sequence of unions on eight elements for which union by size still builds a tree of height 3.

    Show that, with union by size, a tree of \(n\) elements never has a height larger than \(\log_2 n\).

    Hint: When does the depth of an element increase? What happens to the size of its tree at that moment?

  3. Path compression is another improvement: After find(x) has found the root, it makes every element it went through point directly to the root. Write find with path compression, and run find(1) on the forest of Question 2. Draw the result.

  4. With both improvements, a sequence of \(m\) operations on \(n\) elements takes \(O(m \cdot \alpha(n))\) time, where \(\alpha\) grows so slowly that \(\alpha(n) \leq 4\) for any \(n\) you will ever meet (Tarjan, 1975). We do not ask you to prove it! But if Kruskal’s algorithm has to sort the edges in \(O(|E| \log |E|)\) anyway, does the choice of implementation matter at all? Describe a situation where it does.

    Finally, explain how to use disjoint sets to detect a cycle in an undirected graph, as in Exercise 4.

Going Further#

This problem goes beyond the lectures. The assignment problem itself is fair game: It has come up on an earlier exam, and modelling it as a graph (Questions 1 and 2) uses nothing but this module. The Hungarian algorithm, however, is not part of the syllabus, and you are not expected to know it by heart. The background below gives you every step, and the exercise simply takes you through them, as a guided tour of how a classic algorithm on a weighted bipartite graph works and why it is correct.

Exercise 12 (Mentor Matchmaking ★★★★)

Background. Four students, Ada, Bo, Cy, and Dee, each need a mentor, and four mentors, Kari, Lars, Mia, and Nils, can each take one student. Every student ranks the mentors from 1 (favourite) to 4:

Kari

Lars

Mia

Nils

Ada

1

2

3

4

Bo

4

3

1

2

Cy

1

3

2

4

Dee

1

2

3

4

We look for an assignment, which gives each student a different mentor, and we want the sum of the ranks to be as small as possible. This is the assignment problem. The Hungarian algorithm (Kuhn, 1955; Munkres, 1957) solves it on an \(n \times n\) matrix of costs, here the ranks. There is no need to memorise it; just follow the steps:

  1. Subtract from every row its smallest entry.

  2. Subtract from every column its smallest entry.

  3. Cover all the zeros of the matrix with as few lines (whole rows or whole columns) as possible. If \(n\) lines are needed, we can pick \(n\) zeros, no two in the same row or column: This is an optimal assignment, and we stop.

  4. Otherwise, let \(m\) be the smallest entry that no line covers. Subtract \(m\) from every uncovered entry, add \(m\) to every entry covered by two lines, and go back to Step 3.

Step 3 relies on a theorem by Dénes Kőnig (1931), which gave the algorithm its name: The smallest number of lines that cover all the zeros equals the largest number of zeros we can pick with no two in the same row or column. In graph terms, take the bipartite graph whose edges are the zeros: Picking zeros is a matching, and covering them with lines is a vertex cover.

Problem.

  1. Model the situation as a weighted graph. What are the vertices, the edges, and the weights? What does an assignment correspond to? How many different assignments are there for 4 students? For 20? How long would it take to try them all at \(10^9\) assignments per second?

  2. Two natural strategies:

    • First come, first served: The students choose in alphabetical order, each one taking their favourite mentor among those still free.

    • Happiest first: Repeatedly assign the pair with the smallest rank among the students and mentors still free (break ties any way you like).

    Run both strategies. Then find the best assignment, by reasoning rather than by trying all of them.

    Hint: Three students rank Kari first. How many of them can have a rank of 1?

  3. Run the Hungarian algorithm on the table. Give the matrix after Steps 1 and 2, then after every round of Step 4, together with the lines you used. Give the final assignment and its total.

  4. Let us see why the algorithm is correct, in four steps.

    1. Show that subtracting the same number from every entry of a row (or of a column) does not change which assignments are optimal.

    2. Show that, if all entries are non-negative, an assignment that only uses zeros is optimal.

    3. Show that Step 4 has the same effect as subtracting \(m\) from every uncovered row and adding \(m\) to every covered column. Deduce that Step 4 never makes an entry negative, and that it does not change the optimal assignments either.

    4. Keep track of the total \(L\) of everything subtracted so far (rows and columns, minus what was added back). Show that \(L\) is a lower bound on the cost of any assignment, and that every round of Step 4 increases it. Deduce that the algorithm stops when the costs are integers.

    Hint for d: With \(r\) covered rows and \(k\) covered columns, we have \(r + k < n\). How many uncovered rows are there?

  5. Real life is messier. Explain how to adapt the method to each of the following situations:

    • Each mentor can take two students, and there are eight students.

    • There are five students but only four mentors, so one student gets none.

    • Three students rank the mentors exactly in the same order (Kari, Lars, Mia, Nils), and Dee ranks them Kari 2, Lars 4, Mia 1, Nils 3. Compute the best assignment. Is it fair? What would you minimise instead, and how?

Case Studies#

The problems above all have a solution. The three case studies below are different: Each one is a famous graph problem that is easy to explain at a dinner party, and surprisingly hard to solve. The first questions are within reach; the last ones open onto problems that keep researchers busy today. There is no solution to look up. Instead, each case study comes with a dropdown of ideas and resources to help you go further. Pick the one that tickles your curiosity.

Exercise (Exam Timetabling)

Every semester, NTNU schedules thousands of exams. Two exams that share at least one student cannot take place at the same time. We can draw this as a conflict graph: Courses are the vertices, and an edge connects two courses that share a student. Giving each course a time slot such that adjacent courses get different slots is called colouring the graph, with slots as colours. The smallest number of colours a graph needs is its chromatic number, written \(\chi(G)\). Graph colouring appears on the list of graph problems in Lecture 6.1, among the “difficult” ones.

../_images/exams.svg

Fig. 40 The conflict graph of eight courses#

  1. Find a timetable for the eight courses of Fig. 40 with as few slots as you can. A friend says: “I cannot find four courses that all conflict with each other, so three slots must be enough”. Are they right?

  2. The greedy strategy goes through the courses in some order, and gives each one the first slot that none of its scheduled neighbours uses. Try it with a few different orders. Show that it never needs more than \(\Delta + 1\) slots, where \(\Delta\) is the largest degree. Show also that, for every graph, some order makes greedy optimal. Why does this not solve the problem?

  3. When are two slots enough? Design an algorithm that decides it in \(O(|V| + |E|)\) time.

    For three slots, nobody knows an efficient algorithm, and most researchers believe that none exists. How many timetables would a brute-force search try for 300 courses and 3 slots?

  4. A Sudoku is a colouring problem in disguise. Describe its graph: What are the vertices, the edges, and the colours? How many edges are there? Write a program that colours a graph by backtracking (try a colour, go on, undo it when you get stuck), and use it to solve a Sudoku.

  5. Colour a map of the counties of Norway, so that neighbouring counties get different colours. How many colours do you need? The four colour theorem says that four colours are enough for any map. Why does a map never need five colours, while some graphs do?

  6. Open-ended: Find real conflict data, or one of the benchmark graphs used by researchers (see the resources), and compare greedy with a smarter order, such as largest degree first or DSatur. How close to the best known answer do you get?

Exercise (Your Friends Are More Popular)

In 1991, the sociologist Scott Feld published a paper with a provocative title: Why Your Friends Have More Friends Than You Do. Feld showed that, on average, your friends really do have more friends than you, and this has nothing to do with your personality. It is a property of graphs. Let us check it on the friendship graph of Lecture 6.1, reproduced on Fig. 43.

../_images/friendship.svg

Fig. 43 The friendship graph from Lecture 6.1#

  1. What is the average number of friends per person? For each person, compute the average number of friends of their friends. How many people have fewer friends than their friends do on average?

  2. Here is another way to measure “the friends of my friends”: Pick a friendship (an edge) at random, then one of its two ends at random, and count that person’s friends. Show that the average result is \(\sum_v d(v)^2 / \sum_v d(v)\), where \(d(v)\) is the degree of \(v\), and that it is always at least the average degree. When are they equal? Compute it on the graph.

  3. The average from Question 1 (per person first, then over everyone) is a different number. Is it also always at least the average degree?

  4. Feld’s title suggests something stronger: That most people have fewer friends than their friends do. Find a graph where the friends are more popular on average, in the sense of Question 2, but where fewer than half of the people have fewer friends than their friends.

  5. Download a real social network, such as the Facebook graph from SNAP (see the resources), and compute the three numbers: The average degree, the average of Question 2, and the fraction of people who have fewer friends than their friends. How strong is the paradox in real life?

  6. Open-ended: The paradox has practical uses. During an epidemic, who gets infected first, a random person or a random person’s friend? If you could vaccinate only 1% of a population whose graph you do not know, whom would you pick? Does the paradox hold for followers on a directed network, such as Instagram or Bluesky?

Exercise (The Party Problem)

Here is a game for two players, called Sim. Draw six dots on a sheet of paper. Each player has a pen of their own colour, say red and blue. Taking turns, each player draws a line between two dots that are not yet connected. The first player to complete a triangle of their own colour, with three dots as corners, loses. Lines of the other colour do not count.

  1. Play a few games of Sim with a friend. Did any game end in a draw, with all 15 lines drawn and no single-coloured triangle? Try to colour all the lines on purpose, with no single-coloured triangle.

  2. Show that Sim can never end in a draw. Said differently: At any party of six people, there are always three people who all know each other, or three who are all strangers.

    Hint: Pick one dot. It has five lines. What can you say about their colours?

  3. Would a game of Sim with five dots always have a loser?

  4. Look at the friendship graph of Fig. 43. Are there three people who all know each other? Mathematicians know that, among any nine people, there are always three mutual friends or four mutual strangers. Find the four strangers. In the vocabulary of Lecture 6.1, what are three mutual friends and four mutual strangers?

  5. Programming challenge: Among any 18 people, there are always four mutual friends or four mutual strangers. But 17 people are not enough: Find a friendship graph on 17 people with neither. Write a program that checks a candidate graph, then one that looks for one, for instance by starting from a random graph and flipping the edges that take part in the most bad groups of four.

  6. The smallest number of people that guarantees \(k\) mutual friends or \(k\) mutual strangers is the Ramsey number \(R(k, k)\). We know that \(R(3,3) = 6\) (Question 2) and \(R(4,4) = 18\) (Question 5). For \(R(5,5)\), nobody knows: It lies somewhere between 43 and 46. How many ways are there to colour the lines between 43 dots in red and blue? Why can’t we just check them all?