CMPT 307 - Data Structures and Algorithms:
Solutions to Problem Set 4
1. Network flows Suppose youre in charge of the Mars mission. There are possible
experiments E1 , . . . , Em to perform on Mars. Each experiment Ej brings the profit of
pj dollars (inte

2) Solution by Anni Cao
Each instance of 3-coloring problem can be modeled as an instance of 3-SAT. Assume
there are three colors Red, Green and Blue. For each vertex v in the graph, we can build
a 3-SAT formula: (VR VG VB) (VR VG) (VR VB) (VB VG). The
fi

CMPT 307 Midterm
Problem 0.2 We are given a weighted (non-negative value on the arcs) digraph D
with n nodes. Girth of D is the weight of a smallest weight cycle.
1. Design an algorithm to nd the girth of D and show the running time of your
algorithm.
2.

CMPT 307 - Data Structures and Algorithms:
Problem Set 1
January 17, 2013
Reminder: The homework assignment will not be collected and graded. However, the
quiz given in class will be based on the material covered in the homework. If you solve the
homework

Geoﬂi'ey Herr CMPT Bil? —Assignmenr l — Partial Salmon l
1)
2]
3}
Stable Matehings, Heaps
Due: in-elass Tuesday, September 22, 2015
a]
The rtmning time of (3-3 is proportional to the number of proposals made. If every man has the
same preference list, it

CMPT 307, Quiz 1 Solution
Problem 0.1 Dijkstra vs. Prim. As you may have noticed, Dijkstras and Prims algorithms are very similar. In this question, you will explore their similarities and dierences.
(a) Show that running Dijkstras algorithm on an undire

CMPT 307, Midterm
July 4, 2014 (9:30 am to 10:30 am)
Solve problems (1 or 2), 3,4, (5 or 6).
Problem 0.1 We are given a weighted graph G (each edge has a non-negative weight). A
node v in G is called a center node if the maximum shortest distance (weight

Number 2 )
Algorithm Girth(D=(V,E), c: E -> Q ) / c is the cost function
1) Run all-pairs-shortest-path (D,c)
2) For every pair of nodes u,v let d(u,v) be the length of a
shortest path from u to v according to all-pairs-shortest-path.
3) for every arc uv

Basic SQL Queries
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke
1
Introduction
Introduce SQL, the standard query
language for relational DBS.
An SQL query takes one or more input
tables and returns one output table.
Well start with the

Relational Algebra
1
Relational Query Languages
Query languages: Allow manipulation and
retrieval of data from a database.
Relational model supports simple, powerful
QLs:
Strong formal foundation based on algebra/logic.
Allows for much optimization.
2
Fo

Specificailv, each interval beginning in week i will have a weight n-zjfﬂsJ —4*c. Discard any
intervals with negative weight [i.e. intervals where it costs more to use company B}.
Solve using the weighted interval scheduling algorithm shown in lecture sli

CM?!" 3!}? Assignment 4 — Partial solution 3
introduce an artiﬁcial source vertex s and connect s to each of the to starting points
introduce an artiﬁciai sink vertex t and connect it to each of the 411 — 4 boundar},r points
each undirected edge between p

CWT 3t}? Assigt‘tttt‘crrf 3 — Farah! solution 2
Because exactly one of the factors If} — i] and U + i + 1] is even, 2”“ must divide one of the
factors. It cannot be [j—t'), since U—i)«=:m {23144. It cannot be U+i+1}, sincej+i +
1 a: (in — 1} + [in — 2) +

CMPT 307 Data Structure and Algorithms
Assignment #1
1|Page
Problem 1
Rank the following functions by the order of growth:
You need to arrange them into such that
The result is . Since the exponential functions grows faster than the polynomial
functions,

CMPT 307, Assignment 1
Wentao Huang 301187804
Problem 0.1: Rank the following functions by the order of growth
,
,
, n log n,
,
,
You need to arrange them into
;
;
;
;
;
;
such that
(n) = O(
(n), 1 i 7.
Solution 0.1:
=
;
=
;
=
;
= n log n;
(
Problem 0.2:

Some Notes !
July 30, 2014
Some Notes !
Dominating set problem is NP-complete
We are give a graph G = (V , E ) and an integer k. Decide whether
there exists a set S V such that :
1
2
|S| k
every vertex in V S has a neighbor in S.
S is a dominating set .
S

CMPT 307, Quiz 1 (9:30 am - 10:30 am)
Problem 0.1 Dijkstra vs. Prim. As you may have noticed, Dijkstras and Prims algorithms are very similar. In this question, you will explore their similarities and dierences.
(a) Show that running Dijkstras algorithm

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

Kruskals Algorithm: Correctness Analysis
Valentine Kabanets
February 1, 2011
1
Minimum Spanning Trees: Kruskals algorithm
A spanning tree of a connected graph G = (V, E) is a subset T E of the edges such that
(V, T ) is a tree. (In other words, the edges

CMPT 307
[3]
Solutions to Quiz 4
Dec 1, 2011
1. (a) For a given flow network G with flow f , draw the residual network Gf and show
the residual capacities of all edges in Gf . (In the graph below, the edge label a/b
means there is a flow of value a along

CMPT 307
Solutions to Quiz 2
Oct 20, 2011
1. For each of the algorithms below, give the name of a data structure that we used to
achieve an efficient implementation of the algorithm. No justification is necessary.
[2]
(a) Dijkstras algorithm: Solution: pr

Dynamic Programming Notes
Fall 2011
Dynamic Programming Algorithms
The setting is as follows. We wish to find a solution to a given problem which optimizes
some quantity Q of interest; for example, we might wish to maximize profit or minimize
cost. The al

CMPT 307 - Data Structures and Algorithms:
Solutions to Problem Set 2
October 15, 2011
1. Unique MST. Prove that if an undirected connected graph G = (V, E) has distinct
weights c(e) 0 on its edges e E, then it has exactly one Minimum Spanning Tree.
For y

CMPT 307 - Data Structures and Algorithms:
Problem Set 1
Due: September 27
September 8, 2011
Reminder: The homework assignment will not be collected and graded. However, the
quiz given in class will be based on the material covered in the homework. If you

CMPT 307 - Data Structures and Algorithms:
Solutions to Problem Set 1
September 29, 2011
1. Asymptotics; [KT, # 4, p. 67] Rank the following functions by order of growth;
that is, arrange the following 7 functions
g1 , . . . , g6 so that g1 = O(g2 ), g2 =