CISC/CMPE-365*
Test #2
October 18, 2013
Student Number (Required) _
Name (Optional)_
This is a closed book test. You may not refer to any resources.
This is a 50 minute test.
Please write your answers in ink. Pencil answers will be marked, but will not be

Solution for Test 3, Fall 2010
1. Explain/justify the recursive formula for matrix-chain multiply. The value m[i,j] is the
minimum cost for multiplying matrices Ai-1 . Aj, with matrix dimensions p0 . pn.
First case: if there is only one matrix in the lis

Linear Programming
Many problems take the form of maximizing or minimizing an objective, given
limited resources and competing constraints. If we can specify the objective as
a linear function of certain variables, and if we can specify the constraints on

NP-completeness and the classes P and NP
Throughout this chapter, we shall refer to three classes of problems: P, NP, and
NPC, the latter class being the NP-complete problems. We describe them informally
here, and we shall define them more formally later

Elements of the greedy strategy
A greedy algorithm obtains an optimal solution to a problem by making a sequence
of choices. At each decision point, the algorithm makes choice that seems best at
the moment. This heuristic strategy does not always produce

DepthFirstSearch
The strategy followed by depth-first search is, as its name implies, to search
deeper in the graph whenever possible. Depth-first search explores edges out
of the most recently discovered vertex _ that still has unexplored edges leaving i

Dynamic Programming
Because both the greedy and dynamic-programming strategies exploit optimal substructure,
you might be tempted to generate a dynamic-programming solution to a
problem when a greedy solution suffices or, conversely, you might mistakenly

Greedy Algorithms
Algorithms for optimization problems typically go through a sequence of steps,
with a set of choices at each step. For many optimization problems, using dynamic
programming to determine the best choices is overkill; simpler, more efficie

GraphAlgorithms
Representations of graphs
We can choose between two standard ways to represent a graph G D .V;E/:
as a collection of adjacency lists or as an adjacency matrix. Either way applies
to both directed and undirected graphs. Because the adjacenc

NP Completeness
Almost all the algorithms we have studied thus far have been polynomial-time algorithms:
on inputs of size n, their worst-case running time is O.n k/ for some constant
k. You might wonder whether all problems can be solved in polynomial ti

MinimumSpanningTrees
Electronic circuit designs often need to make the pins of several components electrically
equivalent by wiring them together. To interconnect a set of n pins, we can
use an arrangement of n _ 1 wires, each connecting two pins. Of all

KruskalsAlgorithm
The two minimum-spanning-tree algorithms described in this section elaborate on
the generic method. They each use a specific rule to determine a safe edge in line 3
of GENERIC-MST. In Kruskals algorithm, the set A is a forest whose verti

CISC-365*
Test #1
October 3, 2008
Student Number (Required) _
Name (Optional)_SOLUTIONS
This is a closed book test. You may not refer to any resources.
This is a 50 minute test.
Please write your answers in ink. Pencil answers will be marked, but may not

Answers for Test 2, CISC 365 Fall 2010
1. If one NP-complete problem has an exponential lower bound, then all NP-complete
problems have an exponential lower bound. This is because all NP-complete problems are
reducib

Answers for Test 1
1. From the given information we concluded that g(n)(n2) or g(n)o(n2). In other
words, g(n)O(n2). Therefore the answers are no, maybe, maybe, yes, maybe.
2. The for loop runs log n times, a

Solution for CISC 365 Test 4, Fall 2010
1. No, greedy is not optimal. Consider this counterexample.
Task 1 starts at 1, ends at 3 (length 2)
Task 2 starts at 4, ends at 6 (length 2)
Task 3 starts at 2, ends at 5 (length 3)
Greedy selects task 3, and there

CISC/CMPE-365*
Test #3
November 1, 2013
Student Number (Required) _
Name (Optional)_
This is a closed book test. You may not refer to any resources.
This is a 50 minute test.
Please write your answers in ink. Pencil answers will be marked, but will not be

CISC-365*
Test #2
October 17, 2008
Student Number (Required) _
Name (Optional) _
This is a closed book test. You may not refer to any resources.
This is a 50 minute test.
Please write your answers in ink. Pencil answers will be marked, but may not be
reco

BreadthFirstSearch
Breadth-first search is one of the simplest algorithms for searching a graph and
the archetype for many important graph algorithms. Prims minimum-spanningtree
algorithm (Section 23.2) and Dijkstras single-source shortest-paths algorithm