COT5405 exam 2 solution
1.
a)
TRUE
b)
FALSE
Consider the following input: I = [2, 1, 1] and L = 3,
GREEDY(I) =
21
k=0
1
k=2
max(k) = 2
OPT(I) =
2
k=1
11
k=1
max(k) = 1
c)
FALSE
This algorithm does not correctly solve the problem. Consider the following in
COT5405: ANALYSIS OF ALGORITHMS
Exam I
Date: Sept 30, 2015, Thursday
Time: 8:20 pm - 10:10 pm (110 minutes)
or (Oce CSE 534)
Professor: Alper Ung
This is a closed book exam. No collaborations are allowed. Your solutions should be concise,
but complete, a
1. [30 points] TRUE/FALSE. No need for justication.
(a)
(b)
(C)
1"
/FALsn .
L G = [ME] be a flow network with source 5 E V and sink 1; E V, and non-negative
egge capacities. If the maximum ow assignment for G is unique then the minimum
cut for this netw
3. [15 points = 8 + 7] AMORTIZED ANALYSIS L1!
Recall the amortized analysis of a sequence of'n insertions into a dynamic tables whose
capacity is doubled every time it becomes full. We used three different techniques in class to
show that the amortized co
2. [10 points : 5+ 51 SUPPORTING YOUR CLAIM
Pick any TWO of the statements in Question 1'(a)-(i) that you decided to be FALSE. Give
a complete proof of your decision.
l l
1(5) W 09491;, k too, a We!
"w; W 1: outed 1125 096mm Pw 7
- P . 6M EY KT , '
TM: YC
Solutions
January 27, 2016
Question1:
T (n) = n2 (1 + 5/16 + (5/16)2 + (5/16)3 + + (5/16)n1 )
= (n2 )
T (n) = 2i T (
n
n
n
n
) + n lg n + n lg + n lg . . . n lg i1 = n T (1) + n
2i
2
4
2
lg n1
lg
i=0
lg n1
=n
(lg n i)
i=0
lg n1
= n lg n lg n
i
i=0
= (n
Leftist Trees
Linked binary tree.
Can do everything a heap can do and in the
same asymptotic complexity.
insert
remove min (or max)
initialize
Can meld two leftist tree priority queues in
O(log n) time.
Extended Binary Trees
Start with any binary tree
Chapter 3
With Question/Answer Animations
Chapter Summary
Algorithms
Example Algorithms
Algorithmic Paradigms
Growth of Functions
Big-O and other Notation
Complexity of Algorithms
Section 3.1
Section Summary
Properties of Algorithms
Algorithms for
Solutions
February 15, 2016
Question1:
1.
T (n) =
lg n
X
n
i=0
= (n lg n)
T (n) =
lg n
X
(3/4)i n
i=0
= (n)
2. TRUE, TRUE, FALSE.
3. The recurrence relation is T (n) = 2 T (n/2) + O(n). The worst-case
running time is O(n log n).
4. (a) The best case for b
COT5405 Homework 2 -spring 2016
Assigned: 02/16, Tue
Due: 02/23, Tue
There are five questions for homework 2. Here are the first two questions, and remaining three
will be posted on 02/17 morning.
1. Oxen pairing
Consider the following problem: We have n
(s)
(h)
(j)
T /FALsn
(ions or a directed graph G = (V, E) and a source node 3 E V and a weight function
w : E > R. Suppose there exists some edges [5,11] 6 E sourced at s such that their
weight is negative, i.e., w[s,u < 0. Then, Dijkstras algorithm com
(e) Find a minimum cfw_31,52,537cfw_t1,t2 cut in this network. What is the capacity of this
minimum out?
(f) Starting with a zero flow consider a sequence of three augmentations: (i) < s, s , o, d,t2,t >-
with ow 7, (ii) < S,sz,o,c,t1,t > with ow 6, and (
1. [20 points : 4+4+4+4+41Tnoanarse QUESTIONS (no user: nos JUSTIFICATION)
(a) TRUE/FALSE
Bellman-Ford algorithm presented in class for computing shorthest paths is a dynamic
programming algorithm.
Fads-Q,
(b) TRUE/FALSE
Dijkstras algorithm determines whe
l.(20 points)You are given a family ofS ofm sets S,- , 1g 1' g m. Denote by lAl the size of
set A. Let l Si| =1, i.e., SJ :cfw_Sl=52="'=sj.' Asubset T:cfw_T1,T2,-~,Tk ofSis afamily of
sets such thatfor each 1', lgigk, T; :S, for some r, 13 rg m . Tis a co
Lifi
COWUBOW.
(46) .' Q N ' / ber!
. ~ ' am mgr-Mal "mm .
A each Maid m G 0"; 6
4. [20:10+10 points] MINIMUM SPANNING TREES / SHORTEST PATHS
Given two graphs G and G that have the same sets of vertices V and edges E, however
different weight functio
COT5405 Analysis of Algorithms
Summer 2003
Midterm 3 (07/28/03)
This is closed notes/book inclass exam. Electronic calculators are allowed.
You are expected to derive the best possible algorithm to solve the problems. Poor
performance solutions (even if t
COT 5405 Midterm 2 Solutions
April 1, 2009
1 Problem 4 Graded by Hale
GEOMETRIC DATA STRUCTURES AND ALGORITHMS [30 : 7+ 8+ 7+8 Points]
You may assume that no three points are colinear in the following prob-
lem.
(a) Given a convex polygon P with k points
. [30 points : 4 + 4 + 6 + 4 + 4 + 8] FLOW NETWORK WITH MULTIPLE SOURCES/5mm
Consider a variant of the Flow Network problem where we have multiple sources and multiple
sinks. Figure shows a ow network with three sources 51,52 and 53 and two sinks t1 and t
5. [15 points] UNIQUENESS OF SHORTES'I PATHS
a.
Shortest: paths in a graph are not always unique: sometimes there are two or more dierent
paths with the same minimum possible length. ' Given an undirected graph G : cfw_V,E], a
source node 3 e V, and a
3. [20 points = 10 + 10] AMORTIZBD ANALYSIS
Recall the amortized analysis of a sequence of n. insertions into a dynamic tables whose
capacity is doubled every time it becomes full. We used three dierent techniques in class to
show that the amortized cost
Homework 2 solutions
1. Candidate Greedy Strategy I: Take the weakest two oxen, if together they meet the strength
requirement, make them a team. Recursively find the most teams among the remaining
oxen. Otherwise, delete the weakest ox. Recursively find
4.8
Huffman Codes
These lecture slides are supplied by Mathijs de Weerd
Data Compression
Q. Given a text that uses 32 symbols (26 different letters,
space, and some punctuation characters), how can we encode
this text in bits?
Q. Some symbols (e, t, a, o,
COT5405 Homework 2 - spring 2016
Assigned: 02/16, Tue
Due: 02/23, Tue
There are five questions for homework 2.
1. Oxen Pairing
Consider the following problem: We have n oxen, OX1, , OXn, each with a strength
rating Si. We need to pair the oxen up into tea