CMPT 307
Solutions to Midterm #1
October 14, 2008
NO AIDS ALLOWED. Answer ALL questions on test paper. Use backs of sheets for scratch work. Total Marks: 55 ADVICE: Do this page fast! [5] 1. True or False? All logarithms are base 2. NO JUSTIFICATION IS NE
CMPT-454 Fall 2009 Instructor: Martin Ester TA: Yi Liu Solution Assignment 1
Total marks: Due date:
200 (20 % of the assignments) September 30, 2009
Problem 1.1 (50 marks) Consider a disk with a sector size of 512 bytes, 1,000 tracks per surface, 100 sect
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
Dynamic Programming( Weighted Interval
Scheduling)
June 11, 2014
Dynamic Programming( Weighted Interval Scheduling)
Problem Statement:
1
2
3
We have a resource and many people request to use the
resource for periods of time (an interval of time)
Each inte
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
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
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
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
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
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
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
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
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)
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
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)
Dynamic Programming
June 6, 2014
Dynamic Programming
Dynamic Programming
1
Dynamic programming algorithms are used for optimization
(for example, nding the shortest path between two points, or
the fastest way to multiply many matrices).
Dynamic Programmin
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
Interval Scheduling
May 30, 2014
Interval Scheduling
Interval Scheduling Problem
Problem Statement: We have a resource and many people
request to use the resource for periods of time.
Conditions:
the resource can be used by at most one person at a time.
CMPT-454 Fall 2009 Instructor: Martin Ester TA: Yi Liu Solution Assignment 2
Total marks: Due date:
200 (20 % of the assignments) October 14, 2009
Problem 2.1 (50 marks) Consider B-trees of order n = 2, i.e. each node of the B-tree contains one or two sea
CMPT-454 Spring 2009 Instructor: Martin Ester TA: Bahareh Bina Sample Exam
Problem 1 Given two relations R(a,b,c) and S(a,b,d) with the following statistics: T(R) = 1000, V(R,a) = 1000, V(R,b) = 50, V(R,c) = 20 T(S) = 2000, V(S,a) = 50, V(S,b) = 100, V(S,
CMPT-454 Spring 2009 Instructor: Martin Ester TA: Bahareh Bina Solution Assignment 10 Total marks: Due date: 100 (10 % of the assignments) April 6, 2009
Problem 10.1 (40 marks) Consider the following schedules of transactions T1, T2 and T3. Insert shared
CMPT 307 - Data Structures and Algorithms: Solutions to PS 1
September 25, 2008
1. Asymptotics Rank the following functions by order of growth; that is, arrange the following 14 functions g1 , . . . , g14 so that g1 = O(g2 ), g2 = O(g3 ), . . . , g13 = O(
CMPT 307 - Data Structures and Algorithms: Solutions to Problem Set 2
October 9, 2008
1. Topological ordering. Let G = (V, E ) be a directed acyclic graph (DAG). A topological ordering of G is a sequence of its vertices v1 , v2 , . . . , vn so that for ev
CMPT 307 - Data Structures and Algorithms: Solutions to Problem Set 3
November 5, 2008
1. Making change Youre given an unlimited supply of coins of denominations d1 , d2 , . . . , dk (where each di is a positive integer), and a positive integer number n (
CMPT 307 - Data Structures and Algorithms: Solutions to Problem Set 4
1. Forming committees In a certain department, there are n faculty members. The department needs to organize m dierent committees (such as undergraduate admission committee, etc). Each
CMPT 307
Solutions to Midterm #2
November 13, 2008
[3] 1. True or False? (Below, Pr[X ] stands for the probability of an event X .) (a) For any random events A and B , Pr[A & B ] = Pr[A] Pr[B | A]. (b) For any random events A1 , A2 , . . . , An , Pr[A1 A2
CMPT-454 Fall 2009 Instructor: Martin Ester TA: Yi Liu Solution Assignment 3
Total marks: Due date:
200 (20 % of the assignments) October 28, 2009
Problem 3.1 (30 marks) Consider the following simplified grammar for SQL queries. <Query>:=SELECT <SelList>
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