CMPT 307, Assignment 1
Deadline: Friday, June 13 (5:00 pm)
Problem 0.1 Rank the following functions by the order of growth :
4
n
2log n , 2n , n 3 , n log n, nlog n , 22 , 2
n
You need to arrange them into g1 , g2 , g3 , g4 , g5 , g6 , g7 such that gi (n)
Shortest path with negative edges
June 16, 2014
Shortest path with negative edges
Shortest path from s to t when there are negative weight arcs, but
no negative cycles
A cycle is negative if sum of the weights of its arcs is less than zero.
Lemma
If G has
Dynamic Programming( All pairs shortest
path)
June 25, 2014
Dynamic Programming( All pairs shortest path)
All-pairs shortest paths
Directed graph G = (V , E ), weight function
w : E R, |V | = n
Assume G contains no negative-weight cycles
Goal: create n n
Matching in Bipartite Graphs
July 2, 2014
Matching in Bipartite Graphs
We have a bipartite graph G = (C , R, E ) where R represents a set
of resources and C represents a set of customers.
The edge set shows a customer in C likes (willing to have) a
subset
Exercises
June 23, 2014
Exercises
Going from A to B using one unit diagonal moves
A
,
.
B
From A to B using
A
B
Exercises
Denition : We say a sequence S of 0, 1 is nice if the number of
ones and the number of zeros are the same and
in every prex of S the
Approximation Algorithms (vertex cover)
July 14, 2014
Approximation Algorithms (vertex cover)
Consider a problem that we can not solved in polynomial time.
We may be able to nd a solution that is guaranteed to be close to
optimal and it can be found in po
Approximation Algorithms (Load Balancing)
July 16, 2014
Approximation Algorithms (Load Balancing)
Problem Denition :
We are given a set of n jobs cfw_J1 , J2 , . . . , Jn .
Each job Ji has a processing time ti 0.
We are given m identical machines.
Approxi
Hard Problems (NP problems)
July 9, 2014
Hard Problems (NP problems)
So far we have seen polynomial time problems and we have
designed (attempt) ecient algorithm to solve them.
Hard Problems (NP problems)
So far we have seen polynomial time problems and w
Approximation Algorithms (Travelling
Salesman Problem)
July 18, 2014
Approximation Algorithms (Travelling Salesman Problem)
The travelling-salesman problem
Problem: given complete, undirected graph G = (V , E ) with
non-negative integer cost c(u, v ) for
Divide and Conquer
June 4, 2014
Divide and Conquer
Divide the problem into a number of subproblems
Divide and Conquer
Divide the problem into a number of subproblems
Conquer the subproblems by solving them recursively or if
they are small, there must be a
Dynamic Programming
Shortest path with negative edges
BellmanFord algorithm
Shortest Paths: Failed Attempts
Dijkstra Algorithm: shortest path from s to t
Can fail if negative edge costs.
2
u
3
s
v
1
-6
t
Re-weighting. Adding a constant to every edge weigh
GRAPH SEARCH
BFS & DFS
By: Parminder Benipal
Usage
2
!
!
!
!
Transportation networks (airline carrier, airports as
node and direct flights as edges (direct edge).
Communication networks (a collection of computers as
nodes and the physical link between the
INTERVAL SCHEDULING
Yu-Ta Cheng
IDEAL
We want to schedule jobs on computer.
Given a set of jobs that can be processes on the
computer.
Many jobs request to process at same time but
our computer can only run one job at a time.
Also we can accept only co
Exercises
June 18, 2014
Exercises
Scheduling Jobs with Deadlines and Prots
Problem Statement: We have a resource and many people
request to use the resource for one unit of time.
Conditions:
the resource can be used by at most one person at a time.
we c
Bipartite Matching
Variation of Marriage Problem
Recall marriage problem
Set of men M = cfw_m1, m2, . . . , mn
Set of women W = cfw_w1,w2, . . . ,wn
Want perfect matching M where every man is
married to every woman
Variation of Marriage Problem
Two Ca
A* Algorithm
BY WARREN RUSSELL
Dijkstras Algorithm
In real time, finding a path can be
time consuming.
Especially with all the
extra cells visited.
Is this practical? Could we do better?
A* (A Star)
This is a shortest path algorithm that avoids exhaustive
Santa Clause Problem
Getting to know dynamic programming
Lu Gan Computing Science
What is dynamic programming
is a method for solving complex problems
How?
By breaking them down into simpler sub problems
What kind of sub problem?
a) There are only a po
Divide and Conquer
June 2, 2014
Divide and Conquer
Divide the problem into a number of subproblems
Divide and Conquer
Divide the problem into a number of subproblems
Conquer the subproblems by solving them recursively or if
they are small, there must be a
Dynamic Programming II
June 9, 2014
Dynamic Programming II
DP: Longest common subsequence
biologists often need to nd out how similar are 2 DNA
sequences
DNA sequences are strings of bases: A, C , T and G
how to dene similarity?
Dynamic Programming II
Association Rule Learning
By Jonny Kantor
Association Rule Learning
A method for discovering strong rules
Relationships between items in a transaction
By some measure of user defined 'interestingness'
Without considering the order of items WRT each
other
CMPT 307, Assignment 4
Deadline : Monday August 4 (5:00 pm)
Problem 0.1 Explain when do we use Dijksras algorithm and all pairs shortest path. Please
also explain the algorithm for nding negative cycle in a digraph. What do you know about
these three algo
DYNAMIC PROGRAMMING
A Solution to Complex Problems
WHEN?
Overlapping subproblems
Optimal substructure
OVERLAPPING SUBPROBLEMS
Redundantly solving
problems
Problem with brute-force
approach
(2)
OVERLAPPING SUBPROBLEMS
Redundantly solving
problems
Problem w
CMPT 307, Assignment 3
Deadline Monday July 21 (5:00 pm)
Problem 0.1 Show the steps of all pairs shortest path algorithm on this example.
2
3
4
1
8
-4
2
3
1
-5
7
5
6
4
Problem 0.2 We are given a weighted (non-negative value on the arcs) digraph D = (V, A)
Stable Matching and Interval Scheduling
Arash Raey
May 7, 2014
Arash Raey
Stable Matching and Interval Scheduling
Stable Matching Problem
We have a set M = cfw_m1 , m2 , . . . , mn of men and a set
W = cfw_w1 , w2 , . . . , wn of women.
A matching S is
Analysing Algorithms
Arash Raey
May 9, 2014
Arash Raey
Analysing Algorithms
Usually interested in running time (but sometimes also memory
requirements).
Example: One of the simplest sorting algorithms
Input : n numbers in array A[1], . . . , A[n]
1. for (
CMPT 307, Assignment 2
Deadline Monday June 30th (5:00 pm)
Problem 0.1 Write a pseudo code for nding a longest weighted path between two given
nodes u, v in an acyclic digraph D.
Problem 0.2 Modify the shortest path algorithm to nd the number of shortest
Course Information and Introduction
Arash Raey
May 5, 2014
Arash Raey
Course Information and Introduction
Course Information CMPT 307
1
Instructor : Arash Raey
Email : arashr@sfu.ca
Oce : TACS1 9215
Oce Hours : Monday and Wednesday 10:30 am to 11:30 am
2
Graph Search, BFS,DFS,Topological ordering
May 14, 2014
Graph Search, BFS,DFS,Topological ordering
BFS Algorithm
BFS (s)
1. Set Discover[s]=true and Discover[v]=false for all other v
2. Set L[0] = cfw_s
3. Set layer counter i=0
4. Set T =
4. While L[i] i
Minimum Spanning Trees
May 23, 2014
Minimum Spanning Trees
Minimum spanning trees (MST)
One of the most famous greedy algorithms
Given undirected graph G = (V , E ), connected
Weight function w : E R
Spanning tree: tree that connects all nodes, hence n =
Heap, HeapSort and Priority Queue
May 28, 2014
Heap, HeapSort and Priority Queue
Heap
A heap (data structure) is a linear array that stores a nearly
complete tree.
Only talking about binary heaps that store binary trees.
nearly complete trees:
all levels