Você está na página 1de 3

Cover page for

CSC263 Homework #4
(fill and attach this page to your homework)

Submitted by:

(1) Family Name: (2) Family Name:

Given Name: Given Name:

Student Number: Student Number:

Graded Homework should be returned in Tutorial: (tutorial room number)

By virtue of submitting this homework I/we acknowledge that I am/we are aware of the policy on
homework collaboration for this course.
Computer Science CSC263H March 17, 2011
St. George Campus University of Toronto

Homework Assignment #4
Due: April 7, 2011, by 5:30 pm
(in the drop box for this course in Bahen 2220)

1. On the cover page of your assignment, in addition to your name(s), you must write the location of
the tutorial where you want the graded homework to be returned.

2. If you do not know the answer to a question, and you write “I (We) do not know the answer to this
question”, you will receive 20% of the marks of that question. If you just leave a question blank
with no such statement, you get 0 marks for that question.

3. Unless we explicitly state otherwise, you should justify your answers. Your paper will be marked
based on the correctness and completeness of your answers, and the clarity, precision and conciseness
of your presentation.

Question 1. (20 marks)


In this question, we are interested in the amortised complexity of incrementing by one a number represented
in base 3 notation. Instead of using bits (0 and 1) as in base 2 notation, we use trits, 0, 1 and 2, to
represent this number. We define the time required to increment x to be the number of trits that must
change to get x + 1. For example, the time to increment the number x whose base 3 representation is
12201222 is exactly 4 (because x+1 is 12202000, so 4 trits changed), and the time to increment the number
x whose base 3 representation is 2222 is exactly 5 (because x + 1 is 10000, so 5 trits changed).
Let A(n) be the amortised time per increment operation when we perform a sequence of n successive
increments, starting from the number 0. For example, A(3) = 43 .
In this question, we want you to give an upper bound on A(n). More precisely:
Consider the list 43 , 12
17 3 7
, 2 , 4 , 2, 25 (note that the numbers in this list are sorted from smallest to largest).
What is the smallest number c in this list such that A(n) ≤ c for all n ≥ 1?
Prove the correctness of your answer in two ways: first analyse A(n) using the aggregate method, and then
analyse A(n) using the accounting method with an appropriate charging scheme.
Make sure you justify why your answer is the smallest such c from the list.

Question 2. (15 marks) Solve the Film Star Problem. You walk into a bar in Toronto during the
International Film Festival, and you want to determine whether there is a film star among the n ≥ 2
customers that are at this bar. By definition, a customer is a film star if both:

1. every customer at the bar knows the film star, and

2. of course, the film star does not know anyone in the bar (except him/herself).

To determine whether there is a film star (and if so to determine who it is), you can choose any customer
in the bar and ask him (her) “excuse me, Sir (Madam), do you know this person over there? ” while you are
pointing at another bar customer. All you get is a dry yes/no answer. You can ask several such questions.
Of course, you can assume that every customer knows him/herself.
Since you are a CSC263 alumnus, to solve this problem you decide to model the above situation as a
directed graph G = (V, E), where the set of nodes V = {1, 2, . . . , n} represents the n customers, and the
set of (directed) edges E is such that (i, j) ∈ E iff customer i knows customer j. A film star is any node
x ∈ V such that: (i) for all j, (j, x) ∈ E, and (ii) for all j 6= x, (x, j) 6∈ E. You assume that you are given
the adjacency matrix A of G: with this assumption, asking customer i whether he/she knows customer j
(which takes constant time) corresponds to checking the value of A(i, j) (which also takes constant time).
a. (12 marks) Give an efficient algorithm to determine whether there is a film star in the bar, and if so,
to find which customer it is. Your algorithm should use the above matrix representation of the problem.
Describe your algorithm using pseudo-code and prove it correct.
To obtain full marks, your algorithm should be minimum in the “number of questions that it asks”
(i.e., the number of accesses the adjacency matrix A) in the worst-case.
b. (3 marks) How many questions does your algorithm asks (i.e., how many times it accesses the
adjacency matrix A) in the worst-case? Give the exact number (i.e., do not use the asymptotic notation)
and justify your answer.

Question 3. (10 marks)


In this question, G is a connected undirected graph (without edge weights) and s is a vertex of G.
A shortest-path tree of G rooted at s is a spanning tree T of G rooted at s such that for every vertex v of G,
the path from s to v in T is a shortest-path from s to v in G.
Prove or find a counterexample to the following claim:
For every G and every s, every shortest-path tree of G rooted at s is a Breadth-First Search tree of G.

Question 4. (15 marks)


This question is about the Minimum Spanning Tree (MST) of the following weighted undirected graph G
(G has 8 nodes, a, b, c, d, e, f , g, h, and 14 edges, weighted from 1 to 14):

d
12 2
6
14 8
b c e
4

a 1 9 13 3 7

5
h g f
10 11

a. (8 marks) Perform Kruskal’s MST Algorithm on G, and list the edges of the MST found by the
algorithm, in the order in which the algorithm finds them. Give only this sequence of edges (and nothing
else).
b. (7 marks) Perform Prim’s MST Algorithm on G starting from vertex c, and list the edges of the
MST found by the algorithm, in the order in which the algorithm finds them. Give only this sequence of
edges (and nothing else).

Você também pode gostar