Recitation 5

Recitation notes for the week of September 25, 2024.

Q1 Part (b)

For part (b) you should use the graph from part (a) to come up with an algorithm that will in time $O(p^2+f)$ (where $f=|E|$) seat the ADFs in an admissible seating. Note that the runtime $O(f+p^2)$ is always $O(p^2)$.

There might be a reduction to a problem that you have seen in class.

Homework 3, Question 2

We first recall the question:

The Problem

A 4-clique in a graph $G=(V,E)$ is a set of four distinct vertices $\{u,v,w,x\}$ such that $(u,v),(v,w),(w,x),(x,u),(u,w),(v,x)\in E$. (Note that $G$ is undirected.) In this problem you will design a series of algorithms that given a connected graph $G$ as input, lists all the $4$-cliques in $G$. (It is fine to list one $4$-clique more than once.) We call this the 4-clique listing problem (duh!). You can assume that as input you are given $G$ in both the adjacency matrix and adjacency list format. For this problem you can also assume that $G$ is connected.

Sample Input/Output pair

Question 2, part (a)

The Problem

Present an $O(n^4)$ time algorithm to solve the $4$-clique listing problem.

Algorithm Idea

Let us assume we have access to a function Check-if-4-clique that takes as input $G=(V,E)$ and four vertices $u,v,w,x\in V$ and outputs true if $\{u,v,w,x\}$ is a $4$-clique in $G$ and false otherwise.

Then the algorithm is simple: just go through all possible $n^4$ $4$-tuples $\{u,v,w,x\}$ and if Check-if-4-clique$(G,u,v,w,x)$ outputs true then we add $\{u,v,w,x\}$ to the output.

Duplicates

The above algorithm would output the same set $\{u,v,w,x\}$ $24$ times but that is OK for this problem. As long as you (1) only output $4$-cliques; (2) output all $4$-cliques and (3) maintain the given time bound, you can have duplicates.

Exercise

Show that Check-if-4-clique can be implemented in $O(1)$ time.

Algorithm Details

Even though this is not needed for your HW submission, we write down the details of the $O(n^4)$ time algorithm (assuming Check-if-4-clique as a blackbox of course):

                                    Let GL and GM be the adjacency list and adjacency matrix representation of G (both are input).
                                    # GL is an array of pointers to linked list. The indices to vertices are in GL.keys()

                                    #Get the set of vertices
                                    V = GL.keys()

                                    L = null

                                    #Cycle through all 4-tuples
                                    for u in V:
                                        for v in V:
                                            for w in V:
                                                for x in V:
                                                    if Check-if-4-clique(GM,u,v,w,x) == true:
                                                        Add {u,v,w,x} to L

                                    return L
                                

Question 2, part (b)

The Problem

Present an $O(m^2)$ time algorithm to solve the $4$-clique listing problem.

A Comment

We conclude with a comment:

Homework 3, Question 3

One property of BFS that is useful for Q3 on HW 3:

BFS and distance

Say we run BFS from node $s$ in graph $G=(V,E)$ and let the layers be denoted by $L_0,L_1,\dots$. If $u\in L_i$ for any $u\in V$ and $i\ge 0$, then we have that the distance between $s$ and $u$ is exactly $i$. This is (3.3) in the textbook.

Please see the textbook for a proof of this claim.

Further Reading