Appendix B
Exercise B.1-1
Exercise B.1-2
We prove the statement using induction on n.
Proving the generalization of the first of DeMorgan’s laws
The base case trivially holds. For we have
Using the principles of mathematical induction we can conclude that the first of DeMorgan’s laws is applicable to any finite collection of sets.
Proving the generalization of the second of DeMorgan’s laws
The proof is analogous to the previous case, just swap the symbols and .
Exercise B.1-3
We prove the statement using induction on n. The base case trivially holds. For we have
We now apply the inductive hypothesis on subexpressions in (1) and (2).
Observe that every term in the expansion of the subexpression (2) is initially prefixed with a negative sign. Therefore, each term must be multiplied by -1 when reinserted into the main formula. Ultimately, we have
Using the principles of mathematical induction we can conclude that the generalized variant of equation (B.3) holds for all .
Exercise B.1-4
The function maps a natural number (with zero included) to it's odd counterpart. This establishes a bijection between natural numbers and odd natural numbers. Therefore, the set of odd natural numbers is countable.
Exercise B.1-5
Let and . In a power set, each element either joins a subset or not. Suppose participation is denoted by 1 and absence by 0. Represent any subset as an n-digit binary number , where . This creates a bijection between n-digit binary numbers and subsets of a power set. With n binary digits, there are possible values. This shows that for any finite set S, the power set has elements.
Observe that the previous proof also answers the question how to non-recursively generate all subsets of a power set. Just iterate over all integers in , convert them into binary, and produce subsets based upon those binary representations as described above.
Exercise B.1-6
Exercise B.2-1
The subset relation is reflexive, antisymmetric and transitive as explained in the book. Consequently, it represents a partial order on all subsets of ℤ. It is not a total order, since there are many pairs of subsets that are not in relation with each other. For example, {0,1} and {1,2,3}.
Exercise B.2-2
We need to show that the relation "equivalent modulo n" is reflexive, symmetric and transitive.
. Therefore,
The relation “equivalent modulo n” splits the integers into congruency classes. Two integers are regarded equivalent if they have the same remainder when divided by n.
Exercise B.2-3
is not transitive, since 3 4 and 4 5 do not imply 3 5.
is not symmetric otherwise there would be a cycle.
Let . as a relation on is not reflexive, since is missing. As a matter of fact, even an empty relation on would still be symmetric and transitive, but not reflexive (see the explanation in Exercise B.2-5).
Exercise B.2-4
Suppose some equivalence class has at least two distinct elements and . Since is symmetric, . But this contradicts 's antisymmetry, . Therefore, all equivalence classes of with respect to must be singletons.
Exercise B.2-5
Professor Narcissus is wrong, as Exercise B.2-3 demonstrates.
Symmetry and transitivity are defined through implications. The fallacy stems from presuming that an antecedent must be true for an implication to be true, as well. But if there is an element that is not related to any other element, including itself, then it does not break symmetry or transitivity. On the other hand, reflexivity demands that all elements be related with themselves.
Exercise B.3-1
If is injective, then each element of is mapped to a unique element in . Therefore, there must be at least as many elements in as there are in . Thus, .
If is surjective, then every element in has some element from mapped into it. So, there are at least as many elements in as there are in . This conclusion also relies on being a function, meaning that no single argument is mapped to multiple values. Thus, .
Exercise B.3-2
If the domain and codomain are natural numbers, the function is not a bijection because zero is not in the range. However, if we include all integers, it becomes a bijection.
Exercise B.3-3
Let be a binary relation on sets and . We define its inverse as
.
Observe that if is in fact a bijective function, then its relational inverse is its functional inverse. This follows from the definition of an inverse function (see the book).
Exercise B.3-4
A pairing function is a function that reversibly maps onto . We cannot use it directly, as we need to work with set . So, we will perform a composition of bijective transformations.
Bijection from to
Use the function from the book (see page 1163).
Bijection from to
We can use the inverse of the Cantor's pairing function (see (8) in the above linked material) to produce matching pairs from natural numbers.
Bijection from to
Use the function from the book (see page 1162).
Composition of transformations
We are now ready to connect all the individual components into a pipeline. Define the bijective function as
Exercise B.4-1
We prove the handshaking lemma by induction on . The base case obviously holds. For the inductive step, assume that and pick any edge . Let be the subgraph of where . The total count becomes
The denotes the degree of a node in . By the principles of mathematical induction we can conclude that the handshaking lemma is true for any undirected graph .
The original problem can be reformulated in terms of an undirected graph, where vertices are professors and edges represent handshakings between them.
Exercise B.4-2
Let denote a valid path/cycle.
The iterative path simplifying function is depicted below:
If , then return . There is always a 0-length path from to itself.
If is a simple path, then return .
Find indices , , of a repeated vertex and drop the subpath from . If , then still starts at , but with one less repetition of , so it is a valid path. Otherwise, , which is again a valid path; we know that there is an edge , because the previous path had a subpath and .
Repeat steps 2-3.
Observe that the procedure will terminate, as each iteration reduces the number of duplicates in . Also, it is correct, because step 3 is proven to produce a new valid path and steps 2-3 execute until no duplicates are found.
We can reuse our path simplifier function for a cycle as follows:
Let be the result of simplifying the path without the initial vertex .
If
Output .
It is important to emphasize that both procedures only promise to emit a simple path/cycle at exit. This is enough to prove that any path/cycle contains a simple path/cycle. Starting from both and are possible outputs depending on the order of removal of duplicated vertices. But satisfying such additional quality attributes. like minimizing the path/cycle length, are out of scope of this exercise.
Exercise B.4-3
We prove by induction on . The base case clearly hold.
For the inductive step, assume that for graph and pick a vertex . Let be the subgraph of induced by . We have that , as connectedness of entails that there is at least one edge incident on . may have connected components. Consider each connected component as a subgraph for which the inductive hypothesis applies, hence . Consequently, the number of edges in all connected components of is at least . Furthermore, we know that because is connected, so all components of must have been connected through vertex . Reconnecting them (including itself) requires at least additional edges. As a side note, if , then we need at least one edge to reconnect .
Therefore, the total number of edges satisfies
According to the principles of mathematical induction we can conclude that any connected, undirected graph satisfies .
Exercise B.4-4
We need to show that in an undirected graph, the "is reachable from" relation is reflexive, symmetric and transitive.
Any vertex is reachable from itself via a 0-length path.
If there is a path , then due to bidirectional edges there is also a path , where is reversed.
If there are paths , then there is also a path via vertex .
In a directed graph, symmetry does not hold in general, since edges cannot be reused for "moving" in both directions. The other two properties do hold.
Exercise B.4-5
Exercise B.4-6
Wikipedia has published a solution aligned with the hint from the book.
Exercise B.5-1
Exercise B.5-2
Observe that an undirected version of graph is connected. There is a path from vertex to every other vertex in both directions. Hence, any two vertices are connected via this central vertex .
The in-degree of every vertex except in graph is 1. Assume, for contradiction, that there is a vertex whose in-degree is larger than 1. WLOG let it be 2. Consequently, there are two neighbors and connected to with edges and making two different paths and toward . But this is impossible, since graph has unique paths from to every other vertex.
Vertex has in-degree of zero, otherwise there would be a cycle in . Therefore, each vertex except is associated with one incoming edge, so . According to Theorem B.2 a connected graph with this number of edges is a free tree.
Exercise B.5-3
We proceed by induction on . The base case is when , which is a binary tree with one leaf without a degree-2 node. Hence, the base case is true.
For the inductive step, assume . Denote by and the number of leaves and degree-2 nodes in a binary tree, respectively. If we take out the root node, then we obtain two subtrees. If anyone of them is empty, then the statement follows by applying the inductive hypothesis on the other nonempty subtree, as the root is neither a leaf nor degree-2 node in this case. Otherwise, denote by and the number of leaves and degree-2 nodes in the left subtree, respectively. Similarly, let and be the same for the right subtree. We have and we can apply the inductive hypothesis on both subtrees to get
In a full binary tree, all internal nodes are degree-2 nodes, so the conclusion from the book follows.
Exercise B.5-4
Execute the following iterative function to create a full binary tree with leaves:
Let be a single node binary tree. It is a full binary tree with no degree-2 node.
Repeat steps a-b times:
Create a new binary tree with a degree-2 root node whose left child is and the right child is a leaf node. is a full binary tree with one more leaf than .
Let .
Return .
Exercise B.5-5
We proceed by induction on . The base case clearly holds, since .
For the inductive step, assume the statement holds for all nonempty binary trees with less than nodes. Consider a binary tree with . If one child is empty, then
Suppose that both children are nonempty. Let and be the number of nodes in the left and right subtree, respectively. By the inductive hypothesis we have and , hence and . The last conclusion follows from observations that for any integer as well as that both and are monotonically increasing functions. As a matter of fact, returns for all .
We have
According to the principles of mathematical induction we can conclude that the statement from the book is true for all nonempty binary trees.
Exercise B.5-6
We proceed by induction on . The base case trivially holds, as the only full binary tree with no internal node has one leaf at depth 0.
For the inductive step, take and assume the statement is true for all full binary trees with less than internal nodes. Take out the root of a full binary tree with internal nodes. Let and denote the number of internal nodes in its left and right subtree, respectively. We have that and we know that both subtrees are also full binary trees. According to Exercise B.5-3 the number of leaves in a full binary tree is one more than its number of internal nodes. Furthermore, the root contributes +1 to the depth of all other nodes. After combining these facts we have
and
We can now apply the inductive hypothesis to both subtrees to get
According to the principles of mathematical induction we can conclude that the statement from the book is true for all full binary trees.
Exercise B.5-7
We proceed by induction on number of nodes . The base cases are when (they both hold)
For the inductive step, take and assume it holds for all binary tree with less than nodes. Take out the root of a binary tree with nodes. Let and denote the set of leaves in its left and right subtree, respectively. Notice that the root contributes +1 to the depth of all leaves. After combining these facts we have
According to the principles of mathematical induction we can conclude that the Kraft inequality is true for all binary trees.
Exercise B.5-8
We proceed using the constructive proof method. The algorithm below outputs a subtree matching the constraints from the problem description.
Let the current node become the root of a binary tree with leaves.
Take the children of the current node.
Choose the larger child based on number of leaves and let the current node become its root.
If it has more than leaves, then goto step 2.
Output this subtree.
The algorithm will terminate, since in each iteration the larger subtree has at least one node less than a tree from the previous iteration (its root surely disappears).
It correctly outputs the matching subtree. Notice that the loop continues whilst a larger subtree is too big. When it reduces in size to contain leaves, then it must contain at least leaves, because the previous tree had more than leaves. Observe, that at step 2 the current node cannot be a leaf, since at this point a (sub)tree rooted at the current node has more than leaves.
Problem B-1
a.
We form a rooted tree by picking any node as a root node. Edges in such a tree are incident on nodes from adjacent levels, so we can color a tree by levels. We need 2 colors in total, as the parity of a level determines its color.
b.
(1) -> (2)
Any bipartite graph's vertices may be partitioned into two subsets, such that no two distinct vertices from the same subset are connected by an edge. Therefore, we need 2 colors in total, one per subset.
(2) -> (3)
Suppose, for contradiction, that a 2-colorable graph has a cycle of odd length . WLOG assume that this cycle is simple; otherwise, consider its simple sub-cycle of odd length or simplify the cycle if all sub-cycles are of even length (see Exercise B.4-2). We must ensure that for all . But this is impossible, since we cannot assign two different colors to .
(3) -> (1)
Assume that graph is connected, otherwise apply the reasoning depicted below for each connected component. It is trivial to merge subsets of vertices from individual connected components into two major subsets for a whole graph , as there is no interaction between them.
Pick any vertex and select all vertices reachable from via simple paths of even length. Notice that this includes , as any vertex is reachable from itself through a 0-length path. Denote this subset as . Form subset containing vertices reachable from via simple paths of odd length. We claim that all edges of graph are between vertices from these separate groups as well as no single vertex belongs to both subsets.
Assume, for contradiction, that there is a vertex . But this is impossible, since there would be a cycle of odd length , by choosing paths and of even and odd length, respectively.
Assume, for contradiction, that there are distinct vertices connected by an edge (a simple path of odd length). But this is again impossible, since paths and would be of odd length, so . The same reasoning apples for members of . Therefore, graph is bipartite.
c.
We proceed by induction on . The base case is when , so we need 1 color. Thus, the base case is true, since we cannot have self-loops in an undirected graph.
For the inductive step take and assume it is true for all undirected graphs with less than vertices. Pick a vertex and form an induced graph of . Let be the maximum degree of any vertex in . By the inductive hypothesis graph is colorable with colors, where . A degree of vertex is at most , so coloring its neighbors demand at most colors. Therefore, we can allocate an unused color to , so graph is colorable with colors.
d.
Assume we need colors for coloring a graph . Consequently, all color combinations are required, otherwise there would be two colors that are indistinguishable from each other. We have and .
Problem B-2
a.
In an undirected graph of size there are at least two vertices of the same degree.
Proof We prove this using the pigeonhole principle. A degree of a vertex may take values from the interval . If we have an isolated vertex, then the rest of the vertices can take degrees from the range . Clearly, we cannot avoid duplication of degrees. If there is no isolated vertex, then the range for degrees changes into that must be distributed onto vertices. Again, this cannot be done without a duplicated degree.
b.
In an undirected graph of size there is either a clique or isolated vertex set of size at least 3.
Proof Pick any vertex . From the remaining 5 vertices we can select 3 of them satisfying one of the following two conditions:
All of them are adjacent to .
None of them are adjacent to .
Case 1
If any pair from this group is adjacent, then that pair together with form a clique. Otherwise, they form an isolated vertex set.
Case 2
If all of them are adjacent to each other, then they form a clique. Otherwise, there must be 2 vertices not connected by an edge, so they together with form an isolated vertex set.
c.
Any undirected graph has a cut such that for any vertex at least half of its neighbors do not belong to the same subset where belongs.
Proof We prove the statement by an explicit construction of the required cut.
Arbitrarily split vertices into two disjoint subsets and and initialize the cut-set.
If there is a vertex with more than half of its neighbors also belonging to , then move this vertex into . Update the cut-set to reflect the new state.
If there is a vertex with more than half of its neighbors also belonging to , then move this vertex into . Update the cut-set to reflect the new state.
If the cut-set was updated, then repeat steps 2-3.
Updates in steps 2-3 only increase the size of the cut-set. Therefore, the algorithm must terminate, as there are finite number of edges in a graph .
Observe that at any moment in time , since vertices are shuffled around between disjoint sets. At exit, all vertices satisfy the required constraint.
d.
This is Dirac's theorem on Hamiltonian cycles and the proof has two parts:
Proving that there is a Hamiltonian path in a graph , which is elaborated in the attached PDF document. It was retrieved on July, 2025 from here.
Proving that the above path is a cycle.
Suppose we have a Hamiltonian path . If , then just append to the path to get a cycle. Otherwise, create two sets of indices indicating neighbors of and , as follows:
Let be the common index. The desired cycle is .
Problem B-3
a.
Assume that . The solution is nearly identical to Exercise B.5-8, so will not be repeated here. Instead of number of leaves we count the number of nodes in subtrees. When the modified algorithm terminates at a subtree rooted at node , then its size lies in the interval . So, by removing the edge connecting it to its parent we would get the desired split.
b.
c.
We proceed by explicitly showing how to generate the required sets. It is based on the heavy-light decomposition technique as in Part (a). Let represent the input binary tree with with nodes. The steps of the the algorithm are as follows:
Initialize and an empty set that will hold nodes of .
Let the current node become the root of .
Take the children of the current node.
Choose the larger child based on number of nodes and let the current node become its root.
If has more than nodes, then goto step 3.
Insert the nodes of into .
Set .
Remove the edge connecting to its parent, thus prune .
If , then goto step 2.
Output and .
Each iteration removes a subtree of size at least half the remaining target, i.e., reducing by at least half each time. Thus, the number of edges removed is . The heavy-light traversal ensures that in any subtree larger than , at least one child is sufficiently large (, guaranteeing progress toward the target without overshooting.
Last updated