CS 4102 Exam 1 Fall 2012
Name: _KEY_ Computing ID: _
Honor Pledge: On my honor as a student, I have neither given nor received aid on this exam.
(You must sign here or your grade wont count.)
_
1. This pledged exam is closed book, closed notes, except for
CS432, Algorithms Name: Assessment Self-Quiz for Feb. 23, 2010
Answer the questions below before the end of class and turn it in. The results you give will not count toward your grade in the class. The purpose of this test is for me to get a feel for how
Chapter 5
Greedy algorithms
A game like chess can be won only by thinking ahead: a player who is focused entirely on immediate advantage is easy to defeat. But in many other games, such as Scrabble, it is possible to do quite well by simply making whichev
CS 4102: Algorithms
Page 1 of 3
Spring 2014
Solutions to proofs from class
1. Coin Change Problem: Show that the greedy algorithm for making change always returns
the optimal solution.
See slides
2. Knapsack Problem: Show that the greedy algorithm for the
Proof methods and greedy algorithms
Magnus Lie Hetland
Lecture notes, May 5th 2008
1
Introduction
This lecture in some ways covers two separate topics: (1) how to prove algorithms correct, in general, using induction; and (2) how to prove greedy
algorithm
Introduction to Algorithms CS 482 Spring 2006
Outline for Greedy Algorithms Exchange Arguments
Greedy algorithms generally take the following form. Select a candidate greedily according to some heuristic, and add it to your current solution if doing so do
Greedy Algorithms
1. Some optimization question.
2. At each step, use a greedy heuristic.
3. Chapter 7 of the book
Coin Changing Problem
1. Some coin denominations say, 1, 5, 10, 20, 50
2. Want to make change for amount S using smallest number of
coins.
E
Chapter 4
Paths in graphs
4.1 Distances
Depth-rst search readily identies all the vertices of a graph that can be reached from a designated starting point. It also nds explicit paths to these vertices, summarized in its search tree (Figure 4.1). However,
Greedy algorithm
Prims algorithm for constructing a Minimal
Spanning Tree is a greedy algorithm: it just
adds the shortest edge without worrying
about the overall structure, without looking
ahead. It makes a locally optimal choice at
each step.
Greedy Al
Chapter 24: Single-Source Shortest Paths
The shortest path the path with the
smallest edge-weight sum
2
4b
a
3
c
2
-2
d
3
2
-1
e
1
1
2
f
6
What is the length of the
path a, b, d, c, f ?
1
The Shortest Path Problem (SPP)
def
(u, v ) = the shortest path le
Lecture 14: Greedy Algorithms
CLRS section 16
Outline of this Lecture
We have already seen two general problem-solving
techniques: divide-and-conquer and
dynamic-programming . In this section we introduce a
third basic technique: the greedy paradigm .
A g
Divide and Conquer Algorithms
CS 4102: Algorithms
Spring 2015
Mark Floryan
1
Recurrences and Divide & Conquer
First design strategy: Divide and Conquer
Examples
Recursive algorithms
Counting basic operations in recursive algorithms
Solving recurrence rela
Sorting
CS 4102: Algorithms
Fall 2016
Mark Floryan
1
Reminder: Common Forms of Recurrence
Equations
Remember these?
Divide and conquer: Like Mergesort
T(n) = a*T(n/b) + f(n)
Chip and conquer:
T(n) = T(n-c) + f(n)
Note: One sub-problem of lesser cost!
Inse
Dynamic Programming
CS 4102
Fall 2016
Mark Floryan
1
Introduction
2
Dynamic programming
Old bad name (see Wikipedia or textbook)
It is used, when the solution can be recursively described
in terms of solutions to sub-problems (optimal
substructure)
Algori
CS 4102: Algorithms
Page 1 of 2
Solutions to proofs from class
1. Directly Solve: T (n) = 2T ( n2 ) + n.
We first unroll the recurrence a couple of times until we see a pattern. Lets do this twice:
n
T (n) = 2T ( ) + n
2
n n
= 2[2T ( + ] + n
4
2
n
= 4T (
CS 4102: Algorithms
Page 1 of 5
Spring 2014
Solutions to proofs from class
1. Coin Change Problem: Show that the greedy algorithm for making change always returns
the optimal solution.
Let O(i) be the set of coins optimal for change amount i and G(i) be t
L19
4102
abhi shelat
10.31.2013
Shortest paths,
negative weights
All pairs
what about negative edge weights?
here does old argument break down
w(p)
du + (y, u)
first ideas:
sssp(G,s)
shorti,v =
sssp(G,s)
shorti,v
8
>1
>
<
0
=
>
> minx2V
:
i=0
v=s
shorti
s
L18
4102
abhi shelat
10.29.2013
Shortest paths,
negative weights
implementation
use a priority queue to keep track of light edges
priority queue
bonacci heap
O(log n)
log n
n
n
extractmin:
O(log n )
log n
amortized
decreasekey:
O(log n )
O(1)
amortized
in
L17
4102
abhi shelat
10.24.2013
Min Span Trees,
Shortest paths
MST
minimum spanning tree
looking for a set of edges that T
(a) connects all vertices
(b) has the least cost
min
w(u, v )
(u,v ) T
E
example of a cut
b
8
d
g
7
10
a
8
3
c
5
e
9
12
2
9
11
3
1
i
CS161
Summer 2013
Handout 12
July 29, 2013
Guide to Greedy Algorithms
Based on a handout by Tim Roughgarden, Alexa Sharp, and Tom Wexler
Greedy algorithms can be some of the simplest algorithms to implement, but they're often among
the hardest algorithms