Docsity

Algorithm Design and Analysis - Assignment 1 | ECS 122A, Assignments of Computer Science

Toggle sidebar
bg1
ECS 122A: Algorithm Design and Analysis Homework 1
UC Davis: Charles Martel, Susan Margulies Due Monday, April 14, 2008, 4 PM
Problem Set 1
Homework Info Homeworks are due by 4 PM on the due date. They are to be turned in at the
marked box in K
ĀÆemper Hall, room 2131 (right side). No late homeworks will be accepted.
Much of what one learns in this course comes from trying to solve the homework problems, so work hard on
them. Doing a conscientious job on the homeworks is the best preparation for the exams. We hope that you
will ultimately solve the majority of the problems, but don’t be surprised if some of them stump you; some
of the problems may be quite challenging.
Your solutions should be terse, correct, and legible. Understandability of the solution is as necessary as
correctness. Expect to lose points if you provide a ā€correctā€ solution with a not-so-good writeup. As with
an English paper, you can’t expect to turn in a first draft: it takes refinement to describe something well.
Typeset solutions are always appreciated.
If you can’t solve a problem, briefly indicate what you’ve tried and where the difficulty lies. Don’t try to
pull one over on us.
If you think a problem was misgraded, please see the grader first. (The TA will be the grader for the
homework).
1 Stable Marriage, KT: 1.1 (25 pts)
We claimed in lecture that the stable marriage algorithm could be implemented to run in O(n2)
time. Describe data structures which will allow this run time. In particular you should describe
how to store the preference lists, the current marriage, and the men who are unpaired.
Justify that each proposal now takes O(1) time.
2 Asymptotic running times, KT: 2.1, 2.2, 2.4 (20 pts)
•Show that n3is not O(n2).
•Show that log n=O(n²) for any positive ². Use the fact that log n≤n,āˆ€n > 1.
•Show that n²=O(en) for any positive ².
•Construct a table like KT Table 2.1 for n3and (1.5)3. Identify the point where (1.5)n> n3.
3 Graphs KT: 3 (25 pts)
•For a given vertex v, describe how to decide whether there is a cycle of length 4 containing v.
•Design and analyze an algorithm that given as input an undirected graph G(V, E) decides
in time O(|V|3) whether Gcontains a simple cycle of length four. You may assume that the
input graph is prepresented as an adjacency matrix or as an adjacencey list, whichever makes
your algorithm simpler.
pf2

Partial preview of the text

Download Algorithm Design and Analysis - Assignment 1 | ECS 122A and more Assignments Computer Science in PDF only on Docsity!

ECS 122A: Algorithm Design and Analysis Homework 1 UC Davis: Charles Martel, Susan Margulies Due Monday, April 14, 2008, 4 PM

Problem Set 1

Homework Info Homeworks are due by 4 PM on the due date. They are to be turned in at the

marked box in K ĀÆ

emper Hall, room 2131 (right side). No late homeworks will be accepted.

Much of what one learns in this course comes from trying to solve the homework problems, so work hard on them. Doing a conscientious job on the homeworks is the best preparation for the exams. We hope that you will ultimately solve the majority of the problems, but don’t be surprised if some of them stump you; some of the problems may be quite challenging.

Your solutions should be terse, correct, and legible. Understandability of the solution is as necessary as correctness. Expect to lose points if you provide a ā€correctā€ solution with a not-so-good writeup. As with an English paper, you can’t expect to turn in a first draft: it takes refinement to describe something well. Typeset solutions are always appreciated.

If you can’t solve a problem, briefly indicate what you’ve tried and where the difficulty lies. Don’t try to pull one over on us.

If you think a problem was misgraded, please see the grader first. (The TA will be the grader for the homework).

1 Stable Marriage, KT: 1.1 (25 pts)

We claimed in lecture that the stable marriage algorithm could be implemented to run in O(n^2 ) time. Describe data structures which will allow this run time. In particular you should describe how to store the preference lists, the current marriage, and the men who are unpaired.

Justify that each proposal now takes O(1) time.

2 Asymptotic running times, KT: 2.1, 2.2, 2.4 (20 pts)

  • Show that n^3 is not O(n^2 ).
  • Show that log n = O(n≤) for any positive ≤. Use the fact that log n ≤ n, āˆ€n > 1.
  • Show that n≤^ = O(en) for any positive ≤.
  • Construct a table like KT Table 2.1 for n^3 and (1.5)^3. Identify the point where (1.5)n^ > n^3.

3 Graphs KT: 3 (25 pts)

  • For a given vertex v, describe how to decide whether there is a cycle of length 4 containing v.
  • Design and analyze an algorithm that given as input an undirected graph G(V, E) decides in time O(|V |^3 ) whether G contains a simple cycle of length four. You may assume that the input graph is prepresented as an adjacency matrix or as an adjacencey list, whichever makes your algorithm simpler.

2 ECS 122A Handout 1: Problem Set 1

4 Graphs KT: 3 (15 pts)

One of the following statements is true. Say which one and prove it.

a. If a directed graph G has k strongly connected components, by adding one more edge to G, the number of strongly connected components can drop at most by 1 (i.e the new graph obtained from G by adding one edge has at least k āˆ’ 1 strongly connected components).

b. For every k, there exists a graph G that has k strongly connected components and such that if we add one particular edge to G, we can make it be strongly connected (i.e. the new graph has only 1 strongly connected component).

5 Graphs KT: 3 (15 pts)

In an undirected graph with 2 connected components it is always possible to make the graph con- nected by adding only one edge. Give an example of a directed graph with two strongly connected components such that no addition of one edge can make the graph be strongly connected.