Docsity

CS 3510 A: Minimum Spanning Trees and Greedy Algorithms, Assignments of Algorithms and Programming

Toggle sidebar
bg1
CS 3510 A Fall 2005
Homework Set # 4 Due Friday, Oct. 21
1. (10 pts.) Consider the Minimum Spanning Tree Problem on an undirected graph G= (V, E) with a
cost ce≥0 on each edge, where the costs may not all be different. If the costs are not all distinct, there
can in general be many distinct minimum-cost solutions. Supp ose we are given a spanning tree T⊆E
with the property that for every e∈T, e belongs to some minimum-cost spanning tree in G. Can we
conclude that Titself must be a minimum-cost spanning tree in G? Give a proof or a counterexample
with explanation.
2. (10 pts.) Suppose that three of your friends have decided to hike the Appalachian Trail next summer.
They want to hike as much as possible per day but not after dark. On a map they have identified
a large set of good stopping points for camping, and they are considering the following system for
deciding when to stop for the day. Each time they come to a potential stopping point, they determine
whether they can make it to the next one before nightfall. If they can make it, then they keep hiking;
otherwise, they stop.
Despite many significant drawbacks, they claim this system does have one good feature: “Given that
we are only hiking in the daylight, it minimizes the number of camping stops we have to make.
Is this true? The proposed system is a greedy algorithm, and your task is to determine whether it
minimizes the number of stops needed.
Assumptions:
•Model the Appalachian Trail as a long line segment of length L, and assume that your friends
can hike dmiles per day (independent of any other conditions).
•The potential stopping points are located at distances x1, x2,...,xnfrom the start of the trail.
•The estimation about making to the next stopping point before nightfall is always correct.
•The set of nstopping points is valid, i.e. the distance between each adjacent pair is at most d,
the first is at distance at most dfrom the start of the trail, and the last is at distance at most d
from the end of the trail.
Question: Is your friends’ greedy algorithm optimal, in the sense that it finds a valid set whose size
is as small as possible? Give the correctness of the above greedy algorithm or show an example, in
which the algorithm gives a solution with more points than the optimum contains.
3. (20 pts.) Let G= (V, E) be an undirected graph with a cost ce≥0 on each edge. You are given a
minimum spanning tree Tin G. Now we are moving to a dynamic scenario: a new edge is added to G,
connecting two nodes v, w ∈V(G) with cost c.
1
pf2

Partial preview of the text

Download CS 3510 A: Minimum Spanning Trees and Greedy Algorithms and more Assignments Algorithms and Programming in PDF only on Docsity!

CS 3510 A Fall 2005

Homework Set # 4 Due Friday, Oct. 21

  1. (10 pts.) Consider the Minimum Spanning Tree Problem on an undirected graph G = (V, E) with a cost ce ≥ 0 on each edge, where the costs may not all be different. If the costs are not all distinct, there can in general be many distinct minimum-cost solutions. Suppose we are given a spanning tree T ⊆ E with the property that for every e ∈ T, e belongs to some minimum-cost spanning tree in G. Can we conclude that T itself must be a minimum-cost spanning tree in G? Give a proof or a counterexample with explanation.
  2. (10 pts.) Suppose that three of your friends have decided to hike the Appalachian Trail next summer. They want to hike as much as possible per day but not after dark. On a map they have identified a large set of good stopping points for camping, and they are considering the following system for deciding when to stop for the day. Each time they come to a potential stopping point, they determine whether they can make it to the next one before nightfall. If they can make it, then they keep hiking; otherwise, they stop. Despite many significant drawbacks, they claim this system does have one good feature: “Given that we are only hiking in the daylight, it minimizes the number of camping stops we have to make. Is this true? The proposed system is a greedy algorithm, and your task is to determine whether it minimizes the number of stops needed. Assumptions: - Model the Appalachian Trail as a long line segment of length L, and assume that your friends can hike d miles per day (independent of any other conditions). - The potential stopping points are located at distances x 1 , x 2 ,... , xn from the start of the trail. - The estimation about making to the next stopping point before nightfall is always correct. - The set of n stopping points is valid, i.e. the distance between each adjacent pair is at most d, the first is at distance at most d from the start of the trail, and the last is at distance at most d from the end of the trail.

Question: Is your friends’ greedy algorithm optimal, in the sense that it finds a valid set whose size is as small as possible? Give the correctness of the above greedy algorithm or show an example, in which the algorithm gives a solution with more points than the optimum contains.

  1. (20 pts.) Let G = (V, E) be an undirected graph with a cost ce ≥ 0 on each edge. You are given a minimum spanning tree T in G. Now we are moving to a dynamic scenario: a new edge is added to G, connecting two nodes v, w ∈ V (G) with cost c.

1

(a) Give an efficient algorithm to test if T remains the minimum-cost spanning tree with the new edge added to G (but not to T ). Make your algorithm run in time O(|E|). Can you do it in O(|V |) time? Please mention what data structure are you assuming for representing the graph G and the tree T. (b) Suppose T is no longer the minimum-cost spanning tree. Give a O(|E|-time algorithm to update the tree T to the new minimum spanning tree.

  1. (20 pts.)

(a) Prove that in the Huffman coding algorithm if some character occurs with frequency greater than 2 5 ,^ there exists a codeword of length one.^ Also prove that if all charactes occur with frequency less than 13 then, there is no codeword of length one. (Assume that all frequencies add up to 1.) (b) Codex Unlimited manufactures hardware to decode Huffman-encoded game files in an XBox when you play them over a network. Its decoding hardware stores an entire codeword in a register when it is looking for a match. The uncompressed game files contain characters from an alphabet of size n. What is the minimum required register width ( number of bits) that can support all Huffman codes for n characters, no matter what the frequencies f 1 , f 2 ,... , fn are? What relationship between the frequencies f 1 , f 2 ,... , fn causes the worst case (longest codeword) to occur?

  1. (10 pts.) We have seen in class that using Union by rank and path compression ( implemented in Find operation) on disjoint-set forests, we can achieve a running time which is O(m log∗^ n), i.e. almost linear in the total number of disjoint-set operations m. Your task is to give a sequence of m operations (MakeSet, Find, Union) on n elements that takes Ω(m log n) time when we use union by rank only (do not use path compression in Find). You can assume that we start with n MakeSet operations to create singleton sets.