Skip to content

Commit 32b9658

Browse files
authored
Fall 2017 Mentoring 13 (#27)
* mentor13 * Reflow and fix-up Mentoring 13
1 parent 6f9c45e commit 32b9658

File tree

7 files changed

+79
-39
lines changed

7 files changed

+79
-39
lines changed

src/mentor13.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ \section{Networking}
1313
\subimport{../topics/graphs/minimum-spanning-trees/easy/}{network.tex}
1414
\end{questions}
1515

16+
\clearpage
17+
1618
\section{A* Search}
1719
\begin{questions}
1820
\subimport{../topics/graphs/shortest-paths/a-star/easy/}{s-a-d-g.tex}
1921
\end{questions}
2022

23+
\clearpage
24+
2125
\section{\extra{Algorithms}}
26+
\subimport{../topics/graphs/text/}{algorithms.tex}
2227
\begin{questions}
2328
\subimport{../topics/graphs/search/medium/}{greedy-dfs.tex}
2429
\subimport{../topics/graphs/minimum-spanning-trees/medium/}{weight-constrained.tex}

topics/graphs/minimum-spanning-trees/easy/network.tex

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
\begin{blocksection}
2-
\question Suppose we need to design a telephone network connecting all the
3-
residents, labeled $A$ through $G$, in a neighborhood. How can we create a
4-
network that guarantees connectivity between all subscribers at the least
5-
possible cost?
1+
\question Suppose we want to design a telephone network connecting all the
2+
cities, labeled $A$ to $G$, in a neighborhood. We'd like to do so at the least
3+
cost.
64

75
\begin{center}
86
\begin{tikzpicture}[scale=0.15]
@@ -52,11 +50,10 @@
5250
\part In a graph with $N$ vertices and $M$ edges, how many edges form a minimum
5351
spanning tree?
5452
\begin{solution}[0.5in]
55-
$N-1$, or 6 edges in the above graph.
53+
$N - 1$, or 6 edges in the above graph.
5654
\end{solution}
5755

58-
\part Will the new graph contain any cycles? Describe the structure of the
59-
graph.
56+
\part Will the new graph contain any cycles? Describe its structure.
6057
\begin{solution}[1in]
6158
The resulting graph is a tree which implies that it contains no cycles. If the
6259
tree reaches every node in the graph, then it is a \define{spanning tree}.
@@ -65,8 +62,18 @@
6562
weight of the tree.
6663
\end{solution}
6764

68-
\part Run Kruskal's Algorithm to find the minimum spanning tree.
69-
\begin{solution}[1in]
65+
\part One algorithm to find a minimum spanning tree is Kruskal's algorithm.
66+
\begin{enumerate}
67+
\item Sort all the edges by increasing order of their weight.
68+
\item Pick the smallest edge and check if it forms a cycle with the spanning
69+
tree so far. If it doesn't form a cycle, add this edge to the spanning tree.
70+
\item Repeat the previous step until there are $|V| - 1$ edges in the spanning
71+
tree, where $|V|$ is the number of vertices in the graph.
72+
\end{enumerate}
73+
74+
Run Kruskal's Algorithm to find a minimum spanning tree.
75+
76+
\begin{solution}
7077
\begin{center}
7178
\begin{tikzpicture}[scale=0.15]
7279
\tikzstyle{every node}+=[inner sep=0pt]
@@ -98,6 +105,9 @@
98105
\draw (49.5,-30) node [left] {$1$};
99106
\end{tikzpicture}
100107
\end{center}
108+
109+
\textbf{Meta}: Draw only the nodes and add the edges that are part of the MST
110+
as you walk through the problem. Labeling all the edges would take a long time,
111+
and erasing is confusing and complicated.
101112
\end{solution}
102113
\end{parts}
103-
\end{blocksection}

topics/graphs/minimum-spanning-trees/medium/weight-constrained.tex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
\begin{blocksection}
2-
\question Briefly describe an efficient algorithm (and report the running time)
3-
for finding a minimum spanning tree in an undirected, connected graph
4-
$G = (V, E)$ when the edge weights satisfy:
2+
\question Briefly describe an efficient algorithm and the runtime for finding a
3+
minimum spanning tree in an undirected, connected graph $G = (V, E)$ when the
4+
edge weights satisfy:
55

66
\begin{parts}
7-
\part For all $e \in E$, $w_e = 1$.
7+
\part For all $e \in E$, $w_e = 1$. (All edge weights are 1.)
88
\begin{solution}[1.5in]
99
The key idea here is that any tree which connects all nodes is an MST. We can
1010
run DFS and take the DFS tree. You could also take a BFS tree, or run Prim's
@@ -13,8 +13,8 @@
1313
$\Theta(|V| + |E|) \in \Theta(|E|)$ for simple graphs.
1414
\end{solution}
1515

16-
\part For all $e \in E$, $w_e \in \{1, 2\}$. (In other words, all edge weights
17-
are either 1 or 2.)
16+
\part For all $e \in E$, $w_e \in \{1, 2\}$. (All edge weights are either 1 or
17+
2.)
1818
\begin{solution}[1.5in]
1919
Run Prim's algorithm with a specialized priority queue, comprised of 2 regular
2020
queues. When we add items to the priority queue, we add it to the first queue

topics/graphs/search/medium/greedy-dfs.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
\begin{blocksection}
2-
\question Is this algorithm for computing the shortest path between two
3-
vertices correct?
2+
\question Is this algorithm for computing the \emph{single pair shortest path}
3+
correct?
44

55
Given a starting vertex, $s$, and an ending vertex, $v$, compute the shortest
66
path between $s$ and $v$ by running DFS, but at each node exploring the

topics/graphs/shortest-paths/a-star/easy/s-a-d-g.tex

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
\begin{blocksection}
21
\question Find the path from the start, $S$, to the goal, $G$, when running
32
each of the following algorithms.
43

4+
The \define{heuristic}, $h$, estimates the distance from each node to the goal.
5+
56
\begin{center}
67
\begin{tikzpicture}[scale=0.15]
78
\tikzstyle{every node}+=[inner sep=0pt]
89
\draw (60,-15) circle (3);
910
\draw (60,-15) node {$E$};
10-
\draw (65,-18) node {\footnotesize $h = 1$};
11+
\draw (66.5,-15) node {\footnotesize $h = 1$};
1112
\draw (10,-30) circle (3);
1213
\draw (10,-30) node {$S$};
1314
\draw (15,-33) node {\footnotesize $h = 6$};
@@ -47,48 +48,71 @@
4748
\draw (58,-30) -- (67,-30);
4849
\fill (67,-30) -- (66.2,-29.5) -- (66.2,-30.5);
4950
\draw (62.5,-29.5) node [above] {$2$};
51+
\draw (61.66,-17.5) -- (68.34,-27.5);
52+
\fill (68.34,-27.5) -- (68.31,-26.56) -- (67.48,-27.12);
53+
\draw (64.39,-23.83) node [left] {$1$};
5054
\end{tikzpicture}
5155
\end{center}
5256

5357
\begin{solution}
5458
Note that uniform cost search and greedy search are not a part of the course.
5559
The algorithms for all 3 of these searches are extremely similar, the only
56-
difference being the priority given to a key and whether or not we need the
57-
cumulative distance to a vertex.
60+
difference being the priority given to each node and whether or not we need to
61+
keep track of the cumulative distance to a vertex.
5862
\end{solution}
5963

6064
\begin{parts}
6165
\part Which path does uniform cost search return?
66+
67+
\define{Uniform cost search} is the same as Dijkstra's, except that the search
68+
stops once we visit the goal state.
69+
6270
\begin{solution}[1in]
6371
$S - A - D - G$
6472

6573
From the starting node, choose the path that has the least cost, go to that
6674
node, and repeat until we reach the goal node. We choose the lowest
6775
\emph{backward cost}.
6876

69-
Note that this is very similar to Dijkstra's, just a little more general. We
70-
keep a priority-queue fringe that keeps track of paths. At each step, we remove
71-
the shortest path from the fringe and add its children to the fringe, trying
72-
all paths in increasing cost order until we reach G.
77+
We keep a priority-queue fringe that keeps track of paths. At each step, we
78+
remove the shortest path from the fringe and add its children to the fringe,
79+
trying all paths in increasing cost order until we reach $G$.
7380
\end{solution}
7481

7582
\part Which path does greedy search return?
83+
84+
In \define{greedy search}, we ignore edge weights entirely and only use the
85+
heuristic to decide which node to visit next.
86+
7687
\begin{solution}[1in]
77-
$S - A - E - D - G$ or $S - A - D - G$ depending on tie-breaking behavior.
88+
$S - A - E - D - G$
7889

7990
From the starting node, travel to the next node with the lowest value returned
8091
by the heuristic function until we reach the goal node. We choose the path with
8192
the lowest \emph{forward cost}.
93+
94+
Note that, unlike UCS or Dijkstra's, we don't add heuristics together because
95+
they already estimate the distance to the goal.
8296
\end{solution}
8397

8498
\part Which path does A* search return?
99+
100+
\define{A* search} is an algorithm that combines the total distance from the
101+
start with the heuristic to optimize the search procedure.
102+
85103
\begin{solution}[1in]
86104
$S - A - D - G$
87105

88106
At each node, we choose the next node that has the lowest sum of the path cost
89107
and $h(\cdot)$ value. This is essentially uniform cost search and greedy search
90108
combined.
91109

110+
For A* to work, heuristics must be \emph{admissible} and \emph{consistent}.
111+
112+
\begin{itemize}
113+
\item Admissible heuristics underestimate the true distance to the goal.
114+
\item Consistent heuristics require that the difference in heuristic values
115+
between two nodes cannot be greater than the true distance between the two.
116+
\end{itemize}
92117
\end{solution}
93118
\end{parts}
94-
\end{blocksection}

topics/graphs/shortest-paths/dijkstras/hard/bfs-dijkstras.tex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
connecting them, or infinity if no such path exists.
77

88
\begin{parts}
9-
\part Design an algorithm for solving the problem that runs faster than
10-
Dijkstra's.
11-
\begin{solution}[2in]
9+
\part Design an algorithm for solving the problem better than Dijkstra's.
10+
\begin{solution}[2.5in]
1211
For every edge $e$ in the graph, replace $e$ with a chain of $w-1$ vertices
1312
(where $w$ is the weight of $e$) where the two ends of the chain are the
1413
endpoints of $e$.

topics/graphs/text/algorithms.tex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1+
\begin{blocksection}
12
\begin{description}
23
\item[Traversal] Visit all the nodes in the graph.
34
\begin{itemize}[$\cdot$]
45
\item Depth-first traversal (preorder and postorder)
56
\item Level-order traversal
67
\end{itemize}
78

8-
\item[Search] Given a start node, find a goal state.
9+
\item[Search] Given $s$, find a goal $v$.
910
\begin{itemize}[$\cdot$]
1011
\item Depth-first search
1112
\item Iterative-deepening depth-first search
1213
\item Breadth-first search
1314
\end{itemize}
1415

15-
\item[\emph{Single Pair} Shortest Path] Given a start node, find the shortest
16-
path to a goal node.
16+
\item[Single Pair Shortest Path] Given $s$, find the shortest path to a
17+
goal $v$.
1718
\begin{itemize}[$\cdot$]
1819
\item \emph{Uniform cost search}
1920
\item \emph{Greedy search}
2021
\item A* search
2122
\end{itemize}
2223

23-
\item[\emph{Single Source} Shortest Path] Given a start node, find the shortest
24-
paths to all other nodes.
24+
\item[Single Source Shortest Path] Given $s$, find the shortest path to all
25+
nodes.
2526
\begin{itemize}[$\cdot$]
2627
\item Dijkstra's algorithm
2728
\end{itemize}
2829

29-
\item[Minimum Spanning Tree] A \emph{spanning tree}, or cycle-free subset of
30-
edges connecting all the nodes, with the minimum possible total edge weight.
30+
\item[Minimum Spanning Tree] A \emph{spanning tree}, or acyclic subgraph
31+
connecting all the nodes with the least total edge weight.
3132
\begin{itemize}[$\cdot$]
3233
\item Prim's algorithm
3334
\item Kruskal's algorithm
3435
\end{itemize}
3536
\end{description}
37+
\end{blocksection}

0 commit comments

Comments
 (0)