Skip to content

Commit

Permalink
#1478 B-3c
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtask committed May 7, 2023
1 parent 34535f2 commit f466dc8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions appendixb/problems/3/a.tex
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
\subproblem
The fact trivially holds for binary trees with at most three nodes, so in the rest of the proof we will assume that $n\ge4$.
For a given binary tree consider a sequence of nodes $\langle x_0$, $x_1$, \dots, $x_k\rangle$, where $x_0$ is the root, $x_k$ is a leaf, and for $i=1$, 2, \dots, $k$, $x_i$ is the root of the subtree of $x_{i-1}$ with more nodes.
We define a \concept{branch} of a binary tree as a path $\langle x_0$, $x_1$, \dots, $x_k\rangle$, where $x_0$ is the root, $x_k$ is a leaf, and for $i=1$, 2, \dots, $k$, $x_i$ is the root of the subtree of $x_{i-1}$ with more nodes.
Note that a tree may have more than one branch.
Let's denote by $s(x)$ the number of nodes in the subtree rooted at $x$.
For every $i=0$, 1, \dots, $k-1$,
\[
\begin{equation} \label{eq:subtree-sizes-on-branch}
s(x_i) \le 2s(x_{i+1})+1.
\]
\end{equation}
Of course, the sequence $\langle s(x_0)$, $s(x_1)$, \dots, $s(x_k)\rangle$ decreases from $n$ to 1, so there must be $j$, such that $s(x_j)>n/4$ and $s(x_{j+1})\le n/4$.
Thus, by removing edge $(x_{j-1},x_j)$, we partition the nodes of the tree into two sets of sizes
\begin{align*}
s(x_j) &\le 2n/4+1 \\
s(x_j) &\le 2s(x_{j+1})+1 \tag{by inequality \eqref{eq:subtree-sizes-on-branch}} \\
&= 2n/4+1 \\
&\le 3n/4
\end{align*}
and
Expand Down
18 changes: 18 additions & 0 deletions appendixb/problems/3/c.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
\subproblem
Assume that $n\ge6$.
We'll remove one edge from the original tree to cut off a subtree of at most $\lfloor n/2\rfloor$ vertices.
Consider any of the tree's branches $\langle x_0$, $x_1$, \dots, $x_k\rangle$, as well as the function $s$, both defined in the solution to part (a).
There is an edge $(x_j,x_{j+1})$, such that $s(x_j)>\lfloor n/2\rfloor$ and $s(x_{j+1})\le\lfloor n/2\rfloor$.
From inequality \eqref{eq:subtree-sizes-on-branch} we have
\begin{align*}
s(x_{j+1}) &\ge (s(x_j)-1)/2 \\
&> (\lfloor n/2\rfloor-1)/2 \\
&\ge \lfloor n/2\rfloor/3.
\end{align*}
We cut off the subtree rooted at $x_{j+1}$ and continue partitioning the remaining tree, with at most
\[
\lfloor n/2\rfloor-s(x_{j+1}) < (2/3)\lfloor n/2\rfloor
\]
vertices still to remove from it.
In each subsequent step the number of nodes remaining to be cut is reduced by a factor of $2/3$.
Therefore, we'll need to remove $O(\log_{3/2}n)=O(\lg n)$ edges.
1 change: 1 addition & 0 deletions appendixb/problems/3/main.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
\problem{Bisecting trees}
\subimport{./}{a}
\subimport{./}{b}
\subimport{./}{c}
2 changes: 2 additions & 0 deletions clrs4e-solutions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
\renewcommand{\thefigure}{\thesubsection}
\renewcommand{\thesubfigure}{(\alph{subfigure})}

\counterwithout{equation}{chapter}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\chaptertitlename~\thechapter\quad#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\quad#1}}
Expand Down

0 comments on commit f466dc8

Please sign in to comment.