clrs-practice-exam/examples/exam1.html

312 lines
22 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css" integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js" integrity="sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false},
{left: "\\begin{equation}", right: "\\end{equation}", display: true},
{left: "\\begin{align}", right: "\\end{align}", display: true},
{left: "\\begin{alignat}", right: "\\end{alignat}", display: true},
{left: "\\begin{gather}", right: "\\end{gather}", display: true},
{left: "\\begin{CD}", right: "\\end{CD}", display: true},
{left: "\\[", right: "\\]", display: true}
],
throwOnError : false
});
});
</script>
<title>Practice Exam</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<style>
body {
margin-left: 20%;
margin-right: 20%;
}
summary {
font-weight: bold;
}
@media screen and (max-width:1000px) {
body {
margin-left: 5%;
margin-right: 5%;
}
}
</style>
</head>
<body>
<h1>Practice Exam</h1>
<h2>24.3-6</h2>
<p>We are given a directed graph $G = (V, E)$ on which each edge $(u, v) \in E$ has an associated value $r(u, v)$, which is a real number in the range $0 \le r(u, v) \le 1$ that represents the reliability of a communication channel from vertex $u$ to vertex $v$. We interpret $r(u, v)$ as the probability that the channel from $u$ to $v$ will not fail, and we assume that these probabilities are independent. Give an efficient algorithm to find the most reliable path between two given vertices.</p>
<details>
<summary>Solution</summary>
<p>(Removed)</p>
</details>
<h2>22.3-2</h2>
<p>Show how depth-first search works on the graph of Figure 22.6. Assume that the <strong>for</strong> loop of lines 57 of the $\text{DFS}$ procedure considers the vertices in alphabetical order, and assume that each adjacency list is ordered alphabetically. Show the discovery and finishing times for each vertex, and show the classification of each edge.</p>
<details>
<summary>Solution</summary>
<p>The following table gives the discovery time and finish time for each vetex in the graph.</p>
<p>See the <a href="https://github.com/walkccc/CLRS-cpp/blob/master/Chap22/22.3.cpp">C++ demo</a>.</p>
<p>$$
\begin{array}{ccc}
\text{Vertex} &amp; \text{Discovered} &amp; \text{Finished} \\
\hline
q &amp; 1 &amp; 16 \\
r &amp; 17 &amp; 20 \\
s &amp; 2 &amp; 7 \\
t &amp; 8 &amp; 15 \\
u &amp; 18 &amp; 19 \\
v &amp; 3 &amp; 6 \\
w &amp; 4 &amp; 5 \\
x &amp; 9 &amp; 12 \\
y &amp; 13 &amp; 14 \\
z &amp; 10 &amp; 11
\end{array}
$$</p>
<ul>
<li><strong>Tree edges:</strong> $(q, s)$, $(s, v)$, $(v, w)$, $(q, t)$, $(t, x)$, $(x, z)$, $(t, y)$, $(r, u)$.</li>
<li><strong>Back edges:</strong> $(w, s)$, $(z, x)$, $(y, q)$.</li>
<li><strong>Forward edges:</strong> $(q, w)$.</li>
<li><strong>Cross edges:</strong> $(r, y)$, $(u, y)$.</li>
</ul>
</details>
<h2>26.2-11</h2>
<p>The <strong><em>edge connectivity</em></strong> of an undirected graph is the minimum number $k$ of edges that must be removed to disconnect the graph. For example, the edge connectivity of a tree is $1$, and the edge connectivity of a cyclic chain of vertices is $2$. Show how to determine the edge connectivity of an undirected graph $G = (V, E)$ by running a maximum-flow algorithm on at most $|V|$ flow networks, each having $O(V)$ vertices and $O(E)$ edges.</p>
<details>
<summary>Solution</summary>
<p>Create an directed version of the graph. Then create a flow network out of it, resolving all antiparallel edges. All edges' capacities are set to $1$. Pick any vertex that wasn't created for antiparallel workaround as the sink and run maximum-flow algorithm with all vertexes that aren't for antipararrel workaround (except the sink) as sources. Find the minimum value out of all $|V| - 1$ maximum flow values.</p>
</details>
<h2>34.2-9</h2>
<p>Prove that $\text P \subseteq \text{co-NP}$.</p>
<details>
<summary>Solution</summary>
<p>(Omit!)</p>
</details>
<h2>16.4-4 *</h2>
<p>Let $S$ be a finite set and let $S_1, S_2, \ldots, S_k$ be a partition of $S$ into nonempty disjoint subsets. Define the structure $(S, \mathcal I)$ by the condition that $\mathcal I = \{A: \mid A \cap S_i \mid \le 1$ for $i = 1, 2, \ldots, k\}$. Show that $(S, \mathcal I)$ is a matroid. That is, the set of all sets $A$ that contain at most one member of each subset in the partition determines the independent sets of a matroid.</p>
<details>
<summary>Solution</summary>
<p>Suppose $X \subset Y$ and $Y \in \mathcal I$. Then $(X \cap S_i) \subset (Y \cap S_i)$ for all $i$, so</p>
<p>$$|X \cap S_i| \le |Y \cap S_i| \le 1$$</p>
<p>for all $1 \le i \le k$. Therefore $\mathcal M$ is closed under inclusion.</p>
<p>Now Let $A, B \in \mathcal I$ with $|A| &gt; |B|$. Then there must exist some $j$ such that $|A \cap S_j| = 1$ but $|B \cap S_j| = 0$. Let $a \in A \cap S_j$. Then $a \notin B$ and $|(B \cup \{a\}) \cap S_j| = 1$. Since</p>
<p>$$|(B \cup \{a\}) \cap S_i| = |B \cap S_i| \le 1$$</p>
<p>for all $i \ne j$, we must have $B \cup \{a\} \in \mathcal I$. Therefore $\mathcal M$ is a matroid.</p>
</details>
<h2>24.2-3</h2>
<p>The PERT chart formulation given above is somewhat unnatural. In a more natural structure, vertices would represent jobs and edges would represent sequencing constraints; that is, edge $(u, v)$ would indicate that job $u$ must be performed before job $v$. We would then assign weights to vertices, not edges. Modify the $\text{DAG-SHORTEST-PATHS}$ procedure so that it finds a longest path in a directed acyclic graph with weighted vertices in linear time.</p>
<details>
<summary>Solution</summary>
<p>There are two ways to transform a PERT chart $G = (V, E)$ with weights on the vertices to a PERT chart $G' = (V', E')$ with weights on edges. Both ways satisfy $|V'| \le 2|V|$ and $|E'| \le |V| + |E|$, so we can scan $G'$ using the same algorithm to find the longest path through a directed acyclic graph.</p>
<p>In the first way, we transform each vertex $v \in V$ into two vertices $v'$ and $v''$ in $V'$. All edges in $E$ that enters $V$ will also enter $V'$ in $E'$, and all edges in $E$ that leaves $V$ will leave $V''$ in $E'$. Thus, if $(u, v) \in E$, then $(u'', v') \in E'$. All such edges have weight 0, so we can put edges $(v', v'')$ into $E'$ for all vertices $v \in V$, and these edges are given the weight of the corresponding vertex $v$ in $G$. Finally, we get $|V'| \le 2|V|$ and $|E'| \le |V| + |E|$, and the edge weight of each path in $G'$ equals the vertex weight of the corresponding path in $G$.</p>
<p>In the second way, we leave vertices in $V$, but try to add one new source vertex $s$ to $V'$, given that $V' = V \cup \{s\}$. All edges of $E$ are in $E'$, and $E'$ also includes an edge $(s, v)$ for every vertex $v \in V$ that has in-degree 0 in $G$. Thus, the only vertex with in-degree 0 in $G'$ is the new source $s$. The weight of edge $(u, v) \in E'$ is the weight of vertex $v$ in $G$. We have the weight of each entering edge in $G'$ is the weight of the vertex it enters in $G$.</p>
</details>
<h2>15.4-4</h2>
<p>Show how to compute the length of an $\text{LCS}$ using only $2 \cdot \min(m, n)$ entries in the $c$ table plus $O(1)$ additional space. Then show how to do the same thing, but using $\min(m, n)$ entries plus $O(1)$ additional space.</p>
<details>
<summary>Solution</summary>
<p>Since we only use the previous row of the $c$ table to compute the current row, we compute as normal, but when we go to compute row $k$, we free row $k - 2$ since we will never need it again to compute the length. To use even less space, observe that to compute $c[i, j]$, all we need are the entries $c[i 1, j]$, $c[i 1, j 1]$, and $c[i, j 1]$. Thus, we can free up entry-by-entry those from the previous row which we will never need again, reducing the space requirement to $\min(m, n)$. Computing the next entry from the three that it depends on takes $O(1)$ time and space.</p>
</details>
<h2>15.1-4</h2>
<p>Modify $\text{MEMOIZED-CUT-ROD}$ to return not only the value but the actual solution, too.</p>
<details>
<summary>Solution</summary>
<pre lang="cpp"><code>MEMOIZED-CUT-ROD(p, n)
let r[0..n] and s[0..n] be new arrays
for i = 0 to n
r[i] = -∞
(val, s) = MEMOIZED-CUT-ROD-AUX(p, n, r, s)
print &quot;The optimal value is&quot; val &quot;and the cuts are at&quot; s
j = n
while j &gt; 0
print s[j]
j = j - s[j]
</code></pre>
<pre lang="cpp"><code>MEMOIZED-CUT-ROD-AUX(p, n, r, s)
if r[n] ≥ 0
return r[n]
if n == 0
q = 0
else q = -∞
for i = 1 to n
(val, s) = MEMOIZED-CUT-ROD-AUX(p, n - i, r, s)
if q &lt; p[i] + val
q = p[i] + val
s[n] = i
r[n] = q
return (q, s)
</code></pre>
</details>
<h2>26.3-4 *</h2>
<p>A <strong><em>perfect matching</em></strong> is a matching in which every vertex is matched. Let $G = (V, E)$ be an undirected bipartite graph with vertex partition $V = L \cup R$, where $|L| = |R|$. For any $X \subseteq V$, define the <strong><em>neighborhood</em></strong> of $X$ as</p>
<blockquote>
<p>$$N(X) = \{y \in V: (x, y) \in E \text{ for some } x \in X\},$$</p>
<p>that is, the set of vertices adjacent to some member of $X$. Prove <strong><em>Hall's theorem</em></strong>: there exists a perfect matching in $G$ if and only if $|A| \le |N(A)|$ for every subset $A \subseteq L$.</p>
</blockquote>
<details>
<summary>Solution</summary>
<p>First suppose there exists a perfect matching in $G$. Then for any subset $A \subseteq L$, each vertex of $A$ is matched with a neighbor in $R$, and since it is a matching, no two such vertices are matched with the same vertex in $R$. Thus, there are at least $|A|$ vertices in the neighborhood of $A$.</p>
<p>Now suppose that $|A| \le |N(A)|$ for all $A \subseteq L$. Run Ford-Fulkerson on the corresponding flow network. The flow is increased by $1$ each time an augmenting path is found, so it will suffice to show that this happens $|L|$ times. Suppose the while loop has run fewer than $L$ times, but there is no augmenting path. Then fewer than $L$ edges from $L$ to $R$ have flow $1$.</p>
<p>Let $v_1 \in L$ be such that no edge from $v_1$ to a vertex in $R$ has nonzero flow. By assumption, $v_1$ has at least one neighbor $v_1' \in R$. If any of $v_1$'s neighbors are connected to $t$ in $G_f$ then there is a path, so assume this is not the case. Thus, there must be some edge $(v_2, v_1)$ with flow $1$. By assumption, $N(\{v_1, v_2\}) \ge 2$, so there must exist $v_2' \ne v_1'$ such that $v_2'\in N(\{v_1, v_2 \})$. If $(v_2', t)$ is an edge in the residual network we're done since $v_2'$ must be a neighbor of $v_2$, so $s$, $v_1$, $v_1'$, $v_2$, $v_2'$, and $t$ is a path in $G_f$. Otherwise $v_2'$ must have a neighbor $v_3 \in L$ such that $(v_3, v_2')$ is in $G_f$. Specifically, $v_3 \ne v_1$ since $(v_3, v_2')$ has flow $1$, and $v_3 \ne v_2$ since $(v_2, v_1')$ has flow $1$, so no more flow can leave $v_2$ without violating conservation of flow. Again by our hypothesis, $N(\{v_1, v_2, v_3\}) \ge 3$, so there is another neighbor $v_3' \in R$.</p>
<p>Continuing in this fashion, we keep building up the neighborhood $v_i'$, expanding each time we find that $(v_i', t)$ is not an edge in $G_f$. This cannot happen $L$ times, since we have run the Ford-Fulkerson while-loop fewer than $|L|$ times, so there still exist edges into $t$ in $G_f$. Thus, the process must stop at some vertex $v_k'$, and we obtain an augmenting path</p>
<p>$$s, v_1, v_1', v_2, v_2', v_3, \ldots, v_k, v_k', t,$$</p>
<p>contradicting our assumption that there was no such path. Therefore the while loop runs at least $|L|$ times. By Corollary 26.3 the flow strictly increases each time by $f_p$. By Theorem 26.10 $f_p$ is an integer. In particular, it is equal to $1$. This implies that $|f| \ge |L|$. It is clear that $|f| \le |L|$, so we must have $|f| = |L|$. By Corollary 26.11 this is the cardinality of a maximum matching. Since $|L| = |R|$, any maximum matching must be a perfect matching.</p>
</details>
<h2>22.2-2</h2>
<p>Show the $d$ and $\pi$ values that result from running breadth-first search on the undirected graph of Figure 22.3, using vertex $u$ as the source.</p>
<details>
<summary>Solution</summary>
<p>$$
\begin{array}{c|cccccc}
\text{vertex} &amp; r &amp; s &amp; t &amp; u &amp; v &amp; w &amp; x &amp; y \\
\hline
d &amp; 4 &amp; 3 &amp; 1 &amp; 0 &amp; 5 &amp; 2 &amp; 1 &amp; 1 \\
\pi &amp; s &amp; w &amp; u &amp; \text{NIL} &amp; r &amp; t &amp; u &amp; u
\end{array}
$$</p>
</details>
<h2>4.4-7</h2>
<p>Draw the recursion tree for $T(n) = 4T(\lfloor n / 2 \rfloor) + cn$, where $c$ is a constant, and provide a tight asymptotic bound on its solution. Verify your answer with the substitution method.</p>
<details>
<summary>Solution</summary>
<ul>
<li>
<p>The subproblem size for a node at depth $i$ is $n / 2^i$.</p>
<p>Thus, the tree has $\lg n + 1$ levels and $4^{\lg n} = n^{\lg 4} = n^2$ leaves.</p>
<p>The total cost over all nodes at depth $i$, for $i = 0, 1, 2, \ldots, \lg n - 1$, is $4^i(cn / 2^i) = 2^icn$.</p>
<p>$$
\begin{aligned}
T(n) &amp; = \sum_{i = 0}^{\lg n - 1} 2^icn + \Theta(n^2) \\
&amp; = \frac{2^{\lg n} - 1}{2 - 1}cn + \Theta(n^2) \\
&amp; = \Theta(n^2).
\end{aligned}
$$</p>
</li>
<li>
<p>For $O(n^2)$, we guess $T(n) \le dn^2 - cn$,</p>
<p>$$
\begin{aligned}
T(n) &amp; \le 4d(n / 2)^2 - 4c(n / 2) + cn \\
&amp; = dn^2 - cn.
\end{aligned}
$$</p>
</li>
<li>
<p>For $\Omega(n^2)$, we guess $T(n) \ge dn^2 - cn$,</p>
<p>$$
\begin{aligned}
T(n) &amp; \ge 4d(n / 2)^2 - 4c(n / 2) + cn \\
&amp; = dn^2 - cn.
\end{aligned}
$$</p>
</li>
</ul>
</details>
<h2>15.2-4</h2>
<p>Describe the subproblem graph for matrix-chain multiplication with an input chain of length $n$. How many vertices does it have? How many edges does it have, and which edges are they?</p>
<details>
<summary>Solution</summary>
<p>The vertices of the subproblem graph are the ordered pair $v_{ij}$, where $i \le j$.</p>
<ul>
<li>If $i = j$, the vertex $v_{ij}$ has no output edge.</li>
<li>If $i &lt; j$, for each $k$, s.t. $i \le k &lt; j$, the subproblem graph contains edges $(v_{ij}, v_{ik})$ and $(v_{ij}, v_{k+1, j})$, and these edges indicate that to solve the subproblem of optimally parenthesizing the product $A_i \cdots A_j$, we need to solve subproblems of optimally parenthesizing the products $A_i \cdots A_k$ and $A_{k + 1} \cdots A_j$.</li>
</ul>
<p>The number of vertices is</p>
<p>$$\sum_{i = 1}^n \sum_{j = i}^n = \frac{n(n + 1)}{2}.$$</p>
<p>The number of edges is</p>
<p>$$\sum_{i = 1}^n \sum_{j = i}^n (j - i) = \frac{(n - 1)n(n + 1)}{6}.$$</p>
</details>
<h2>24.3-5</h2>
<p>Professor Newman thinks that he has worked out a simpler proof of correctness for Dijkstra's algorithm. He claims that Dijkstra's algorithm relaxes the edges of every shortest path in the graph in the order in which they appear on the path, and therefore the path-relaxation property applies to every vertex reachable from the source. Show that the professor is mistaken by constructing a directed graph for which Dijkstra's algorithm could relax the edges of a shortest path out of order.</p>
<details>
<summary>Solution</summary>
<p>(Removed)</p>
</details>
<h2>26.2-12</h2>
<p>Suppose that you are given a flow network $G$, and $G$ has edges entering the source $s$. Let $f$ be a flow in $G$ in which one of the edges $(v, s)$ entering the source has $f(v, s) = 1$. Prove that there must exist another flow $f'$ with $f'(v, s) = 0$ such that $|f| = |f'|$. Give an $O(E)$-time algorithm to compute $f'$, given $f$, and assuming that all edge capacities are integers.</p>
<details>
<summary>Solution</summary>
<p>(Removed)</p>
</details>
<h2>22.2-8 *</h2>
<p>The <strong><em>diameter</em></strong> of a tree $T = (V, E)$ is defined as $\max_{u,v \in V} \delta(u, v)$, that is, the largest of all shortest-path distances in the tree. Give an efficient algorithm to compute the diameter of a tree, and analyze the running time of your algorithm.</p>
<details>
<summary>Solution</summary>
<p>Suppose that a and b are the endpoints of the path in the tree which achieve the diameter, and without loss of generality assume that $a$ and $b$ are the unique pair which do so. Let $s$ be any vertex in $T$. We claim that the result of a single $\text{BFS}$ will return either $a$ or $b$ (or both) as the vertex whose distance from $s$ is greatest.</p>
<p>To see this, suppose to the contrary that some other vertex $x$ is shown to be furthest from $s$. (Note that $x$ cannot be on the path from $a$ to $b$, otherwise we could extend). Then we have</p>
<p>$$d(s, a) &lt; d(s, x)$$</p>
<p>and</p>
<p>$$d(s, b) &lt; d(s, x).$$</p>
<p>Let $c$ denote the vertex on the path from $a$ to $b$ which minimizes $d(s, c)$. Since the graph is in fact a tree, we must have</p>
<p>$$d(s, a) = d(s, c) + d(c, a)$$</p>
<p>and</p>
<p>$$d(s, b) = d(s, c) + d(c, b).$$</p>
<p>(If there were another path, we could form a cycle). Using the triangle inequality and inequalities and equalities mentioned above we must have</p>
<p>$$
\begin{aligned}
d(a, b) + 2d(s, c) &amp; = d(s, c) + d(c, b) + d(s, c) + d(c, a) \\
&amp; &lt; d(s, x) + d(s, c) + d(c, b).
\end{aligned}
$$</p>
<p>I claim that $d(x, b) = d(s, x) + d(s, b)$. If not, then by the triangle inequality we must have a strict less-than. In other words, there is some path from $x$ to $b$ which does not go through $c$. This gives the contradiction, because it implies there is a cycle formed by concatenating these paths. Then we have</p>
<p>$$d(a, b) &lt; d(a, b) + 2d(s, c) &lt; d(x, b).$$</p>
<p>Since it is assumed that $d(a, b)$ is maximal among all pairs, we have a contradiction. Therefore, since trees have $|V| - 1$ edges, we can run $\text{BFS}$ a single time in $O(V)$ to obtain one of the vertices which is the endpoint of the longest simple path contained in the graph. Running $\text{BFS}$ again will show us where the other one is, so we can solve the diameter problem for trees in $O(V)$.</p>
</details>
<h2>26.3-3</h2>
<p>Let $G = (V, E)$ be a bipartite graph with vertex partition $V = L \cup R$, and let $G'$ be its corresponding flow network. Give a good upper bound on the length of any augmenting path found in $G'$ during the execution of $\text{FORD-FULKERSON}$.</p>
<details>
<summary>Solution</summary>
<p>(Removed)</p>
</details>
<h2>26.2-3</h2>
<p>Show the execution of the Edmonds-Karp algorithm on the flow network of Figure 26.1(a).</p>
<details>
<summary>Solution</summary>
<p>If we perform a breadth first search where we consider the neighbors of a vertex as they appear in the ordering $\{s, v_1, v_2, v_3, v_4, t\}$, the first path that we will find is $s, v_1, v_3, t$. The min capacity of this augmenting path is $12$, so we send $12$ units along it. We perform a $\text{BFS}$ on the resulting residual network. This gets us the path $s, v_2, v_4, t$. The min capacity along this path is $4$, so we send $4$ units along it. Then, the only path remaining in the residual network is $\{s, v_2, v_4, v_3, t\}$ which has a min capacity of $7$, since that's all that's left, we find it in our $\text{BFS}$. Putting it all together, the total flow that we have found has a value of $23$.</p>
</details>
<h2>26.3-1</h2>
<p>Run the Ford-Fulkerson algorithm on the flow network in Figure 26.8 (c) and show the residual network after each flow augmentation. Number the vertices in $L$ top to bottom from $1$ to $5$ and in $R$ top to bottom from $6$ to $9$. For each iteration, pick the augmenting path that is lexicographically smallest.</p>
<details>
<summary>Solution</summary>
<p>First, we pick an augmenting path that passes through vertices 1 and 6. Then, we pick the path going through 2 and 8. Then, we pick the path going through 3 and 7. Then, the resulting residual graph has no path from $s$ to $t$. So, we know that we are done, and that we are pairing up vertices $(1, 6)$, $(2, 8)$, and $(3, 7)$. This number of unit augmenting paths agrees with the value of the cut where you cut the edges $(s, 3)$, $(6, t)$, and $(7, t)$.</p>
</details>
<h2>24.2-2</h2>
<p>Suppose we change line 3 of $\text{DAG-SHORTEST-PATHS}$ to read</p>
<blockquote>
<pre lang="cpp"><code> 3 for the first |V| - 1 vertices, taken in topologically sorted order
</code></pre>
<p>Show that the procedure would remain correct.</p>
</blockquote>
<details>
<summary>Solution</summary>
<p>When we reach vertex $v$, the last vertex in the topological sort, it must have $out\text-degree$ $0$. Otherwise there would be an edge pointing from a later vertex to an earlier vertex in the ordering, a contradiction. Thus, the body of the for-loop of line 4 is never entered for this final vertex, so we may as well not consider it.</p>
</details>
<h2>4.1-1</h2>
<p>What does $\text{FIND-MAXIMUM-SUBARRAY}$ return when all elements of $A$ are negative?</p>
<details>
<summary>Solution</summary>
<p>It will return the greatest element of $A$.</p>
</details>
<footer>
<hr>
<p>
built by nat, from questions written by Michelle Bodnar and Andrew Lohr (CLRS 3rd Edition), the solutions to which were prepared and organized by <a href="https://pengyuc.com/">Peng-Yu Chen</a> and <a href="https://github.com/walkccc/CLRS/graphs/contributors">contributors to walkccc/CLRS on GitHub</a>.
</p>
</footer>
</body>
</html>