diff options
Diffstat (limited to 'main.tex')
-rw-r--r-- | main.tex | 86 |
1 files changed, 77 insertions, 9 deletions
@@ -85,13 +85,79 @@ With the assumption that accessing the labels $(u, w)$ takes $\mathcal{O}(1)$ ti | |||
85 | \section{Reachability}% | 85 | \section{Reachability}% |
86 | \label{sec:reachability} | 86 | \label{sec:reachability} |
87 | 87 | ||
88 | 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 the root node, we will initially label all nodes of the SCC $F'$ with the $min(u)$ of the connected component. | 88 | The intuition for this question can be illustrated as follows; |
89 | 89 | ||
90 | Then, by ignoring the tree edges, 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. | 90 | If $G$ is strongly connected then the answer is trivial; every vertex have the same $\min(u) = 1$. |
91 | 91 | ||
92 | 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)$. | 92 | For a directed acyclic graph, consider the scenario below; |
93 | 93 | ||
94 | Finally, 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 as follows; | 94 | \begin{tikzpicture} |
95 | [vertex/.style={circle,draw,thick,minimum size=6mm,inner sep=10pt}, | ||
96 | edge/.style={->,>=stealth',line width=1pt]}] | ||
97 | |||
98 | \node[vertex] (0) {$a$}; | ||
99 | \node[vertex] (1) [right=of 0] {$b$}; | ||
100 | \node[vertex] (2) [right=of 1] {$c$}; | ||
101 | \node[vertex] (3) [right=of 2] {$d$}; | ||
102 | |||
103 | \node [above,xshift=-5mm] at (0.north west) {$L(u) = 4$}; | ||
104 | \node [above] at (1.north) {$L(u) = 1$}; | ||
105 | \node [above] at (2.north) {$L(u) = 3$}; | ||
106 | \node [above,xshift=5mm] at (3.north east) {$L(u) = 2$}; | ||
107 | |||
108 | % \node [red,below] at (0.south) {$\min(u) = 1$}; | ||
109 | % \node [red,below] at (1.south) {$\min(u) = 1$}; | ||
110 | % \node [red,below] at (2.south) {$\min(u) = 2$}; | ||
111 | % \node [red,below] at (3.south) {$\min(u) = 3$}; | ||
112 | |||
113 | \draw [edge] (0) to (1); | ||
114 | \draw [edge,bend left=45] (0) to (3); | ||
115 | \draw [edge] (1) to (2); | ||
116 | \draw [edge] (2) to (3); | ||
117 | \end{tikzpicture} | ||
118 | |||
119 | 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; | ||
120 | |||
121 | \begin{tikzpicture} | ||
122 | [vertex/.style={circle,draw,thick,minimum size=6mm,inner sep=10pt}, | ||
123 | edge/.style={<-,>=stealth',line width=1pt]}] | ||
124 | |||
125 | \node[vertex] (0) {$a$}; | ||
126 | \node[vertex] (1) [right=of 0] {$b$}; | ||
127 | \node[vertex] (2) [right=of 1] {$c$}; | ||
128 | \node[vertex] (3) [right=of 2] {$d$}; | ||
129 | |||
130 | \node [above,xshift=-5mm] at (0.north west) {$L(u) = 4$}; | ||
131 | \node [above] at (1.north) {$L(u) = 1$}; | ||
132 | \node [above] at (2.north) {$L(u) = 3$}; | ||
133 | \node [above,xshift=5mm] at (3.north east) {$L(u) = 2$}; | ||
134 | |||
135 | \node [red,below] at (0.south) {$\min(u) = 1$}; | ||
136 | \node [red,below] at (1.south) {$\min(u) = 1$}; | ||
137 | \node [red,below] at (2.south) {$\min(u) = 2$}; | ||
138 | \node [red,below] at (3.south) {$\min(u) = 2$}; | ||
139 | |||
140 | \draw [edge] (0) to (1); | ||
141 | \draw [edge,bend left=45] (0) to (3); | ||
142 | \draw [edge] (1) to (2); | ||
143 | \draw [edge] (2) to (3); | ||
144 | \end{tikzpicture} | ||
145 | |||
146 | 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}. | ||
147 | 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. | ||
148 | |||
149 | With the intuition out of the way, we will generalize the problem. | ||
150 | 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. | ||
151 | 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'\}}$. | ||
152 | |||
153 | 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. | ||
154 | This step takes another $\mathcal{O}(E+V)$ time. | ||
155 | |||
156 | Now run the topological sort algorithm presented in \emph{page 84} of the \nth{3} lecture notes. | ||
157 | This operation is yet again $\mathcal{O}(E+V)$. | ||
158 | |||
159 | We now have a scenario like the one illustrated above. | ||
160 | 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; | ||
95 | 161 | ||
96 | {\centering | 162 | {\centering |
97 | \begin{minipage}{.7\linewidth} | 163 | \begin{minipage}{.7\linewidth} |
@@ -100,13 +166,13 @@ Finally, reverse the direction of the edges on the graph that have been output b | |||
100 | \SetAlgoLongEnd{} | 166 | \SetAlgoLongEnd{} |
101 | \KwData{$G'$ = topological sorted G with reversed edges} | 167 | \KwData{$G'$ = topological sorted G with reversed edges} |
102 | \KwResult{$\min(u)$ for all vertices $u \in V$} | 168 | \KwResult{$\min(u)$ for all vertices $u \in V$} |
103 | $\text{mostmin} \longleftarrow \min(\text{root})$\; | 169 | $\text{minnest} \longleftarrow \min(\text{root})$\; |
104 | \While{traversing $G'$ downwards with current node $v$}{ | 170 | \While(\tcp*[f]{$m+n$}){traversing $G'$ downwards with current node $v$}{ |
105 | \uIf{$\min(v) < mostmin$}{ | 171 | \uIf{$\min(v) < minnest$}{ |
106 | $\text{mostmin} \longleftarrow \min(v)$\; | 172 | $\text{minnest} \longleftarrow \min(v)$\; |
107 | } | 173 | } |
108 | \Else{ | 174 | \Else{ |
109 | label $v$ as $mostmin$ | 175 | label $v$ as $minnest$ |
110 | } | 176 | } |
111 | } | 177 | } |
112 | \caption{Updating $\min(u)$ of the SCCs}% | 178 | \caption{Updating $\min(u)$ of the SCCs}% |
@@ -116,6 +182,8 @@ Finally, reverse the direction of the edges on the graph that have been output b | |||
116 | \par | 182 | \par |
117 | } | 183 | } |
118 | 184 | ||
185 | 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. | ||
186 | |||
119 | \printbibliography | 187 | \printbibliography |
120 | 188 | ||
121 | \end{document} | 189 | \end{document} |