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 p.m. in The Point 113 (or next door in The Point 112)
 Used to be Königsberg, Prussia  Now called Kaliningrad, Russia  On the Pregel River, including two large islands
 In 1736, the islands were connected by seven bridges  In modern times, there are only five
 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
 Can you find such a solution?  Start anywhere and find a path which crosses each bridge exactly once
 What did Euler find?  The same thing you did: nothing  But, he also proved it was impossible  Here’s how: North Shore Center East Island Island South Shore
 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) North Shore Center East Island Island South Shore
 There is actually an way to find such a path on a graph where one 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
 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
 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
 Put the bridge from the Bishop’s land to the Red Prince’s land
 Furious, the Red Prince wants to build his own bridge so that only he can start at his own castle, cross all the bridges once and then end at the Tavern
 Put the bridge from the Red Prince’s land to the Blue Prince’s land
 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
 Put the bridge from the Center Island to the Red Prince’s land, making all pieces of land have even degree
2 1 3 4 9 5 0 7 8 6
1 5 2 4 3
 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)
 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
 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
4 a b 3 5 3 7 4 7 s c d t 4 6 1 6 e f 5
 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
 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
4 a b 3 5 3 7 4 7 s c d t 4 6 1 6 e f 5
 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 other  Think of it as a line that slices through the edges, putting s on one side and t on the other  The capacity of a cut is the sum of the capacities of the edges that the cut divides
 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
4 a b 3 5 3 7 4 7 s c d t 4 6 1 6 e f 5
 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 )
 Binary trees are great  However, only two splits means that you have a height of log 2 n when you want to store n things  If n = 1,000,000, log 2 n = 20  What if depth was expensive? Could we have say, 10 splits?  If n = 1,000,000, log 10 n = 6
 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
 A B-tree of order m has the following properties: The root has at least two subtrees unless it is a leaf 1. 2. Each nonroot and each nonleaf node holds k keys and k + 1 pointers to subtrees where m /2 ≤ k ≤ m Each leaf node holds k keys where m /2 ≤ k ≤ m 3. 4. All leaves are on the same level
50 70 80 10 15 20 54 56 71 76 81 89 6 8 11 12 16 18 21 25 27 29
12 5 8 13 15 Insert 7 12 5 7 8 13 15
12 2 5 7 8 13 15 Insert 6 6 12 2 5 7 8 13 15
 Insert the following numbers:  86 69 81 15 100 94 8 27 56 68 92 89 38 53 88
 When the list of keys drops below half m , we have to redistribute keys  In the worst case, we have to delete a level
 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
 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 6 7 8 12 13 15
 Finish B-trees  Intractability and NP-completeness
 Work on Project 3  Finish Assignment 5  Due tonight!
Recommend
More recommend