You are on page 1of 5

CS255 HOMEWORK 1

Q1: COMPARISON OF RUNNING TIMES

For each function f (n) and time t in the following table, determine the largest size n of a
problem that can be solved in time t , assuming that the algorithm to solve the problem takes f
(n) microseconds.

Q2: RELATIVE ASYMPTOTIC GROWTHS


Q3: ORDERING BY ASYMPTOTIC GROWTH RATES

Q4: PROVE THAT

Q5: GRAPH REPRESENTATION EXAMPLE

Give an adjacency-list representation for a complete binary tree on 7 vertices. Give an


equivalent adjacency-matrix representation. Assume that vertices are numbered from 1 to 7 as
in a binary heap.

Q6: MULTIGRAPH TO SIMPLE GRAPH

Given an adjacency-list representation of a multigraph G =(V, E), describe an O(V + E)-time


algorithm to compute the adjacency-list representation of the equivalent undirected graph
G=(V,E), where E consists of the edges in E with all multiple edges between two vertices
replaced by a single edge and with all self-loops removed.

Q7: SPECIAL GRAPH

There are two types of professional wrestlers: babyfaces (good guys) and heels (bad
guys). Between any pair of professional wrestlers, there may or may not be a rivalry. Suppose
we have n professional wrestlers and we have a list of r pairs of wrestlers for which there are
rivalries. Give an O(n+r)-time algorithm that determines whether it is possible to designate
some of the wrestlers as babyfaces and the remainder as heels such that each rivalry is
between a babyface and a heel. If it is possible to perform such a designation, your algorithm
should produce it.

Q8: FINDING CONNECTED COMPONENTS

Show that we can use a depth-first search of an undirected graph G to identify the connected
components of G, and that the depth-first forest contains as many trees as G has connected
components. More precisely, show how to modify depth-first search so that it assigns to each
vertex an integer label v.cc between 1 and k, where k is the number of connected components
of G, such that u.cc =v.cc if and only if u and v are in the same connected component.

Q9: INTERNAL SCHEDULING

Suppose that instead of always selecting the first activity to finish, we instead select the last
activity to start that is compatible with all previously selected activities. Describe how this
approach is a greedy algorithm, and prove that it yields an optimal solution.

Q10: GREEDY ALGORITHM

Professor Gekko has always dreamed of inline skating across North Dakota. He plans to cross
the state on highway U.S. 2, which runs from Grand Forks, on the eastern border with
Minnesota, to Williston, near the western border with Montana. The professor can carry two
liters of water, and he can skate m miles before running out of water. (Because North Dakota is
relatively flat, the professor does not have to worry about drinking water at a greater rate on
uphill sections than on flat or downhill sections.) The professor will start in Grand Forks with
two full liters of water. His official North Dakota state map shows all the places along U.S. 2 at
which he can refill his water and the distances between these locations. The professors goal is
to minimize the number of water stops along his route across the state. Give an efficient
method by which he can determine which water stops he should make. Prove that your
strategy yields an optimal solution, and give its running time.

Q11: HUFFMAN CODES

What is an optimal Huffman code for the following set of frequencies, based on the first 8
Fibonacci numbers? a:1 b:1 c:2 d:3 e:5 f:8 g:13 h:21

Can you generalize your answer to find the optimal code when the frequencies are the first n
Fibonacci numbers?
Q13: LOMBARDI GRAPHS

A number of art museums around the country have been featuring work by an artist named
Mark Lombardi (19512000), consisting of a set of intricately rendered graphs. Building on a
great deal of research, these graphs encode the relationships among people involved in major
political scandals over the past several decades: the nodes correspond to participants, and each
edge indicates some type of relationship between a pair of participants. And so, if you peer
closely enough at the drawings, you can trace out ominous-looking paths from a high-ranking
U.S. government official, to a former business partner, to a bank in Switzerland, to a shadowy
arms dealer. Such pictures form striking examples of social networks, which have nodes
representing people and organizations, and edges representing relationships of various kinds.
And the short paths that abound in these networks have attracted considerable attention
recently, as people ponder what they mean. In the case of Mark Lombardis graphs, they hint at
the short set of steps that can carry you from the reputable to the disreputable. Of course, a
single, spurious short path between nodes v and w in such a network may be more coincidental
than anything else; a large number of short paths between v and w can be much more
convincing. So in addition to the problem of computing a single shortest v-w path in a graph G,
social networks researchers have looked at the problem of determining the number of shortest
v-w paths. This turns out to be a problem that can be solved efficiently. Suppose we are given
an undirected graph G = (V , E), and we identify two nodes v and w in G. Give an algorithm that
computes the number of shortest v-w paths in G. (The algorithm should not list all the paths;
just the number suffices.) The running time of your algorithm should be O(m + n) for a graph
with n nodes and m edges.

A Lombardi drawing

You might also like