mmn 12
Q1
-
given a directed graph , with for all . and a source vertex .
-
given that for all , there is a path from to .
-
-
if for each path then is a shortest path from to .
-
if are the possible weights of paths from to , then for each shortest path , we have . and the paths with the weight are called an almost shortest path (or second shortest path).
-
if an edge is the last edge in some shortest path , then is called a critical edge (שימושית)
-
(A) Paths with only critical edges are shortest paths
- Base Case ():
- A path with means has only one edge, which is critical, and thus is a shortest path, because it is the only path from to .
- Inductive Assumption:
- Assume that for any path of length , if all its edges are critical, then is a shortest path.
- Inductive Step:
- Consider a path of length , where all edges are critical.
- Let be the last edge of . This means , where is a path from to of length .
- By the inductive assumption, is a shortest path since all its edges are critical.
- Now consider the addition of , which is also critical. By definition of criticality, adding to the shortest path from to results in the shortest path from to .
- The total weight of is .
- No alternative path from to can have a lower weight because is already the shortest to and is critical.
- Thus, is a shortest path.
- Base Case ():
-
(B) Paths containing non-critical edges are not shortest paths
- Let be a path from to of any length . Suppose includes a non-critical edge .
- By definition, an edge is non-critical if there exists another path from to that does not use and .
- Let’s define a new path by .
- Since thus .
- Thus, cannot be a shortest path because.
-
(C) Prove that if is a second shortest path, then it has exactly one non-critical edge.
- is a second shortest path if , where is the weight of the shortest path. Hence, is not a shortest path. Therefore, must contain at least one non-critical edge. (by A)
- Suppose contains more than one non-critical edge. Let and be two non-critical edges in .
- Let’s be a shortest path from to .
- Since and are non-critical, there exist paths and that are shorter than and , respectively.
- Therefore, the path and
- (since )
- (since )
- Therefore , which contradicts the assumption that is a second shortest path.
-
(D) Prove that the prefix of from to is a shortest path, and the suffix from to is a shortest path.
- By A, both the prefix and the suffix are shortest paths since they only contain critical edges.
-
(E) show using the above an algorithm to find the second shortest path from to with a time complexity of .
- find a shortest path using Dijkstra’s algorithm from .
- define and .
- for each edge such that
pred[v]!=u
(i.e., is not a critical edge) do:- if then:
- if then:
- if or then there is no second shortest path from to . otherwise, we have a second shortest path that is .
Q2
- given undirected connected graph with that are integer values and distinct.
- is a tree of shortest paths from to all other vertices in . and is a minimum spanning tree of that its weight is minimal among all spanning trees of .
- (A) prove that and have at least one common edge.
- Assume for contradiction that and have no common edges.
- That is, .
- Let’s take some edge in that it is not in .
- Since is a tree of shortest paths, there is a path from to in such that .
- Let’s denote the graph as the graph that is the same as but with inserting of the path and removing the edge and removing some other edge .
- Therefore, . (since )
- So we have a spanning tree such that , which contradicts the assumption that is a minimum spanning tree.
- (B) show a sequence of graph with and a source vertex and integer positive weights such that the graph has and that have exactly one common edge.
Q4
- Prove that for every rooted binary tree with leaves, there exists a frequency sequence s.t. one of the Huffman trees for this frequency sequence is .
- Let’s use in induction on the number of leaves in the tree .
- Base Case ():
- A full binary tree with leaves consists of a single root with two child nodes (the leaves). Huffman’s algorithm, when provided with two frequencies and , will always construct a tree where these two nodes are combined into a root. Thus, any with leaves is trivially realizable by Huffman’s algorithm.
- Inductive Hypothesis:
- Assume that for any full binary tree with leaves, there exists a frequency sequence such that Huffman’s algorithm produces .
- Inductive Step
- Select two leaves and at the maximum depth. Let the parent of these leaves be .
- If we remove and from and replace their parent with a single new leaf . This creates a new tree with leaves.
- By the inductive hypothesis, there exists a frequency sequence for the leaves of such that Huffman’s algorithm can reconstruct .
- Let’s define frequencies of and be and , respectively, such that , where is the frequency of in . Assign and such that they are distinct and smaller than all other frequencies in .
- In the first step of Huffman’s algorithm, the two smallest frequencies and will be merged into , producing . By the inductive hypothesis, the remaining steps of the algorithm will reconstruct , and hence is produced.