Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 12 - Wednesday.  What did we talk about last time?  Matching  Stable marriage  Started Euler paths.

Similar presentations


Presentation on theme: "Week 12 - Wednesday.  What did we talk about last time?  Matching  Stable marriage  Started Euler paths."— Presentation transcript:

1 Week 12 - Wednesday

2  What did we talk about last time?  Matching  Stable marriage  Started Euler paths

3

4

5

6

7  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

8  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

9  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

10  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

11  Put the bridge from the Bishop’s land to the Red Prince’s land

12  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

13  Put the bridge from the Red Prince’s land to the Blue Prince’s land

14  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

15  Put the bridge from the Center Island to the Red Prince’s land, making all pieces of land have even degree

16

17 8 7 9 5 6 0 3 4 2 1

18 1 52 43

19 Student Lecture

20

21  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

22  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

23  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

24 50 10 15 20 70 80 6 6 8 8 11 12 16 18 21 25 27 29 54 56 71 76 81 89

25 12 5 5 8 8 13 15 Insert 7 12 5 5 7 7 8 8 13 15

26 12 2 2 5 5 7 7 8 8 13 15 Insert 6 6 6 12 2 2 5 5 13 15 7 7 8 8

27  Insert the following numbers:  86 69 81 15 100 94 8 27 56 68 92 89 38 53 88

28  When the list of keys drops below half m, we have to redistribute keys  In the worst case, we have to delete a level

29  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

30  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 6 12 2 2 5 5 13 15 6 6 7 7 8 8

31 Are you ready to get Hamiltonian with it?

32  The Eulerian Cycle problem asked if you could start at some node, cross every edge once, and return to the start  The Hamiltonian Cycle problem asks if you can start at some node, visit every node only once, and return to the start  In other words, find a tour  Sounds easy, right?

33  On this graph: E E A A C C B B D D E A C B D

34  Now, on this graph:  There isn’t one! E E A A C C B B D D F F

35  Now, on this graph: Hmmm…

36

37  Given a graph, find the shortest tour that visits every node and comes back to the starting point  Like a lazy traveling salesman who wants to visit all possible clients and then return to his home

38  Find the shortest TSP tour:  Starts anywhere  Visits all nodes  Has the shortest length of such a tour E E A A D D B B F F C C 5 6 4 4 3 5 2 7 3 3

39  Strategies:  Always add the nearest neighbor  Randomized approaches  Try every possible combination  Why are we only listing strategies?

40  So far we haven’t given a foolproof solution to TSP  Let’s look at two possibilities:  Greedy Solution: Pick the closest neighbor  Brute Force: Try all possibilities

41

42  Finish NP-completeness  Elementary sorts  Merge sort

43  Start on Project 4  Form teams by Friday  Start on Assignment 6  Read sections 2.1 and 2.2


Download ppt "Week 12 - Wednesday.  What did we talk about last time?  Matching  Stable marriage  Started Euler paths."

Similar presentations


Ads by Google