CS2040 Tutorial9 Qns
CS2040 Tutorial9 Qns
Problem 1. Skyscrapers
There are n skyscrapers in a city, numbered from 1 to n. You would like to order the skyscrapers
by height, from the tallest to the shortest. Unfortunately, you do not know the exact heights of
the skyscrapers.
Problem 1.a. Suppose that you have m pieces of information about the skyscrapers. Each piece
of information tells you that skyscraper x is taller than skyscraper y for some pair of skyscrapers
x and y. Describe the most efficient algorithm you can think of to output any one
possible ordering of the buildings by height which is consistent with the m pieces of
information given. What is the running time of your algorithm?
Problem 1.b. Suppose that you have m pieces of information about the skyscrapers. Each
piece of information tells you one of the following regarding two skyscapers x and y:
x is taller than y
Describe the most efficient algorithm you can think of to output any one possible
ordering of the buildings by height. What is the running time of your algorithm?
For each of the following, determine if the statement is True or False, justifying your answer with
appropriate explanation.
c) For a graph with unique edge weights, the edge with the largest weight in any cycle of the
graph can be included in the MST.
d) For a graph with two disjoint sets of vertices A and B (vertices in A are not in B and vice
versa), and another vertex x not inside both the sets, the combined MST of A ∪ x and B ∪ x
is a MST of the original graph.
1
Problem 3. Lets add some new stuff !
Given a graph G with V vertices and E edges, and the unique Minimum Spanning Tree (MST) of
G (i.e G has only 1 MST), give an algorithm (including the time complexity) to update the MST
if
Problem 3.b. A new vertex Y, along with a set of edges connecting Y to the rest of the graph,
is inserted to G.
An ambitious cable company has obtained a contract to wire up the government offices in the city
with high speed fiber optics to create a high speed intra-net linking up all the different governmen-
tal departments. In the beginning they were confident that the minimum cost of connecting all
the offices will be within budget. However, they later found they made a miscalculation, and the
minimum cost is in fact too costly. In desperation, they decided to group the government offices
into K groups and link up the offices in each group, but not offices between groups to save on the
cost. This effectively creates k intra-nets instead of one big intra-net.
Given V government offices, the cost of linking E pairs of government offices, and a budget b, help
the company design a program which will tell them what is the smallest value of k (so as to minimize
the number of intra-nets). The program also needs to output the government offices in each of the k
groups and how they should be linked such that the total cost of all selected links is within budget b.
The program should model the problem as a graph. It should also run in O(E log V )time. Where
E and V are the number of vertices (government offices) and edges (possible links between those
government offices), respectively.
Please look at the CS2010 AY2011/2012 S1 Final Exam paper in the ‘2011-12-S1-final.pdf’ file
that came in the same zip file as the tutorial questions and solve the problem titled: Vehicle
Monitoring System.
2
Figure 3: An example of power plants, sites and cables
Figure 4: An example of the edges chosen to minimise total cost of cables to build
Indonesia is the worlds largest archipelago with approximately 17,000 islands scattered for more
than 5,000 km from Sabang (west most) in Sumatra island to Merauke (east most) in Papua island.
Thus, providing electricity in all cities and towns across all islands is a challenging problem for the
government.
Power plants, cities, towns and all other important sites can be represented as a graph where
each node represents a site and each edge which connects two different sites represents a cable
transferring electricity between the two sites in both directions. You may assume that all sites
are connected through some cables and for each pair of sites there is at most one cable connecting
them. There is of course a cost to maintain each cable and some of them probably have a very high
cost to maintain.
The government has a plan to calculate the minimum total cost to maintain only necessary cables
such that all sites are connected to at least one power plant, except for the power plants (which
are already connected to themselves). A site is considered connected to a power plant if and only
if there is a path which consists of only maintained cables from the site to a power plant.
Consider the following example. There are 9 sites and 3 of them are power plants (A, H and I).
The connectivity and the cost of each cable are shown in Figure 3. The minimum total cost to
maintain the cables in this example is 22 as shown in Figure 4.
Given an undirected graph (which you may assume is stored in an adjacency list) which represents
the connectivity between all sites, determine the minimum total cost needed to maintain cables
such that all sites except power plants are connected to at least one power plant.