SLIDE 1
Week 10 - Friday What did we talk about last time? Shortest paths - - PowerPoint PPT Presentation
Week 10 - Friday What did we talk about last time? Shortest paths - - PowerPoint PPT Presentation
Week 10 - Friday What did we talk about last time? Shortest paths Matching bipartite graphs Stable marriage Lab hours Wednesdays at 5 p.m. in The Point 113 Saturdays at noon in The Point 113 CS Club Tuesdays at 5
SLIDE 2
SLIDE 3
SLIDE 4
SLIDE 5
SLIDE 6
Lab hours
- Wednesdays at 5 p.m. in The Point 113
- Saturdays at noon in The Point 113
CS Club
- Tuesdays at 5 p.m. in The Point 113 (or next door in The Point 112)
SLIDE 7
SLIDE 8
Used to be Königsberg, Prussia Now called Kaliningrad, Russia On the Pregel River, including two large islands
SLIDE 9
In 1736, the islands were connected by seven bridges In modern times, there are only five
SLIDE 10
After a lazy Sunday and a bit of drinking, the citizens would
challenge each other to walk around the city and try to find a path which crossed each bridge exactly once
SLIDE 11
Can you find such a solution? Start anywhere and find a path which crosses each bridge
exactly once
SLIDE 12
What did Euler find? The same thing you did: nothing But, he also proved it was impossible Here’s how:
Center Island North Shore East Island South Shore
SLIDE 13
By simplifying the problem into a graph, the
important features are clear
To arrive as many times as you leave, the
degrees of each node must be even (except for the starting and ending points)
Center Island North Shore East Island South Shore
SLIDE 14
There is actually an way to find such a path on a graph where
- ne exists:
- Start with a node of odd degree if there is one
- Every time we move across an edge, delete it
- If you have a choice, always pick an edge whose deletion will not
disconnect the graph
At the end of the algorithm, you will either have an Eulerian
path or an Eulerian cycle, depending on the graph
SLIDE 15
We can label the nodes to make a more interesting problem Now each piece of land is associated with the Blue Prince, the
Red Prince, the Bishop, or the Tavern
SLIDE 16
The Blue Prince wants to build an 8th bridge so that he can
walk starting at his castle, cross every bridge once, and end at the Tavern to brag
SLIDE 17
Put the bridge from the Bishop’s land to the Red Prince’s land
SLIDE 18
Furious, the Red Prince wants to build his own bridge so that
- nly he can start at his own castle, cross all the bridges once
and then end at the Tavern
SLIDE 19
Put the bridge from the Red Prince’s land to the Blue Prince’s
land
SLIDE 20
Upset by this pettiness, the Bishop decides to build a 10th
bridge which allows all citizens to cross all bridges and return to their starting point
SLIDE 21
Put the bridge from the Center Island to the Red Prince’s land,
making all pieces of land have even degree
SLIDE 22
SLIDE 23
8 7 9 5 6 3 4 2 1
SLIDE 24
1 5 2 4 3
SLIDE 25
SLIDE 26
A flow network is a weighted, directed graph with positive
edge weights
- Think of the weights as capacities, representing the maximum units
that can flow across an edge
An st-flow network has a source s (where everything comes
from) and a sink t (where everything goes to)
SLIDE 27
Oil flowing from a start to a destination Airline crews needed to man aircraft, moving from city to city Goods being produced by factories and consumed by cities,
with roads that can accommodate a certain amount of traffic
SLIDE 28
A common flow problem is to find the maximum flow A maximum flow is a non-negative amount of flow on each
edge such that:
- The maximum amount of flow gets from s to t
- No edge has more flow than its capacity
- The flow going into every node (except s and t) is equal to the flow
going out
SLIDE 29
s t a b c d e f 4 5 3 7 4 3 7 6 4 1 5 6
SLIDE 30
When we were talking about matching, we mentioned
augmenting paths
Augmenting paths in flows are a little different A flow augmenting path:
- Starts at s and ends at t
- May cross some edges in the direction of the edge (forward edges)
- May cross some edges in the opposite direction (backwards edges)
- Increases the flow by the minimum of the unused capacity in the
forward edges or the maximum of the flow in the backwards edges
SLIDE 31
Ford-Fulkerson is a family of algorithms for finding the
maximum flow
- 1. Start with zero flow on all edges
- 2. Find an augmenting path (increasing flow on forward edges
and decreasing flow on backwards edges)
- 3. If you can still find an augmenting path, go back to Step 2
SLIDE 32
s t a b c d e f 4 5 3 7 4 3 7 6 4 1 5 6
SLIDE 33
An cut in a graph partitions the graph into two disjoint sets An st-cut is a cut such that s is in one partition and t is in the
- ther
Think of it as a line that slices through the edges, putting s on
- ne side and t on the other
The capacity of a cut is the sum of the capacities of the edges
that the cut divides
SLIDE 34
The smallest capacity st-cut you can make has the same
capacity as the largest possible st-flow
Intuitively, it's like that cut is a set of edges that most
constricts the flow from s to t
SLIDE 35
s t a b c d e f 4 5 3 7 4 3 7 6 4 1 5 6
SLIDE 36
Our definition of Ford-Fulkerson didn't say how you pick the
augmenting path
At worst, it could take O(|E|f), where |E| is the number of
edges in the graph and f is the maximum flow
- That could be terrible if f has a large numerical value
Edmonds-Karp is a variation of Ford-Fulkerson that uses a
breadth-first search to find a shortest augmenting path
- It runs in O(|V||E|2)
SLIDE 37
SLIDE 38
Binary trees are great However, only two splits means that you have a height of log2
n when you want to store n things
- If n = 1,000,000, log2 n = 20
What if depth was expensive? Could we have say, 10 splits?
- If n = 1,000,000, log10 n = 6
SLIDE 39
Answer: When the tree is in secondary storage Each read of a block from disk storage is slow
- We want to get a whole node at once
- Each node will give us information about lots of child nodes
- We don’t have to make many decisions to get to the node we want
SLIDE 40
A B-tree of order m has the following properties: 1.
The root has at least two subtrees unless it is a leaf
- 2. Each nonroot and each nonleaf node holds k keys and k + 1 pointers
to subtrees where m/2 ≤ k ≤ m
3.
Each leaf node holds k keys where m/2 ≤ k ≤ m
- 4. All leaves are on the same level
SLIDE 41
50 10 15 20 70 80 6 8 11 12 16 18 21 25 27 29 54 56 71 76 81 89
SLIDE 42
12 5 8 13 15
Insert 7
12 5 7 8 13 15
SLIDE 43
12 2 5 7 8 13 15
Insert 6
6 12 2 5 13 15 7 8
SLIDE 44
Insert the following numbers:
- 86 69 81 15 100 94 8 27 56 68 92 89 38 53 88
SLIDE 45
When the list of keys drops below half m, we have to
redistribute keys
In the worst case, we have to delete a level
SLIDE 46
Instead of requiring every non-root node to be half full, every
non-root node must be at least 2/3 full
Key redistribution becomes more complex However, the tree is fuller
SLIDE 47
Essentially, make a B-tree such that all the leaves are tied
together in a linked list
It is also necessary that all keys in a B-tree appear as leaves Some other variations are possible, but we’ll end the list here
6 12 2 5 12 13 15 6 7 8
SLIDE 48
SLIDE 49
Finish B-trees Intractability and NP-completeness
SLIDE 50
Work on Project 3 Finish Assignment 5
- Due tonight!