0% found this document useful (0 votes)
102 views

Homework 1: You Are Allowed To Have at Most 4 Collaborators

This document describes Homework 1 for COMPSCI 311: Introduction to Algorithms. It includes 5 problems related to algorithms, their analysis, and graph theory. Students are instructed to work in groups of up to 4 but write solutions individually. They must list collaborators and any outside help. For algorithm design problems, they must provide pseudocode, analysis of correctness and running time. Solutions should be submitted as PDFs.

Uploaded by

mah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Homework 1: You Are Allowed To Have at Most 4 Collaborators

This document describes Homework 1 for COMPSCI 311: Introduction to Algorithms. It includes 5 problems related to algorithms, their analysis, and graph theory. Students are instructed to work in groups of up to 4 but write solutions individually. They must list collaborators and any outside help. For algorithm design problems, they must provide pseudocode, analysis of correctness and running time. Solutions should be submitted as PDFs.

Uploaded by

mah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COMPSCI 311: Introduction to Algorithms Spring 2021

Homework 1
Released 2/09/2020 Due 2/22/2020 11:59pm in Gradescope

Instructions. You may work in groups, but you must write solutions yourself. List collaborators on your
submission. You are allowed to have at most 4 collaborators. Also list any sources of help (including online
sources) other than the textbook and course staff.
If you are asked to design an algorithm, please provide: (a) the pseudocode or precise description in words
of the algorithm, (b) an explanation of the intuition for the algorithm, (c) a proof of correctness, (d) the
running time of your algorithm and (e) justification for your running time analysis.
Submissions. Please submit a PDF file. You may submit a scanned handwritten document, but a typed
submission is preferred. Please assign pages to questions in Gradescope.

1. (20) Latin Squares and Stable Matching. A Latin square is an n × n array of numbers, each in
the set {1, . . . , n}, such that no number appears twice in any row or any column. The following array
of numbers is an example of a Latin square:

1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3

If we have a preference list where each college ci ranks the n students, we can represent this list by an
n × n array where the ith row represents the peferences of college ci . Another n × n array can represent
the preferences of the n students.
a) Suppose that the preference list of the colleges is a Latin square. What is the largest and smallest
number of proposals in a run of the Gale-Shapley algorithm (with colleges proposing) under this
condition? (We assume nothing about the student preferences.) If you can’t get the exact number of
proposals as a function of n, find a function f such that you can show the number to be Θ(f ).
b) Now suppose that the preference list of the students is a Latin square. Find the exact minimum
possible number of proposals in any run of the Gale-Shapley algorithm (with colleges proposing) under
this condition? (We assume nothing about the college preferences.) This means finding a function
f such that for any n, there is a run with exactly f (n) proposals and no run with fewer than f (n)
proposals.
c) Find a function g such that the maximum number of proposals on a run of Gale-Shapley with the
student preference lists a Latin square and the colleges proposing is Θ(g).
d) (extra credit) Find the exact maximum number of proposals possible under this condition, with the
colleges proposing. This means finding a function g so that there is a run with g(n) for every n, and
no run ever has more than g(n).
2. (20 points) Big-O and big-Ω. For each function f (n) below, find (1) the smallest integer constant
H such that f (n) = O(nH ), and (2) the largest positive real constant L such that f (n) = Ω(nL ).
Otherwise, indicate that H or L do not exist. All logarithms are to base 2.
a) f (n) = (3n + 1)(2n − 3)(n + 2).
Pn
b) f (n) = k=1 k 2 .
c) f (n) = 4log(n) .

log n
d) f (n) = 2 .

1
Homework 1 2

3. (20 points) Running time analysis. In the lecture, we consider the following program, that takes
an array of n elements as the input.

SumOfProduct(A[1, . . . , n])
1. s ← 0; x ← 0; y ← 0
2. for i ← 1 to n
3. x ← x + 1/i
4. if x ≥ y + 1
5. y ←y+1
6. for j ← 1 to n
7. s ← s + A[i] · A[j]
8. return s

Prove that the running


Pn time of SumOfProduct is Θ(n log n). You may use the fact that the harmonic
number H(n) = i=1 1i satisfies H(n) = Θ(log n).
4. (20 points) Articulation Points. An articulation point of a connected undirected graph G is a
vertex whose removal disconnects G (creating several connected components). We can find articulation
points using depth-first search.
a) Prove that the root of the DFS tree of G is an articulation point of G if and only if it has at least
two children.
b) Prove that a node v other than the root is an articulation point of G if and only if it has a child s
such that there is no back edge from s or any descendant of s to a proper ancestor of v.
c) Let all nodes v begiven a number v.d in order of their discovery, with the root being first.
v.d
Define v.low = min
w.d, where (u, w) is a back edge for some descendant u of v
Show how to compute v.low for all vertices in O(|E|) time.
d) Show how to compute all articulation points in O(|E|) time.

5. (20 points) Three-Color Search (after Jeff Erickson) One way to describe a generic graph search
is by marking each vertex using one of three colors: white, gray, or black.
ThreeColorStep()
v ← any gray vertex
ThreeColorSearch(s):
if v has no white neighbors then
color all nodes white
color v black
color s gray
else
while at least one vertex is gray do
w ← any white neighbor of v
ThreeColorStep()
parent(w) ← v
color w gray
a) Prove that ThreeColorSearch maintains the following invariant: no black vertex is a neighbor
of a white vertex.
b) Prove that after ThreeColorSearch(s) terminates, all vertices reachable from s are black, all
vertices not reachable from s are white, and that the parent edges v → parent(v) define a rooted
spanning tree of the component containing s.
Hint: as the search progresses, black nodes are “explored”, and gray nodes are the frontier (“discov-
ered”).
c) Prove that thee following variant of ThreeColorSearch, which maintains the set of gray vertices
in a stack, is equivalent to depth-first search. (Hint: the order of the last two highlighted lines matters.)
Homework 1 3

ThreeColorStackStep()
pop v from the stack
ThreeColorSearch(s): if v has no white neighbors then
color all nodes white color v black
color s gray else
push s onto the stack w ← any white neighbor of v
while at least one vertex is gray do parent(w) ← v
ThreeColorStackStep() color w gray
push v onto the stack
push w onto the stack

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy