Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CSE5311 FinalExamPractice

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Design and Analysis of Algorithms

CSE 5311
Final Exam Practice

Junzhou Huang, Ph.D.


Department of Computer Science and Engineering

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 1


Midterm Exam
Covered Contents
Chapter 15, Dynamic Programming
Chapter 16 Greedy Algorithm
Chapter 22 Graph Algorithm
Chapter 23 Minimum Spanning Trees
Chapter 24 Single-Source Shortest Paths
Chapter 25 All-pairs Shortest Paths
Chapter 26 Maximum Flow

Questions
PART I. False and True (10 x 1pts=10pts)
PART II. Multiple Choices (10 x 3pts=30 pts)
PART III. Algorithm Questions (6 x 10pts=60pts)

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 2


How to review
Questions
60% of questions come from the questions in Homework Assignments

How
Homework Assignments
Lectures
Textbooks

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 3


Practices
True and False
For a dynamic programming algorithm, computing all values in
a bottom-up fashion is asymptotically faster than using recursion
and memoization.

Solution: False. A bottom-up implementation must go through all of


the subproblems and spend the time per subproblem for each. Using
recursion and memoization only spends time on the subproblems that it
needs. In fact, the reverse may be true: using recursion and memoization
may be asymptotically faster than a bottom-up implementation.

Dijkstras shortest-path algorithm may relax an edge more than once in


a graph with a cycle.

Solution: False. Dijkstras algorithm always visits each node at most once; this
is why it produces an incorrect result in the presence of negative-weight edges.
Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 4
Multiple Choices
Which of the following algorithms can be used to solved
single source or all-pairs shortest paths problem in general
non-negative weighted graph. [c, d, e]
a. Breadth-first search
b. Depth-first search
c. Bellman-Ford algorithm
d. Dijkstra's algorithm
e. The Floyd-Warshall algorithm

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 5


Multiple Choices
What is the asymptotic time complexity of the dynamic
programming algorithm for matrix-chain multiplication
problem. [c]
a) O(n)
b) O(n2)
c) O(n3)
d) O(nlgn)
e) O(n2lgn)

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 6


Multiple Choices
What is the asymptotic time complexity of Dijkstra's
algorithm on a general non-negative weighted connected
graph with n vertexes and m edges. [c]
a) O(n+m)
b) O(m+nlgn)
c) O(mlgn)
d) O(n3)
e) O(mn)

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 7


Algorithm Questions
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.

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 8


Algorithm Questions
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.

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 9


Algorithm Questions
Answer
Create a graph G where each vertex represents a wrestler and
each edge represents a rivalry. The graph will contain n vertices
and r edges.
Perform as many BFSs as needed to visit all vertices. Assign all
wrestlers whose distance is even to be babyfaces and all
wrestlers whose distance is odd to be heels. Then check each
edge to verify that it goes between a babyface and a heel.
This solution would take O(n+r) time for the BFS, O(n) time
to designate each wrestler as a babyface or heel, and O(r) time
to check edges, which is O(n + r) time overall.

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 10


Algorithm Questions
Professor Adam has two children who, unfortunately, dislike
each other. The problem is so severe that not only do they
refuse to walk to school together, but in fact each one refuses
to walk on any block that the other child has stepped on that
day. The children have no problem with their paths crossing at
a corner. Fortunately both the professors house and the
school are on corners, but beyond that he is not sure if it is
going to be possible to send both of his children to the same
school. The professor has a map of his town. Show how to
formulate the problem of determining whether both his
children can go to the same school as a maximum-flow
problem.

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 11


Algorithm Questions
Answer
Create a vertex for each corner, and if there is a street between
corners u and v, create directed edges (u,v) and (v,u). Set the
capacity of each edge to 1. Let the source be corner on which
the professors house sits, and let the sink be the corner on
which the school is located. We wish to find a flow of value 2
that also has the property that f(u,v) is an integer for all vertices
u and v. Such a flow represents two edge-disjoint paths from
the house to the school.

Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 12

You might also like