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
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
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
Chapter 16: Greedy Algorithms Greedy is a strategy that works well on optimization problems with the following characteristics: 1. Greedy-choice property: A global optimum can be arrived at by selecting a local optimum. 2. Optimal substructure: An optimal
Merge Sort
1/15/2008 5:58 PM
Divide-and-Conquer
Divide-and conquer is a
general algorithm design
paradigm:
Merge Sort
Divide: divide the input data
S in two disjoint subsets S1
and S2
Recur: solve the
subproblems associated
with S1 and S2
Conquer: combine
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
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
DEPARTMENT OF COMPUTER SCIENCE
SCHOOL OF ENGINEERING AND APPLIED SCIENCE
UNIVERSITY OF VIRGINIA
COURSE SYLLABUS
Course Title: Algorithms
Course Number: CS4102
Credit Hours: 3
Instructor
Name: K. C. Wong
Office: Rice Hall 202
Phone: (434)982-2224
E-mail: k
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
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
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
L3 4102
sep 2 2013
shelat
Karatsuba algorithm
1
7
8
9
We are aiming to compute
ac*100^2 + (ad+bc)*100 + bd.
1
4
3
2
The way that we are going to compute
(ad+bc) is to (1) compute (a+b)(c+d)
recursively, (2) then we subtract of ac
bd
(a+b)(c+d) -ac -bd = a