Vous êtes sur la page 1sur 7

1

Name:

CS343: Analysis of Algorithms, Sp 04

Final Exam

Score:

1.
2.
3.

(max 13)
(max 25)
(max 25)
Total:

4.
5.

(max 15)
(max 22)
(max 100)

This exam is closed book. Calculators are not allowed.

1. (13 pts) Indicate for each pair of expressions (A and B) in the table below, whether A is
O, o, , , or of B. Assume that k 1, and c > 1. You should fill in a yes or no
in each slot of the table.

log10 n

lg n

lg6 n

nk

cn

clg n

nlg c

n!

22

CS 343 Analysis of Algorithms, Spring 2004: Final Exam

2. (25 pts total) Willamette student, Willamina, is taking her computer science algorithms
exam. She notices that the professor has assigned points to each problem according
to the professors opinion of the difficulty of the problem. Unfortunately, Willaminas
studying was a bit spotty so her opinion of the difficulty of each problem differs quite a
bit from the professors. However, Willamina does understand greedy algorithms so she
decides to apply a greedy algorithm to her test taking. For each problem, she estimates
how much time it will take her to complete the problem. Her goal is to maximize the
points she will receive given that {p1 , p2 , ..., pn } are the number of points assigned by
the professor to each of the n problems, {t1 , t2 , ..., tn } are Willaminas estimates of the
time required to do each problem, and T is the total time available for taking the exam.
Note, partial credit is given to problems that are partially done.
(a) (10 pts) Describe a greedy algorithm that Willamina could use to maximize her
points. (Hint: recall the fractional knapsack problem).

(b) (5 pts) State the greedy choice principle for greedy algorithms.

CS 343 Analysis of Algorithms, Spring 2004: Final Exam


(c) (10 pts) Prove that your algorithm satisfies the greedy choice property.

CS 343 Analysis of Algorithms, Spring 2004: Final Exam

3. (25 pts total) Graphs:

C
E
B

(a) (5 pts) Show the adjacency list for the above graph. In places where more than one
ordering of nodes is allowed, always choose an alphabetical ordering.

(b) (5 pts)What is an articulation point?

CS 343 Analysis of Algorithms, Spring 2004: Final Exam

(c) (5 pts) What are the articulation points in the above graph?

(d) (10 pts) Topologically sort this graph. Show your work and explain what you are
doing to obtain the sort. Note, when faced with a choice, use an alphabetical
ordering.

CS 343 Analysis of Algorithms, Spring 2004: Final Exam

4. (15 pts total) Define a dictionary to be any data structure that allows the following
operations (Assume that no deletions occur):
insert(i): adds the integer i into the dictionary.
find(i): checks to see if the integer i is already in the dictionary.
largest(): returns the largest integer in the dictionary. Note, the value is returned
but the item itself is not removed from the data structure.
Each of the following columns below gives the time complexities associated with a particular data structure (DS).
Operation
insert
find
largest

DS 1
O(lg n)
O(lg n)
O(lg n)

DS 2
O(n)
O(lg n)
O(1)

DS 3
O(1)
O(n)
O(n)

DS 4
O(lg n)
O(n)
O(1)

Give the name of a well known data structure that achieves those complexities on a
dictionary of up to n elements and briefly describe how to implement each of the 3
operations.
For example, DS 3 could correspond to an unsorted list. Insert consists of adding an item
to the end of the list which is O(1). However, find and largest would require searching
through the entire list which is O(n).
(a) (5 pts) DS 1

(b) (5 pts) DS 2

(c) (5 pts) DS 4

CS 343 Analysis of Algorithms, Spring 2004: Final Exam

5. (22 pts) You are playing a game where there is a monster chasing you in a maze. The
maze has a graph structure, possibly with cycles. Your goal is to escape from the maze
before the monster catches you and eats you. You know the following: the maze layout,
your location in the maze, and the monsters location. However, the escape door is
invisible unless you are right in front of it. You and the monster alternate moves. At
each move, the player moving (you or the monster) must move to a node adjacent to the
movers current position in the maze.
After getting eaten multiple times, you decide to write a program to figure out your
moves. That is, at each step in the game, you will consult your program to decide where
to move next. Your strategy wont necessarily guarantee that you escape, but it should
greatly improve your chances. Discuss the issues/challenges of this problem, discuss the
graph algorithms you might use and why (consider the ones we looked at in class or ones
you might create/modify), your general strategy if you have one, and any other details
you feel are important. Note, this problem is intentionally left vague. Be creative and
thoughtful.