CMPT 307
[4]
Solutions to Quiz #1
October 4 , 2011
1. Suppose the runtime of an algorithm is T (n). Circle the expressions for T (n) below
which would make the algorithm polynomial-time (that is, which T (n) are in O(nc ) for
some constant c). All logarit

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 Structures and Algorithms:
Solutions to Problem Set 3
November 4, 2011
1. Recurrences Give asymptotic upper and lower bounds for T (n) in each of the following recurrences. Assume that T (n) is constant for n 2. Make your bounds as tight
a

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

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

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

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 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:
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 =

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

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

CMPT 307
[10]
Solutions to Quiz #3
November 10, 2011
1. Recurrences Give the asymptotically tight upper bounds for T (n) in each of the
following cases. Assume T (n) is constant for n 2. No justification is necessary.
(a) T (n) = T (n/2) + n. Solution: T

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

Lecture 12
Thursday, June 15, 2017
7:51 PM
Longest Common Subsequnce
Given: Two sequences x = x1 x2 xn and y = y1 y2 ym, over some alphabet A
Find: Longest common subsequence z = z1 zk of x and y.
Example: x = TGACTA
y = GTGCATG
LCS z = TGCA, or TGAT, or

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

Lecture 11
Monday, June 12, 2017
11:10 PM
All-Pairs Shortest Paths
Given: Digraph G=(V,E), where V=cfw_1,2,n,
possibly negative costs c(i,j), BUT no negative cycles!
( c(i,j) = infinity means no edge (i,j) in G )
Compute: D(i,j) = cost of cheapest path fr

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

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
[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 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, 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

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

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