Algorithms
What is an algorithm?
An algorithm is any well-defined computational
procedure that takes some value, or set of values, as
input and produces some value, or set of values, as
output. An al
Outline
1
HC is N PC
2
Subset-Sum is N PC
c
Xin
He (University at Buffalo)
CSE 431/531 Algorithm Analysis and Design
1 / 27
HC is N PC
HC is N PC
We have shown HC is in N P.
We show HC is N P-hard by
Outline
c
Xin
He (University at Buffalo)
CSE 431/531 Algorithm Analysis and Design
1/1
Approximation Algorithms
We have a N PC problem Q.
c
Xin
He (University at Buffalo)
CSE 431/531 Algorithm Analysi
Midterm I, XXX XXXX
Solution
Version A
CS431
CS531
(Please circle one)
NAME:
0
Name
1. (6 points) List the following functions according to increasing order of growth rate. Relate
them by using , or o
(a) T(n) is of the form T(n) = aT(n/b) + n) where a = 4, b = 3 and n) = n. Since
logba : log34 2 1 + 0.25, we have n) : 0(n1'333L 0'25). So T(n) : 1.3334 by
Masters Theorem.
(b) By denition of T(n), w
Name
5: (5 points] Subset Sum Problem
Let A = cfw_31, . . . , an be a set of positive integers. Let K be another positive integer:
We want to decide if theres a subset S Q A such that the sum of the i
Master theorem
Let a 1 and b > 1 be constants, let f(n) be a
function, and let T(n) be defined on the nonnegative integers by the recurrence
T(n) = aT(n/b) + f(n)
where we interpret n/b to mean either
(g(n) = cfw_ f(n): there exists positive constants
c1, c2, n0 such that 0 c1g(n) f(n) c2g(n)
for all n n0
O(g(n) = cfw_ f(n): there exists positive constants
c, n0 such that 0 f(n) cg(n) for all n n0
The Sorting Problem
Formal definition:
Input: A sequence of numbers
a1 , a2 , , an
Output: A permutation (reordering) a1, a2 , an
permutation (reordering)
of the input sequence such that a1 a2 an
INSE
(a) T(n) is of the form T(n) = aT(n/b) + n) where a = 4, b = 3 and n) = n. Since
logo 2 log34 2 1 + 0.25, we have n) = 0(n1'3334 0'25). So T(n) = nlg34 by
Masters Theorem.
(b) By denition of T(n), we