Shortest Paths
Input: weighted, directed graph G = (V, E), with weight function w :
E R.
The weight of path p =< v0, v1, . . . , vk > is the sum of the weights of its
constituent edges:
w(p) =
k
i=1
CS4231: Analysis of Algorithms, I
Midterm Exam Solutions, Thursday October 27, 2016
Problem 1 [18 points, 6 points per part] (Graded by Srikar)
Give asymptotic solutions T(n) =(f(n) for the following
Midterm Exam Guidelines
The midterm exam will be held on Thursday October 27, at 11:40-12:55.
Students in Section 001 will take the exam in the usual classroom, Pupin 428.
Students in Section H01 will
Randomization
CS 4231, Fall 2016
Mihalis Yannakakis
1
Randomized algorithms
Make random choices (coin flips, random numbers .)
Different random choices are assumed independent
Outcome of algorithm
Selection
CS 4231, Fall 2016
Mihalis Yannakakis
1
Selection (Order Statistics)
Input: Set A of n numbers (or more
generally, elements from an ordered
domain), number i, 1in
Output: i-th smallest (ra
CS4231: Analysis of Algorithms, I
Midterm Solutions, Tuesday October 27, 2015
Problem 1 [18 points, 6 points per part]
Give asymptotic solutions T(n) =(f(n) for the following recurrences. Assume that
CSOR W4231-2: Midterm Practice Problems
Fall 2016
These problems are ungraded, and are intended as a study aid. Solutions will also be posted
on canvas. They are very similar to the problems that will
Depth First Search
Acyclicity
Graph Components
CS 4231, Fall 2015
Mihalis Yannakakis
1
Depth-First Search from a source s
R
s
N-R
u
v
Policy: Choose edge (u,v) from R (reached nodes) to N-R
(unreache
Dynamic Programming
CS 4231, Fall 2016
Mihalis Yannakakis
1
Dynamic Programming
General method that applies to a class of problems, often
a class of optimization problems (but not only
optimization)
P
Counting Sort, Radix Sort,
Bucket Sort
CS 4231, Fall 2016
Mihalis Yannakakis
1
Counting Sort
Restricted domain: D=cfw_1,k
Idea: Count how many input elements for each i in D
Example: Input A = [ 1,
CSOR W4231-2: Midterm Practice Problems
Fall 2016
These problems are ungraded, and are intended as a study aid. Solutions will also be posted
on canvas. They are very similar to the problems that will
How do you model the future?
Stochastic
approach: The future can be
modeled as a distribution over possible
events.
Very successful in many contexts.
Alternative:
Think of the future as an
adversar
NP-Completeness
Goal: We want some way to classify problems that are hard to solve, i.e.
problems for which we can not nd polynomial time algorithms.
For many interesting problems
we cannot nd a poly
Graphs
Graph G = (V, E) has vertices (nodes) V and edges (arcs) E.
Graph can be directed or undirected
Graph can represent any situation with objects and pairwise relationships.
1
2
3
4
Representat
Randomized Selection
Same start as for deterministic selection
Select(A,i,n)
1
2
if (n = 1)
then return A[1]
3
4
5
p = median(A)
6
L = cfw_x A : x p
H = cfw_x A : x > p
7
8
9
if i |L|
then Select(L, i
Human Codes
Coding is the problem of representing data in another representation.
Typically, we want that representation to be concise. We will encode in
binary in this lecture. We call the encoding o
Randomization in Algorithms
Randomization is a tool for designing good algorithms.
Two kinds of algorithms
Las Vegas - always correct, running time is random.
Monte Carlo - may return incorrect an
Dynamic Programming
Wed like to have generic algorithmic paradigms for solving problems Example: Divide and conquer
Break problem into independent subproblems Recursively solve subproblems (subproble