4. G REEDY A LGORITHMS II
Dijkstra's algorithm
minimum spanning trees
Prim, Kruskal, Boruvka
single-link clustering
min-cost arborescences
SECTION 6.1
Cycles and cuts
Def. A path is a sequence of edges which connects a sequence of nodes.
Def. A cycle
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #5, due Friday, August 1th , 2014 at 18:00
[12] 1. Given a set of n numbers, we wish to find the i largest in sorted order using a comparisonbased algorithm. We consider these three strategie
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #4, due Thursday, July 24th , 2014 at 18:00
[18] 1. Binary search of a sorted array takes logarithmic search time, but the time to insert
a new element is linear in the size of the array, sin
Page 1 of 6
CPSC 320 Midterm 1
Wednesday, February 3, 2016
1. [11 points] (Unequal Stable Matching Problem) Consider the stable matching problem with more men than
women: n > n0 , where n is the number of men and n0 is the number of women. In this problem
Page 1 of 7
CPSC 320 Final Examination
Friday, April 22, 2016
1. [20 points] Short Answers
(a) [4 points]
Solution: Yes, it is. It suffices for every man to have a different first choice, and for each mans first
choice to be a woman who ranks him last. Fo
Page 1 of 5
CPSC 320 Midterm 2
Monday, March 14, 2016
1. [20 points] [Chen] Short answers.
(a) [6 points] Write a pseudocode of an algorithm that takes the array P returned by the Dijkstra algorithm,
source node s and a node v as input and returns a short
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #9
1. (Divide&Conquer) Consider the problem of taking a sorted array A containing distinct (and not necessarily positive) integers, and determining whethe
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #13
1. (Dynamic Programming) As some of you know well, and others of you may be interested to learn,
a number of languages (including Chinese and Janapese
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #2
1. (Coop Student/Company Matching Problem) The Stable Matching Problem we discussed in class
was a simplified version of the more general Coop Student/
UBC, CPSC 320: Intermediate Algorithm Design and Analysis Winter 2 2015/2016
Solutions to Tutorial #10
1. (Multi-Selection Problem) Suppose that we are given an unsorted array A with n elements, and another
sorted array P with k distinct elements chosen f
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #3
1. (Asymptotic order) Rank the following functions by order of growth. That is, order them so that f1
O(f2 ), f2 O(f3 ), etc. Make sure to indicate wh
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #2, due Friday, January 11st , 2014 at 18:00
[6] 1. King Yemechan was angry because the solutions proposed to help him determine
which wine bottle was poisoned all used too many taste testers
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #3, due Thursday, July 17th , 2014 at 18:00
[15] 1. One aspect of Huffmans algorithm that we did not discuss in class is whether or not the
code it produces is significantly shorter than the
Introduction to Algorithms
Massachusetts Institute of Technology
Professors Erik Demaine and Sha Goldwasser
March 18, 2004
6.046J/18.410J
Handout 14
Lecture Notes on Skip Lists
Lecture 12 March 18, 2004
Erik Demaine
Balanced tree structures we know at thi
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #6, due Friday, August 8th , 2014 at 18:00
[30] 1. Tim and Jim are twin brothers who just had their joint birthday party. Among the presents
that they received, they got n gift cards. They wa
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #2, due Friday, July 11st , 2014 at 18:00
[6] 1. King Yemechan was angry because the solutions proposed to help him determine
which wine bottle was poisoned all used too many taste testers. D
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #5, due Friday, August 1th , 2014 at 18:00
[12] 1. Given a set of n numbers, we wish to find the i largest in sorted order using a comparisonbased algorithm. We consider these three strategie
CPSC 320 Another Sample Midterm 1
October 2014
[12] 1. Short Answers
[3] a. Why is it useful to know that the furthest-in-the-future cache maintenance algorithm
is optimal, even though it can not be implemented in practice?
Solution : It is because we can
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #1, due Monday July 7th, 2014 at 18:00
[8] 1. As stated in class and proved in the textbook, the stable matching algorithm of Gale and
Shapley gives the best possible results for the side tha
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #1, due Monday July 7th, 2014 at 18:00
[8] 1. As stated in class and proved in the textbook, the stable matching algorithm of Gale and
Shapley gives the best possible results for the side tha
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #3, due Thursday, July 17th , 2014 at 18:00
[15] 1. One aspect of Huffmans algorithm that we did not discuss in class is whether or not the
code it produces is significantly shorter than the
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #6, due Friday, August 8th , 2014 at 18:00
[30] 1. Tim and Jim are twin brothers who just had their joint birthday party. Among the presents
that they received, they got n gift cards. They wa
CPSC 320: Intermediate Algorithm Design and Analysis
Assignment #4, due Thursday, July 24th , 2014 at 18:00
[18] 1. Binary search of a sorted array takes logarithmic search time, but the time to insert
a new element is linear in the size of the array, sin
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #1
January 58, 2016
1. (Proof by contradiction) Show that
Use a proof by contradiction.
2 is irrational, i.e., there are no integers p and q such that
2 =
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #4
1. In the Exhibition Guarding Problem, we are given a line L that represents a long hallway in a show room.
We are also given an ordered set X = cfw_x1
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #6
1. (Cycle Property without the assumption that edge cost are distinct) Consider an undirected graph
G = (V, E) and c : E R+ the cost function. Let C be
Linear-time Sorting
Greedy Algorithms
Bucket Sort
Interval Scheduling
July 08, 2016
Geoffrey Tien
1
Bucket Sort
Counting Sort and Radix Sort achieve significant speed up
against comparison algorithms because they use certain
assumptions about the input v
Amortized Analysis
Union-Find data structure
(Kruskal's Algorithm
implementation)
Recurrence relations
July 13, 2016
Geoffrey Tien
1
Amortized Analysis
Suppose we are dealing with an algorithm or data structure where:
Most operations are fast, i.e. "che
Dynamic Programming
Weighted interval scheduling
Knapsack
July 22, 2016
Geoffrey Tien
1
Algorithmic Paradigms
Greed
Build a solution incrementally, choosing short-term optimization on
some local criterion
Divide and conquer
Break up a problem into one
Divide and Conquer
Integer Multiplication
July 18, 2016
Geoffrey Tien
1
Integer Multiplication
Back to grade school!
Multiplication of two -digit numbers
Produce partial products by multiplying by a single digit
Add all partial products
Same rules for
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #7
1. (Forming Recurrence) Give a recurrence relation for the running time of the following algorithm as a
function of n = last f irst + 1. To simplify yo
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #8
1. (Master Theorem) Suppose that f (n) is n when n is even, and n2 when n is odd. Let T (n) be defined by
T (n) = T (bn/2c) + f (n) if n 2, with T (1)
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #5
1. (Greedy algorithm) Alice wants to throw a party and is deciding whom to call. She has n people to
choose from, and she has made up a list of which p
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #11
1. (Amortized Analysis) It is possible to implement a queue using a pair of stacks as follows:
Enqueue(x) pushes x on stack1.
Dequeue() first checks
UBC, CPSC 320: Intermediate Algorithm Design and Analysis (Winter 2 2015/2016)
Solutions to Tutorial #12
1. (Amortized Analysis) Consider an ordinary binary min-heap structure with n elements that supports
the operations INSERT and DELETE-MIN in O(log n)