Graphs:
* sparse - e<= v log v
* dense - e = MAX - (weird e)
* complete graph - max num edges
* adjacency matrix - array of neighbor list
*M[i][j] = 1 if (i,j) in set E
*M[i][j] = 0 if (i,j) not in
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Dynamic Programming Examples
The unbounded knapsack problem
Given a knapsack that can hold a weight limit L, and a set of
n types items that each has a weigh
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
More on Network Flow
An example to review
A
3 /3
1
1 /1
2 /7
s
C
t
2
5 /5
3 /7
3 /9
B
Let's look for bottlenecks
An st-cut on G is a set of edges in G that,
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Dynamic Programming Exercises
Questions to ask in finding dynamic programming solutions
Does the problem have optimal substructure?
Can solve the problem by
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Compression
What is compression?
Represent the same data using less storage space
Can get more use out a disk of a given size
Can get more use out of memor
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Additional Dynamic Programming
Examples
Subset sum
Given a set of non-negative integers S and a value k, is there
a subset of S that sums to exactly k?
2
Sub
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Searching
Symbol tables
Abstract structures that link keys to values
Key is used to search the data structure for a value
Described as a class in the text,
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Sorting
The sorting problem
Given a list of n items, place the items in a given order
Ascending or descending
Numerical
Alphabetical
etc.
First, well re
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Introduction
Meta-notes
These notes are intended for use by students in CS1501 at
the University of Pittsburgh. They are provided free of
charge and may not
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Hashing
Wouldnt it be wonderful if.
Search through a collection could be accomplished in (1)
with relatively small memory needs?
Lets try this:
Assume we h
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Greedy Algorithms and Dynamic
Programming
Consider the change making problem
What is the minimum number of coins needed to make up a
given value k?
If you w
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
B-trees
The problem
Weve discussed several approaches to search through a set
of keys and retrieve a value
Several implementations of a symbol table
All of
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Priority Queues
We mentioned priority queues in building Huffman tries
Primary operations they needed:
Insert
Find item with highest priority
E.g., findMi
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Brute-force Search
Brute-force (or exhaustive) search
Find the solution to a problem by considering all potential
solutions and selecting the correct one
Ru
CS/COE 1501
cs.pitt.edu/~bill/1501/
Hashing
Wouldnt it be wonderful if.
Search through a collection could be accomplished in (1)
with relatively small memory needs?
Lets try this:
Assume we have an
CS/COE 1501
cs.pitt.edu/~bill/1501/
Sorting
The sorting problem
Given a list of n items, place the items in a given order
Ascending or descending
Numerical
Alphabetical
etc.
2
Prerequisites
boolean
CS/COE 1501
cs.pitt.edu/~bill/1501/
Introduction
Meta-notes
These notes are intended for use by students in CS/COE
1501 at the University of Pittsburgh. They are provided
free of charge and may not b
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Network Flow
Defining network flow
Consider a directed, weighted graph G(V, E)
Weights are applied to edges to state their capacity
c(v, w) is the capacity
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
B-trees
The problem
Weve discussed several approaches to search through a set
of keys and retrieve a value
Several implementations of a symbol table
All of
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Dealing with NP-Complete
Problems
So what are NP-Complete problems?
First of all, to review:
What are P problems?
What are NP problems?
What are NP-Comple
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Introduction
Meta-notes
These notes are intended for use by students in CS1501 at
the University of Pittsburgh. They are provided free of
charge and may not
[NAME]
Dr. Garrison
CS 1501
23 March 2017
Boyer-Moore Search
As users of my word processor, I am sure you have come across the find feature.
Finding a specific word or phrase within your document is i
[NAME] 1
[NAME]
Dr. Garrison
CS 1501
2 February 2017
Merge Sort
When considering the problem of sorting, our goal is typically to take an unordered list of
items and put the list into ascending or des
[NAME] 1
[NAME]
Dr. Garrison
CS 1501
27 February 2017
LZW Compression
LZW compression is an excellent way to compress large files into smaller ones utilizing a
codebook. This codebook contains entries
[NAME]
Dr. Farnan
CS 1501
One of the most important features of a good spreadsheet application is the ability to sort.
When considering the problem of sorting, our goal is typically to take an unorder
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Compression 2
When we last left our heroes.
Huffman coding allowed for optimal
encoding on a symbol by symbol basis
We created and traversed a trie to
gener
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
More Math
Exponentiation
xy
Can easily compute with a simple algorithm:
ans = 1
for i = 1 . y:
ans = ans * x
Runtime?
It's just a for loop with a single m
CS/COE 1501
www.cs.pitt.edu/~nlf4/cs1501/
Graphs
5
3
4
0
2
1
Graphs
A graph G = (V, E)
Where V is a set of vertices
E is a set of edges connecting vertex pairs
Example:
V = cfw_0, 1, 2, 3, 4, 5