id
stringlengths 6
26
| chapter
stringclasses 36
values | section
stringlengths 3
5
| title
stringlengths 3
27
| source_file
stringlengths 13
29
| question_markdown
stringlengths 17
6.29k
| answer_markdown
stringlengths 3
6.76k
| code_blocks
listlengths 0
9
| has_images
bool 2
classes | image_refs
listlengths 0
7
|
---|---|---|---|---|---|---|---|---|---|
35-35.5-3
|
35
|
35.5
|
35.5-3
|
docs/Chap35/35.5.md
|
Prove inequality $\text{(35.29)}$.
|
(Omit!)
|
[] | false |
[] |
35-35.5-4
|
35
|
35.5
|
35.5-4
|
docs/Chap35/35.5.md
|
How would you modify the approximation scheme presented in this section to find a good approximation to the smallest value not less than $t$ that is a sum of some subset of the given input list?
|
(Omit!)
|
[] | false |
[] |
35-35.5-5
|
35
|
35.5
|
35.5-5
|
docs/Chap35/35.5.md
|
Modify the $\text{APPROX-SUBSET-SUM}$ procedure to also return the subset of $S$ that sums to the value $z^\*$.
|
(Omit!)
|
[] | false |
[] |
35-35-1
|
35
|
35-1
|
35-1
|
docs/Chap35/Problems/35-1.md
|
Suppose that we are given a set of $n$ objects, where the size $s_i$ of the $i$th object satisfies $0 < s_i < 1$. We wish to pack all the objects into the minimum number of unit-size bins. Each bin can hold any subset of the objects whose total size does not exceed $1$.
**a.** Prove that the problem of determining the minimum number of bins required is $\text{NP-hard}$. ($\textit{Hint:}$ Reduce from the subset-sum problem.)
The **_first-fit_** heuristic takes each object in turn and places it into the first bin that can accommodate it. Let $S = \sum_{i = 1}^n s_i$.
**b.** Argue that the optimal number of bins required is at least $\lceil S \rceil$.
**c.** Argue that the first-fit heuristic leaves at most one bin less than half full.
**d.** Prove that the number of bins used by the first-fit heuristic is never more than $\lceil 2S \rceil$.
**e.** Prove an approximation ratio of $2$ for the first-fit heuristic.
**f.** Give an efficient implementation of the first-fit heuristic, and analyze its running time.
|
(Omit!)
|
[] | false |
[] |
35-35-2
|
35
|
35-2
|
35-2
|
docs/Chap35/Problems/35-2.md
|
Let $G = (V, E)$ be an undirected graph. For any $k \ge 1$, define $G^{(k)}$ to be the undirected graph $(V^{(k)}, E^{(k)})$, where $V^{(k)}$ is the set of all ordered $k$-tuples of vertices from $V$ and $E^{(k)}$ is defined so that $(v_1, v_2, \dots, v_k)$ is adjacent to $(w_1, w_2, \dots, w_k)$ if and only if for $i = 1, 2, \dots, k$, either vertex $v_i$ is adjacent to $w_i$ in $G$, or else $v_i = w_i$.
**a.** Prove that the size of the maximum clique in $G^{(k)}$ is equal to the $k$th power of the size of the maximum clique in $G$.
**b.** Argue that if there is an approximation algorithm that has a constant approximation ratio for finding a maximum-size clique, then there is a polynomial-time approximation scheme for the problem.
|
(Omit!)
|
[] | false |
[] |
35-35-3
|
35
|
35-3
|
35-3
|
docs/Chap35/Problems/35-3.md
|
Suppose that we generalize the set-covering problem so that each set $S_i$ in the family $\mathcal F$ has an associated weight $w_i$ and the weight of a cover $\mathcal C$ is $\sum_{S_i \in \mathcal C} w_i$. We wish to determine a minimum-weight cover. (Section 35.3 handles the case in which $w_i = 1$ for all $i$.)
Show how to generalize the greedy set-covering heuristic in a natural manner to provide an approximate solution for any instance of the weighted set-covering problem. Show that your heuristic has an approximation ratio of $H(d)$, where $d$ is the maximum size of any set $S_i$.
|
(Omit!)
|
[] | false |
[] |
35-35-4
|
35
|
35-4
|
35-4
|
docs/Chap35/Problems/35-4.md
|
Recall that for an undirected graph $G$, a matching is a set of edges such that no two edges in the set are incident on the same vertex. In Section 26.3, we saw how to find a maximum matching in a bipartite graph. In this problem, we will look at matchings in undirected graphs in general (i.e., the graphs are not required to be bipartite).
**a.** A **_maximal matching_** is a matching that is not a proper subset of any other matching. Show that a maximal matching need not be a maximum matching by exhibiting an undirected graph $G$ and a maximal matching $M$ in $G$ that is not a maximum matching. ($\textit{Hint:}$ You can find such a graph with only four vertices.)
**b.** Consider an undirected graph $G = (V, E)$. Give an $O(E)$-time greedy algorithm to find a maximal matching in $G$.
In this problem, we shall concentrate on a polynomial-time approximation algorithm for maximum matching. Whereas the fastest known algorithm for maximum matching takes superlinear (but polynomial) time, the approximation algorithm here will run in linear time. You will show that the linear-time greedy algorithm for maximal matching in part (b) is a $2$-approximation algorithm for maximum matching.
**c.** Show that the size of a maximum matching in $G$ is a lower bound on the size of any vertex cover for $G$.
**d.** Consider a maximal matching $M$ in $G = (V, E)$. Let
$$T = \\{v \in V: \text{ some edge in } M \text{ is incident on } v\\}.$$
What can you say about the subgraph of $G$ induced by the vertices of $G$ that are not in $T$?
**e.** Conclude from part (d) that $2|M|$ is the size of a vertex cover for $G$.
**f.** Using parts (c) and (e), prove that the greedy algorithm in part (b) is a $2$-approximation algorithm for maximum matching.
|
(Omit!)
|
[] | false |
[] |
35-35-5
|
35
|
35-5
|
35-5
|
docs/Chap35/Problems/35-5.md
|
In the **_parallel-machine-scheduling problem_**, we are given $n$ jobs, $J_1, J_2, \dots, J_n$, where each job $J_k$ has an associated nonnegative processing time of $p_k$. We are also given $m$ identical machines, $M_1, M_2, \dots, M_m$. Any job can run on any machine. A **_schedule_** specifies, for each job $J_k$, the machine on which it runs and the time period during which it runs. Each job $J_k$ must run on some machine $M_i$ for $p_k$ consecutive time units, and during that time period no other job may run on $M_i$. Let $C_k$ denote the **_completion time_** of job $J_k$, that is, the time at which job $J_k$ completes processing. Given a schedule, we define $C_{\max} = \max_{1 \le j \le n} C_j$ to be the **_makespan_** of the schedule. The goal is to find a schedule whose makespan is minimum.
For example, suppose that we have two machines $M_1$ and $M_2$ and that we have four jobs $J_1, J_2, J_3, J_4$, with $p_1 = 2$, $p_2 = 12$, $p_3 = 4$, and $p_4 = 5$. Then one possible schedule runs, on machine $M_1$, job $J_1$ followed by job $J_2$, and on machine $M_2$, it runs job $J_4$ followed by job $J_3$. For this schedule, $C_1 = 2$, $C_2 = 14$, $C_3 = 9$, $C_4 = 5$, and $C_{\max} = 14$. An optimal schedule runs $J_2$ on machine $M_1$, and it runs jobs $J_1$, $J_3$, and $J_4$ on machine $M_2$. For this schedule, $C_1 = 2$, $C_2 = 12$, $C_3 = 6$, $C_4 = 11$, and $C_{\max} = 12$.
Given a parallel-machine-scheduling problem, we let $C_{\max}^\*$ denote the makespan of an optimal schedule.
**a.** Show that the optimal makespan is at least as large as the greatest processing time, that is,
$$C_{\max}^\* \ge \max_{1 \le k \le n} p_k.$$
**b.** Show that the optimal makespan is at least as large as the average machine load, that is,
$$C_{\max}^\* \ge \frac 1 m \sum_{1 \le k \le n} p_k.$$
Suppose that we use the following greedy algorithm for parallel machine scheduling: whenever a machine is idle, schedule any job that has not yet been scheduled.
**c.** Write pseudocode to implement this greedy algorithm. What is the running time of your algorithm?
**d.** For the schedule returned by the greedy algorithm, show that
$$C_{\max} \le \frac 1 m \sum_{1 \le k \le n} p_k + \max_{1 \le k \le n} p_k.$$
Conclude that this algorithm is a polynomial-time $2$-approximation algorithm.
|
(Omit!)
|
[] | false |
[] |
35-35-6
|
35
|
35-6
|
35-6
|
docs/Chap35/Problems/35-6.md
|
Let $G = (V, E)$ be an undirected graph with distinct edge weights $w(u, v)$ on each edge $(u, v) \in E$. For each vertex $v \in V$, let $\max(v) = \max_{(u, v) \in E} \\{w(u, v)\\}$ be the maximum-weight edge incident on that vertex. Let $S_G = \\{\max(v): v \in V\\}$ be the set of maximum-weight edges incident on each vertex, and let $T_G$ be the maximum-weight spanning tree of $G$, that is, the spanning tree of maximum total weight. For any subset of edges $E' \subseteq E$, define $w(E') = \sum_{(u, v) \in E'} w(u, v)$.
**a.** Give an example of a graph with at least $4$ vertices for which $S_G = T_G$.
**b.** Give an example of a graph with at least $4$ vertices for which $S_G \ne T_G$.
**c.** Prove that $S_G \subseteq T_G$ for any graph $G$.
**d.** Prove that $w(T_G) \ge w(S_G) / 2$ for any graph $G$.
**e.** Give an $O(V + E)$-time algorithm to compute a $2$-approximation to the maximum spanning tree.
|
(Omit!)
|
[] | false |
[] |
35-35-7
|
35
|
35-7
|
35-7
|
docs/Chap35/Problems/35-7.md
|
Recall the knapsack problem from Section 16.2. There are $n$ items, where the $i$th item is worth $v_i$ dollars and weighs $w_i$ pounds. We are also given a knapsack that can hold at most $W$ pounds. Here, we add the further assumptions that each weight $w_i$ is at most $W$ and that the items are indexed in monotonically decreasing order of their values: $v_1 \ge v_2 \ge \cdots \ge v_n$.
In the 0-1 knapsack problem, we wish to find a subset of the items whose total weight is at most $W$ and whose total value is maximum. The fractional knapsack problem is like the 0-1 knapsack problem, except that we are allowed to take a fraction of each item, rather than being restricted to taking either all or none of each item. If we take a fraction $x_i$ of item $i$, where $0 \le x_i \le 1$, we contribute $x_iw_i$ to the weight of the knapsack and receive value $x_iv_i$. Our goal is to develop a polynomial-time $2$-approximation algorithm for the 0-1 knapsack problem.
In order to design a polynomial-time algorithm, we consider restricted instances of the 0-1 knapsack problem. Given an instance $I$ of the knapsack problem, we form restricted instances $I_j$, for $j = 1, 2, \dots, n$, by removing items $1, 2, \dots, j - 1$ and requiring the solution to include item $j$ (all of item $j$ in both the fractional and 0-1 knapsack problems). No items are removed in instance $I_1$. For instance $I_j$, let $P_j$ denote an optimal solution to the 0-1 problem and $Q_j$ denote an optimal solution to the fractional problem.
**a.** Argue that an optimal solution to instance $I$ of the 0-1 knapsack problem is one of $\\{P_1, P_2, \dots, P_n\\}$.
**b.** Prove that we can find an optimal solution $Q_j$ to the fractional problem for instance $I_j$ by including item $j$ and then using the greedy algorithm in which at each step, we take as much as possible of the unchosen item in the set $\\{j + 1, j + 2, \dots, n\\}$ with maximum value per pound $v_i / w_i$.
**c.** Prove that we can always construct an optimal solution $Q_j$ to the fractional problem for instance $I_j$ that includes at most one item fractionally. That is, for all items except possibly one, we either include all of the item or none of the item in the knapsack.
**d.** Given an optimal solution $Q_j$ to the fractional problem for instance $I_j$, form solution $R_j$ from $Q_j$ by deleting any fractional items from $Q_j$. Let $v(S)$ denote the total value of items taken in a solution $S$. Prove that $v(R_j) \ge v(Q_j) / 2 \ge v(P_j) / 2$.
**e.** Give a polynomial-time algorithm that returns a maximum-value solution from the set $\\{R_1, R_2, \dots, R_n\\}$, and prove that your algorithm is a polynomial-time $2$-approximation algorithm for the 0-1 knapsack problem.
|
(Omit!)
|
[] | false |
[] |
UNKNOWN-index-GettingStart
|
UNKNOWN
|
index
|
Getting Started
|
docs/index.md
|
This **[website](https://walkccc.github.io/CLRS/)** contains nearly complete solutions to the bible textbook - [**Introduction to Algorithms** _Third Edition_](https://mitpress.mit.edu/books/introduction-algorithms-third-edition), published by [Thomas H. Cormen](https://mitpress.mit.edu/contributors/thomas-h-cormen), [Charles E. Leiserson](https://mitpress.mit.edu/contributors/charles-e-leiserson), [Ronald L. Rivest](https://mitpress.mit.edu/contributors/ronald-l-rivest), and [Clifford Stein](https://mitpress.mit.edu/contributors/clifford-stein).
|
This **[website](https://walkccc.github.io/CLRS/)** contains nearly complete solutions to the bible textbook - [**Introduction to Algorithms** _Third Edition_](https://mitpress.mit.edu/books/introduction-algorithms-third-edition), published by [Thomas H. Cormen](https://mitpress.mit.edu/contributors/thomas-h-cormen), [Charles E. Leiserson](https://mitpress.mit.edu/contributors/charles-e-leiserson), [Ronald L. Rivest](https://mitpress.mit.edu/contributors/ronald-l-rivest), and [Clifford Stein](https://mitpress.mit.edu/contributors/clifford-stein).
I hope to organize solutions to help people and myself study algorithms. By using [Markdown (.md)](https://en.wikipedia.org/wiki/Markdown) files and [KaTeX](https://katex.org) math library, this page is much more readable on portable devices.
_"Many a little makes a mickle."_
|
[] | false |
[] |
UNKNOWN-index-Contributors
|
UNKNOWN
|
index
|
Contributors
|
docs/index.md
|
Thanks to the authors of [CLRS Solutions](https://sites.math.rutgers.edu/~ajl213/CLRS/CLRS.html), [Michelle Bodnar](mailto:[email protected]) (who writes the even-numbered problems) and [Andrew Lohr](mailto:[email protected]) (who writes the odd-numbered problems), [@skanev](https://github.com/skanev), [@CyberZHG](https://github.com/CyberZHG), [@yinyanghu](https://github.com/yinyanghu), [@Gutdub](https://github.com/Gutdub), etc.
|
Thanks to the authors of [CLRS Solutions](https://sites.math.rutgers.edu/~ajl213/CLRS/CLRS.html), [Michelle Bodnar](mailto:[email protected]) (who writes the even-numbered problems) and [Andrew Lohr](mailto:[email protected]) (who writes the odd-numbered problems), [@skanev](https://github.com/skanev), [@CyberZHG](https://github.com/CyberZHG), [@yinyanghu](https://github.com/yinyanghu), [@Gutdub](https://github.com/Gutdub), etc.
Thanks to [all contributors on GitHub](https://github.com/walkccc/CLRS/graphs/contributors), you guys make this repository a better reference!
Special thanks to [@JeffreyCA](https://github.com/JeffreyCA), who fixed math rendering on iOS Safari in [#26](https://github.com/walkccc/CLRS/pull/26).
If I miss your name here, please tell me!
|
[] | false |
[] |
UNKNOWN-index-Motivation
|
UNKNOWN
|
index
|
Motivation
|
docs/index.md
|
I build this website since I want to help everyone learn algorithms by providing something easy to read on mobile devices.
|
I build this website since I want to help everyone learn algorithms by providing something easy to read on mobile devices.
Therefore, if any adjustment is needed or you have the same motivation to contribute to this work, please don't hesitate to give me your feedback. You can press the "pencil icon" in the upper right corner to edit the content or [open an issue](https://github.com/walkccc/CLRS/issues/new) in [this repository](https://github.com/walkccc/CLRS/). Your solution will be rebased after I review it and make some form modifications to your pull request.
There're lots of [issues](https://github.com/walkccc/CLRS/issues) regarding to solutions in this repository, if you have time, please take a look and try to help people on the internet :)
Thank you very much, and I hope that everyone will learn algorithms smoothly.
|
[] | false |
[] |
UNKNOWN-index-HowIGenerate
|
UNKNOWN
|
index
|
How I Generate the Website?
|
docs/index.md
|
I use the static site generator [MkDocs](http://www.mkdocs.org/) and the beautiful theme [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) to build this website.
|
I use the static site generator [MkDocs](http://www.mkdocs.org/) and the beautiful theme [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) to build this website.
As for rendering math equations, I use [KaTeX](https://katex.org/), which is fast and beautiful.
I also add `overflow-x: auto` to prevent the overflow issue on small screen devices so that you can scroll horizontally in the math display equations.
|
[] | false |
[] |
UNKNOWN-index-MoreInformat
|
UNKNOWN
|
index
|
More Information
|
docs/index.md
|
For a clear commit history, I rebase my repository regularly. Therefore, if you have forked the repository before, consider re-forking it again.
|
For a clear commit history, I rebase my repository regularly. Therefore, if you have forked the repository before, consider re-forking it again.
For more information, please visit [**my GitHub**](https://github.com/walkccc).
Updated to this new page on April 13, 2018, at 04:48 [(GMT+8)](https://time.is/GMT+8).
Revised on July 21, 2019.
|
[] | false |
[] |
UNKNOWN-index-License
|
UNKNOWN
|
index
|
License
|
docs/index.md
|
Licensed under the MIT License.
|
Licensed under the MIT License.
|
[] | false |
[] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.