240 likes | 406 Views
CS 173: Discrete Mathematical Structures. Cinda Heeren heeren@cs.uiuc.edu Siebel Center, rm 2213 Office Hours: W 12:30-2:30. CS 173 Announcements. Homework #12 available, due 12/11, 8a. Final exam 12/14, 8-11a. Rooms announced on web site.
E N D
CS 173:Discrete Mathematical Structures Cinda Heeren heeren@cs.uiuc.edu Siebel Center, rm 2213 Office Hours: W 12:30-2:30
CS 173 Announcements • Homework #12 available, due 12/11, 8a. • Final exam 12/14, 8-11a. Rooms announced on web site. • Conflict 12/14, 1:30-4:30p. Siebel Center Rm 1109, 1105. • Review 12/12, 5-6p, SC1404. Additional reviews will be announced. • ACM study hall 1-5p, Sunday & Monday Cs173 - Spring 2004
shoes belt jacket socks jeans swter jwlry In what order will you get dressed while respecting constraints? uwear shirt CS173Total Orders Consider the problem of getting dressed. Precedence constraints are modeled by a poset in which a b iff you must put on a before b. Let (S, ) be a poset (S finite). We will extend to a total order on S, so we can decide for all incomparable pairs whether to make a b, or vice versa w/o violating T,R,A. Cs173 - Spring 2004
shoes belt jacket socks jeans swter jwlry NOT A REAL PROOF! Should use induction!! uwear shirt CS173Total Orders Things we need: Lemma: Every finite non-empty poset (S, ) has at least one minimal element. Proof: choose a0 S. If a0 was not minimal, then there exists a1 a0, and so on until a minimal element is found. Cs173 - Spring 2004
shoes belt jacket socks jeans swter jwlry uwear shirt CS173Total Orders More things we need: Lemma: If (S, ) is a poset with a minimal, then (S-{a}, ) is also a poset. Proof: If you remove minimal a reflexivity and antisymmetry still hold. If x,y,z S-{a}, with x y and y z, then x z too, since (S, ) was transitive. Cs173 - Spring 2004
shoes belt jacket socks jeans swter jwlry Depending on which min elt is chosen each time, a different total order is obtained, but all TOs will be consistent with the PO. uwear shirt CS173Total Orders Think about what this means: • There is always a minimal element. • If you remove it you still have a poset. alg Topological Sort Input: poset (S, ) Out: elements of S in total order While S Remove any min elt from S and output it. This suggests: Cs173 - Spring 2004
shoes belt jacket socks jeans swter jwlry uwear shirt t CS173Total Orders alg Topological Sort Input: poset (S, ) Out: elements of S in total order While S Remove any min elt from S and output it. Cs173 - Spring 2004
Why are these two problems on the same slide? CS173Graphs Suppose YOU are the person in charge of scheduling finals. Conflict exams are not allowed…that is, no student can have two exams scheduled for any one time. How many exam periods do you need? Suppose I give you a graph consisting of vertices and edges. Your task is to label the vertices with colors. Vertices which share an edge cannot be colored the same. How many colors do you need? Cs173 - Spring 2004
CS173Graphs Graphs are a very general way of representing data. We can use graphs to model things as diverse as: • Scheduling problems • Routes for travelling between cities • Connections between atoms in a molecule • Paths that messages can take in a network • Dependence relations between events in a large project Cs173 - Spring 2004
CS173Graphs Cs173 - Spring 2004
CS173Graphs Definitions you should understand: • Simple • Vertex • Edge • Weights • Degree • Neighbors • Connected • Complete • Bipartite • Planar • Cycle • Tree • Path • Circuit Cs173 - Spring 2004
A B C D E Why or why not? CS173Graphs A real estate agent wishes to give a tour of this house, starting and ending outside, and going through each door exactly once. Can she do it? Cs173 - Spring 2004
A B C D E outside CS173Graphs Model the floor plan as a graph. A B C D E Cs173 - Spring 2004
Is there an Eulerian Path (or circuit) in this graph? Given a graph, how can we tell if an Eulerian Path (or circuit) exists? A “circuit” is a path that begins and ends at the same vertex. CS173Graphs An equivalent question is: Can we traverse the graph, visiting each edge exactly once? A B C D E outside Cs173 - Spring 2004
CS173Graphs A connected graph contains an Eulerian Circuit if and only if every vertex has even degree. A connected graph contains an Eulerian Path if and only if exactly 2 vertices have odd degree. Cs173 - Spring 2004
CS173Graphs Pick a vertex and attempt to find the Eulerian Cycle... Cs173 - Spring 2004
CS173Graphs The algorithm: • Pick a vertex u. • Follow any edge from u to another vertex v. • Travel from v to any other vertex. (This is possible because all vertices have even degree.) • Continue forging a path until vertex u is reached again. • If all edges are on the path, quit. Otherwise, pick any vertex u’ on the current path, and repeat the process to return to u’, and then splice the new route into the path. • Do this until all edges are included in the path. Cs173 - Spring 2004
All Orange Green Orange and green Beats me! CS173Graphs Quiz time: Which graphs have an Eulerian Circuit? Cs173 - Spring 2004
All Orange Green Orange and green Beats me! Bonus: Give a descriptive name for the green graph. CS173Graphs Quiz time: Which graphs have an Eulerian Path? Cs173 - Spring 2004
4 1 7 12 6 11 14 13 8 3 2 10 CS173Graphs • Suppose you live in an itty bitty town, where none of the streets are paved. Your community WANTS to build a swimming pool, but they MUST perform some road upgrades, and the budget is limited. • The road committee has decided that it’s important for a paved path to exist between every pair of houses in the town. • A swimming pool will cost $1 million. The cost of paving each stretch of road is given in the graph below ($10k). • Given these constraints, the graph, and a budget of $1.4 million, can you upgrade the roads AND build a swimming pool? 5 9 Cs173 - Spring 2004
Can we build the swimming pool? Which would you pave first? • (b,e) • (e,h) • (b,c) • (d,e) • None of these. Which would you pave second? • (a,b) • (e,h) • (b,f) • (g,h) • None of these. CS173Graphs • The road committee has decided that it’s important for a paved path to exist between every pair of houses in the town. Which ones should we pave in order to minimize cost? 4 1 a b c 12 6 5 7 11 14 d e f 9 8 3 13 2 10 g h i Cs173 - Spring 2004
CS173Graphs • Alternative algorithm: 4 1 a b c 12 6 5 7 11 14 d e f 9 8 3 13 2 10 g h i Cs173 - Spring 2004
More formal study of this in cs473, FUN! CS173Graphs Official name for the structure you created: “Minimal cost spanning tree” 4 1 a b c 12 6 5 7 11 14 d e f 9 8 3 13 2 10 g h i Cs173 - Spring 2004
CS173Graphs Cs173 - Spring 2004