CMPT 405/705  Design and Analysis of Algorithms:
Solutions to Problem Set 2
February 14, 2014
Solve the following 6 problems from the KleinbergTardos textbook. As most of these
problem have rather lengthy descriptions (with reallife settings and exampl
CMPT 405/705  Design and Analysis of Algorithms:
Problem Set 3
March 3, 2014
Solve the following 5 problems from the KleinbergTardos textbook.
1. Chapter 7 (Network Flows): problems 6, 12, 19, 44, 45.
1
CMPT 405/705  Design and Analysis of Algorithms:
Solutions to Problem Set 3
March 10, 2014
Solve the following 5 problems from the KleinbergTardos textbook.
1. Chapter 7 (Network Flows): problems 6, 12, 19, 44, 45.
7.6 Construct a bipartite graph G = (V
Approximation algorithms
Some optimisation problems are hard, little chance of finding polytime algorithm
that computes optimal solution
largest clique
smallest vertex cover
largest independent set
But: We can calculate a suboptimal solution in poly
CMPT 405/705 Problem Sheet 4
June, 4 and 11, 2015
Problem 1 (10 marks)
Prove the Integrality theorem: if the capacity function c takes only integral values, then the
maximum ow f produced by the FordFulkerson method has the property that f  is integerv
CMPT 405/705 Problem Sheet 2
May, 21, 2015
Problem 1 (10 marks)
You are at a conference and there are n presentations and you would like to attend quite a few
of the presentations. Every presentation has a start time and a fnishing time, s1 , . . . , sn a
CMPT 405/705 Problem Sheet 3
May, 28, 2015
Problem 1 (10 marks)
Assume we are given a connected graph G = (V, E) where all edges have dierent weights. Show
that the following is true: there exists only one minimum spanning tree.
Problem 2 (10 marks)
Somet
CMPT 405/705 Problem Sheet 1
May, 14, 2015
Problem 1 (10 marks)
A clique in a graph G = (V, E) is a set of vertices U V which form a complete subgraph of G.
(So all edges between vertices in U are present in G.)
Consider the following Greedy algorithm for
29/07/2016
312
Algorithms LPRounding
Weighted Vertex Cover
Weighted vertex cover
Instance
An undirected graph G = (V, E) with vertex weights wi 0
Objective
Find a minimum weight subset of nodes S such that every edge is
incident to at least one vertex i
7/25/2016
Algorithms Approximation
262
Approximation Algorithms
Approximation
Design and Analysis of Algorithms
Andrei Bulatov
Algorithms Approximation
Suppose I need to solve an NPhard problem. What should I do?
Theory says you're unlikely to find a po
14/07/2016
332
Algorithms Markov Chains
Land of Oz Weather
In the land of Oz weather is unpredictable. Almost.
However, it is known that if it is rainy today, rain continues tomorrow with
probability 1/2, weather will be nice tomorrow with probability 1/
7/10/2016
Algorithms Closest Pair
242
Closest Pair: The Problem
The Closest Pair Problem
Instance:
n points in the plane
Objective:
Find a pair of points that are closest together
Closest Pair
min
Design and Analysis of Algorithms
Andrei Bulatov
Algorith
Algorithms More Approximation
272
Center Selection Problem
Input. Set of n sites s1, , sn.
Center selection problem (informal).
Select k centers C so that maximum distance from a site to
nearest center is minimized.
More Approximation
k=4
r(C)
Design and
12/07/2016
251
Algorithms Primes
252
Algorithms Primes
e
e
e

?ss
0s
Primes
s
E
ssk.
?
 sk
.
L s
s ss
rss
L
ss
ss s ss
 svBBush0
ss s hss
s
sl ss
ssM
ss
s
ss
s
rss
s ss
s s
hss
s s
http:/www.cse.iitk.ac.in/news/primality.htmly
w
s
s0
F
s s0
0
s1
rs
s
342
Algorithms Markov Chains
a:
Lss 4
4 s

ssl

s

yss s4ssxhzhs s4s
4 s

ss
s s 4 ss / s 4
Ps F
ss s4 s
/ s ssFss s
4 ssu
E
Stationary Distribution
1/ 2 1 / 4 1/ 4
P = 1/ 2 0 1/ 2
j4 s s3
1/ 4 1 / 4 1/ 2
1 / 2 1/ 4 1 / 4
( x, y , z ) = ( x, y , z
Cmpt405/705
Assignment 6
June 25, 2015,
Problem 1. The subgraphisomorphism problem takes two graphs G1
and G2 and asks whether G1 is isomorphic to a subgraph of G2 . Show that
the subgraphisomorphism problem is N Pcomplete.
Two graphs H1 and H1 are is
Cmpt405/705
June 22, 2015,
Assignment 5
Problem 1. How would you dene a TM with 3 tapes? Can a 3tape TM
do more in polynomial time than a TM with one tape?
Problem 2. Show that any language in N P can be decided by an algorithm
k
running in time 2O(n )
A Multitape Turing machine is like an ordinary Turing machine with several tapes. Each tape has its own head for reading and writing. Initially the input appears on tape 1, and the others start out blank.[1]
This model intuitively seems much more powerfu
Complexity Theory
So far in this course, almost all algorithms had polynomial running time, i.e., on
inputs of size n, worstcase running time is O(nk ) for some constant k.
Is this always the case?
Obviously no (just consider basic FF algorithm: running
Flow networks, flow, maximum flow
Can interpret directed graph as flow network.
Material courses through some system from some source to some sink.
Source produces material at some steady rate, sink consumes at same rate.
Examples:
water through system o
Greedy Algorithms
The Greedy strategy is (just like D&C or DP) a design paradigm.
General idea: Greedy algorithms always make choices that look best
at the moment.
They do not always yield optimal results, but in many cases they do
(and if not, then often
Minimum spanning trees
One of the most famous greedy algorithms
(actually rather family of greedy algorithms).
Given undirected graph G = (V, E), connected
Weight function w : E IR
For simplicity, all edge weights distinct
Spanning tree: tree that con
Allpairsshortestpaths
Directed graph G = (V, E), weight function
w : E ! IR, V  = n
Pk 1
Weight of path p = (v1, v2, . . . , vk ) is w(p) = i=1 w(vi, vi+1)
Assume G contains no negativeweight cycles
Goal: create nn matrix of shortest path distan
Cmpt405/705
January 27, 2016
Assignment 3
Problem 1
Assume we are given a connected graph G = (V, E) where all edges have different weights.
Show that the following is true: there exists only one minimum spanning tree.
Problem 2
Sometimes when calculatin
Cmpt405/705
January 13, 2016
Assignment 1
Problem 1
Assume we have a set of n jobs to execute, each of which takes unit time. At any time we
can serve exactly one job. Job i, 1 i n earns us a profit gi > 0 if and only if it is
executed no later than time
Cmpt405/705
February 5, 2016
Assignment 4
Problem 1
Show that a maximum flow in a network G = (V, E) can always be found by a sequence of
at most E augmenting paths.
Hint: Determine the paths after finding the flows!
Problem 2
Assume we are given a con
Cmpt405/705
January 20, 2016
Assignment 2
Problem 1
You are at a conference and there are n presentations and you would like to attend quite a
few of the presentations. Every presentation has a start time and a fnishing time, s1 , . . . , sn
and f1 , . .
Introduction to Analysis of Algorithms
CS4820 Spring 2013
Notes on Turing Machines
Monday, April 1, 2013
These notes are adapted from [10].
1
Turing Machines and Eective Computability
In these notes we will introduce Turing machines (TMs), named after Ala
CS3261 Computability and Models of Computation
Summer 2002
Instructor: Michel Galley
Homework 4
(solutions)
Exercise 1: Unrestricted Grammars
a) The language accepted iscfw_a n bn c n  n 1 .
b) One of the many solutions:
S
T
Ba
Bb
aTb 
aBTaB  ba
aB
bb
6/21/2016
221
Algorithms More Randomization
212
Algorithms Randomization
Contention Resolution in a Distributed System
Contention resolution
Instance
Given n processes P1 ,K, Pn , each competing for access to a
shared database. If two or more processes
42
Algorithms Divide and Conquer
v
v
Mv
E?Z
?s*
Ssss1* s
3 H?s* Hs1
? *
k s*s ? s s
k ?s ?
?Z
1 ?s
s s
Divide and Conquer
? ? ? s s ?
Ssss
?
lH H?y
? sslZ
?y
?
lZ ?y
? ?k
3 H?Sssk s*s ? s ? ? Z?ss s * ?
1
? Sss7 sZ* s ? s s ?s s * ?
1 ?Ssss? ?s ?s s ?
5/18/2016
62
Algorithms Dynamic Programming
a
a
 QVp
?s V s Yss s 6 VQ rsVQ s Ys Q s  ss
Vs VHV s  Vssssssssssssssssssssssssssssss
vi
wi
 8ss
Vs VHV ss V H sssssssshsss?s
V H s ss5h
6 VQ Vp
EV VQ s 6 VQ s s  s V s  s V H s8 V s sV QVV8ss5rs 8s
Algorithms Sequence Alignment
Algorithms Sequence Alignment
82
The Sequence Alignment Problem
Question:
How similar two words are?
Say ocurrance and occurrence
They are similar, because one can be turned into another by few
changes
ocurrance
mismatch
ga