summaryrefslogtreecommitdiffstats
path: root/main.tex
blob: 28c54bd53742bf4a72829950660182748fc44d5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lachaise Assignment
% LaTeX Template
% Version 1.0 (26/6/2018)
%
% This template originates from:
% http://www.LaTeXTemplates.com
%
% Authors:
% Marion Lachaise & François Févotte
% Vel (vel@LaTeXTemplates.com)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{article}
\input{structure.tex}

\title{CENG567: Homework \#2}
\author{Yiğit Sever}
\date{\today}

\addbibresource{mylib.bib}

%----------------------------------------------------------------------------------------

\begin{document}

\maketitle

\section{Checking Consistency of Judgements}%
\label{sec:checking_consistency_of_judgements}

Given the collection of $n$ butterflies and a potential judgement between every pair (or not if the judgement is ambiguous), we have a graph $G = (V, E)$ with $n = |V|$ vertices and $|E| = m \le \frac{n(n-1)}{2}$ edges, with every edge $(i, j) \in E$ labelled either \enquote{same} or \enquote{different}, assuming $(i,j)$ is not judged again as $(j,i)$. At the end of our algorithm, the vertices should be \emph{consistently} labelled as either \texttt{A} and \texttt{B} or our algorithm should be able to prove that $G$ cannot be labelled as so.

A modified graph traversal using either BFS or DFS will work. Here we will modify the graph traversal given on \emph{page 42} on our \nth{3} lecture slides that uses BFS. The input of the algorithm is any node $s \in E$. If, due to ambiguous (i.e.\ missing) nodes, the graph is not connected, the algorithm should be run on a new undiscovered node until every connected component is discovered.

{\centering
    \begin{minipage}{.7\linewidth}
        \begin{algorithm}[H]
            \SetKwProg{Fn}{function}{}{end}
            \DontPrintSemicolon{}
            \SetAlgoLongEnd{}
            \Fn{consistency\_check(s: node)}{
                \KwData{$K$ = data structure of discovered nodes}
                \KwResult{boolean = whether $G$ is consistent or not}
                \textbf{label} $s$ as \texttt{A} \tcc*[r]{the opposite label is B}
                put $s$ in $K$\;
                \While{$K$ is not empty}{
                    take a node $v$ from $K$\;
                    \If{$v$ is not marked \enquote{explored}}{
                        mark $v$ \enquote{explored}\;
                        \For{each edge $(v, w)$ incident to $v$}{
                            \uIf{$w$ is labelled}{
                                \If{the label of $w$ is not consistent with the label of $v$ with respect to the judgement $(v,w$)}{
                                    terminate the algorithm; $G$ is \textbf{inconsistent}\;
                                }
                            }
                            \Else{
                                \uIf{$(v,w)$ is labelled \enquote{same}}{
                                    \textbf{label} $w$ with the label of $v$\;
                                }
                                \Else(\tcc*[f]{$(v,w)$ is labelled \enquote{different}}){
                                    \textbf{label} $w$ with the opposite label of $v$\;
                                }
                            }
                            put $w$ in $K$\;
                        }
                    }
                }
                the spanned connected component is \textbf{consistent}
            }
            \caption{Modified graph traversal algorithm so solve judgement consistency checking problem}%
            \label{alg:question_1}
        \end{algorithm}
    \end{minipage}
    \par
}

With the assumption that accessing the labels $(u, w)$ takes $\mathcal{O}(1)$ time this algorithm has the same running time as BFS; $\mathcal{O}(m+n)$.

To give a short proof, consider the scenario below;

\begin{tikzpicture}[auto]
    \node [label={[red]left:$A$}] (a) at (90:1) {$a$};
    \node [label={[red]right:$A$}] (b) at (45:2) {$b$};
    \node [label={[red]right:$B$}] (c) at (0:2) {$c$};
    \node [label={[red]left:$A$}] (d) at (240:1) {$d$};

    \draw (a) to node {S} (b);
    \draw (b) to node {D} (c);
    \draw (c) to node {?} (d);
    \draw (a) to node [swap] {S} (d);
\end{tikzpicture}

Consider the situation where we started at node $a$ with the label \texttt{A}, labelled $b$ with \texttt{A} due to \enquote{same} $(a,b)$ edge and labelled $d$ with \texttt{A} due to \enquote{same} $(a, d)$ edge.
Node $c$ will be labelled with \texttt{B} due to \enquote{different} $(b, c)$ edge.
Now, depending on the judgement on (or lack thereof) $(d,c)$ edge, the graph will be either consistent (if \enquote{different})
or inconsistent (if \enquote{same}).
Since the modified BFS above visits every node at least once and considers every edge at least once (property of BFS), an inconsistent path will be discovered or none will occur, meaning a consistent graph.

\section{Reachability}%
\label{sec:reachability}

The intuition for this question can be illustrated as follows;

If $G$ is strongly connected then the answer is trivial; every vertex have the same $\min(u) = 1$.

For a directed acyclic graph, consider the scenario below;

\begin{tikzpicture}
    [vertex/.style={circle,draw,thick,minimum size=6mm,inner sep=10pt},
    edge/.style={->,>=stealth',line width=1pt]}]

    \node[vertex] (0) {$a$};
    \node[vertex] (1) [right=of 0] {$b$};
    \node[vertex] (2) [right=of 1] {$c$};
    \node[vertex] (3) [right=of 2] {$d$};

    \node [above,xshift=-5mm] at (0.north west) {$L(u) = 4$};
    \node [above] at (1.north) {$L(u) = 1$};
    \node [above] at (2.north) {$L(u) = 3$};
    \node [above,xshift=5mm] at (3.north east) {$L(u) = 2$};

    % \node [red,below] at (0.south) {$\min(u) = 1$};
    % \node [red,below] at (1.south) {$\min(u) = 1$};
    % \node [red,below] at (2.south) {$\min(u) = 2$};
    % \node [red,below] at (3.south) {$\min(u) = 3$};

    \draw [edge] (0) to (1);
    \draw [edge,bend left=45] (0) to (3);
    \draw [edge] (1) to (2);
    \draw [edge] (2) to (3);
\end{tikzpicture}

We can assign the $\min(u)$ values on this directed acyclic graph by reversing the direction of the edges and traversing the graph, keeping a minimum $\min(u)$ encountered so far for the nodes;

\begin{tikzpicture}
    [vertex/.style={circle,draw,thick,minimum size=6mm,inner sep=10pt},
    edge/.style={<-,>=stealth',line width=1pt]}]

    \node[vertex] (0) {$a$};
    \node[vertex] (1) [right=of 0] {$b$};
    \node[vertex] (2) [right=of 1] {$c$};
    \node[vertex] (3) [right=of 2] {$d$};

    \node [above,xshift=-5mm] at (0.north west) {$L(u) = 4$};
    \node [above] at (1.north) {$L(u) = 1$};
    \node [above] at (2.north) {$L(u) = 3$};
    \node [above,xshift=5mm] at (3.north east) {$L(u) = 2$};

    \node [red,below] at (0.south) {$\min(u) = 1$};
    \node [red,below] at (1.south) {$\min(u) = 1$};
    \node [red,below] at (2.south) {$\min(u) = 2$};
    \node [red,below] at (3.south) {$\min(u) = 2$};

    \draw [edge] (0) to (1);
    \draw [edge,bend left=45] (0) to (3);
    \draw [edge] (1) to (2);
    \draw [edge] (2) to (3);
\end{tikzpicture}

Starting from the \enquote{root} \texttt{d}, the $\min(u)$ is $2$, which is assigned to the immediate neighbours of \texttt{d}, \texttt{c} and \texttt{a}.
When the traversal \emph{reaches} \texttt{b}, \texttt{b} sets the current $\min(u)$ to $1$ and \texttt{a}'s $\min(u)$ value is updated to $1$ as well.

With the intuition out of the way, we will generalize the problem.
First, compute all strongly connected components (SCCs) of $G$ by using~\parencite{tarjanDepthFirst1972} per \emph{page 72} of the \nth{3} lecture notes in $\mathcal{O}(E+V)$ time.
Instead of labelling the SCCs with their root node, we will initially label all nodes of the SCC $F'$ with the $\min(u)$ of the connected component; $\min(a) ~ \text{of} ~ a \in F' = \min{\{L(w) : w \in F'\}}$.

Then, by ignoring the tree edges, \emph{shrink} the graph $G$ such that $E' = \{(v, w)~|~v \in F', w \in F''\}$, leaving only cross links behind.
This step takes another $\mathcal{O}(E+V)$ time.

Now run the topological sort algorithm presented in \emph{page 84} of the \nth{3} lecture notes.
This operation is yet again $\mathcal{O}(E+V)$.

We now have a scenario like the one illustrated above.
Reverse the direction of the edges on the graph that have been output by the topological sort and starting from the new root node, traverse the graph downwards and update the $\min(u)$ of every SCC in $\mathcal{O}(m+n)$ time as follows;

{\centering
    \begin{minipage}{.7\linewidth}
        \begin{algorithm}[H]
            \DontPrintSemicolon{}
            \SetAlgoLongEnd{}
            \KwData{$G'$ = topological sorted G with reversed edges}
            \KwResult{$\min(u)$ for all vertices $u \in V$}
            $\text{minnest} \longleftarrow \min(\text{root})$\;
            \While(\tcp*[f]{$m+n$}){traversing $G'$ downwards with current node $v$}{
                \uIf{$\min(v) < minnest$}{
                    $\text{minnest} \longleftarrow \min(v)$\;
                }
                \Else{
                    label $v$ as $minnest$
                }
            }
            \caption{Updating $\min(u)$ of the SCCs}%
            \label{alg:question_2}
        \end{algorithm}
    \end{minipage}
    \par
}

Finally, update the $\min(u)$ of every node $w \in G$ to match the cross link edges of the SCC they belong to. This operation is yet another $\mathcal{O}(m+n)$ traversal.

\printbibliography

\end{document}