Mathematics for Computer Science Normal Person’s Graph MIT 6.042J/18.062J DAGs, Partial Orders, Scheduling y = f(x) y x Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.1 September 28, 2005 Computer Scientist’s Graph a c set of vertices V set of edges E, E ⊆ V × V f (Formally the same as a binary relation on V.) V={a,b,c,d} E = {(a,b), (a,c), (c,b)} e Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.3 September 28, 2005 Graphical Properties of Relations Reflexive Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. d b c L4-2.4 September 28, 2005 A R Antisymmetric NO September 28, 2005 a Paths Symmetric Transitive L4-2.2 September 28, 2005 Relations and Graphs b d Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.5 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.6 1 R2 from A to A A Path Relations R= paths a1Rka2 iff of length 1 R2 = paths of length 2 R≤ 2 = paths of length ≤ 2 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.7 September 28, 2005 Reflexive Transitive Closure a1 and a2 are connected by path of length exactly k in the graph of R a1R≤ka2 iff a1 and a2 are connected by path of length at most k in the graph of R Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Prerequisite Relation on Classes class c is a prerequisite for class d a1R*a2 iff a1 and a2 are connected by path Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. c→d L4-2.9 September 28, 2005 Some Course 6 Prerequisites • • • • • • 18.01 → 6.042 18.01 → 18.02 18.01 → 18.03 8.01 → 8.02 6.001 → 6.034 6.042 → 6.046 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.10 Indirect Prerequisites • 18.03, 8.02 → 6.002 • 6.001, 6.002 → 6.004 • 6.001, 6.002 → 6.003 • 6.004 → 6.033 • 6.033 → 6.857 • 6.046 → 6.840 September 28, 2005 L4-2.8 September 28, 2005 L4-2.11 18.01 → 6.042 → 6.046 → 6.840 18.01 is indirect prereq. of 6.840 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.12 2 Classes with no prereqs 18.01 8.01 Minimal elements 6.001 d is minimal for → "Freshman classes" there is no c s.t. c→d d is a Freshman class iff nothing → d L4-2.13 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Prerequisite graph 18.01 18.02 6.042 8.01 18.03 6.002 6.840 6.004 September 28, 2005 L4-2.14 minimal not minimum 6.001 8.02 6.046 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. 6.034 minimum means "smallest" -- a prereq. for every class no minimum in this example 6.003 6.033 6.857 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.15 Team Problem September 28, 2005 September 28, 2005 L4-2.16 Prerequisite graph What if there is a cycle in this graph? -- a path from class c to class d and back to class c? No one can graduate! Comm. on Curricula & Registrar are supposed to prevent cycles. Problem 1,2 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.17 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.18 3 Directed Acyclic Graph (DAG) 18.01 18.02 6.042 8.01 18.03 6.001 8.02 6.046 6.002 6.840 6.004 6.034 6.003 DAG's = Partial Orders Theorem: • The path relation of a DAG is a partial order. • The graph of a partial order is a DAG. 6.033 6.857 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.19 Constructing the DAG • • • • • • 18.01 → 6.042 18.01 → 18.02 18.01 → 18.03 8.01 → 8.02 6.001 → 6.034 6.042 → 6.046 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.20 September 28, 2005 Directed Acyclic Graph (DAG) • 18.03, 8.02 → 6.002 • 6.001, 6.002 → 6.004 • 6.001, 6.002 → 6.003 • 6.004 → 6.033 • 6.033 → 6.857 • 6.046 → 6.840 18.01 8.01 6.001 Identify Minimal Elements Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.21 Constructing the DAG • • • • • • 18.01 → 6.042 18.01 → 18.02 18.01 → 18.03 8.01 → 8.02 6.001 → 6.034 6.042 → 6.046 • 18.03, 8.02 → 6.002 • 6.001, 6.002 → 6.004 • 6.001, 6.002 → 6.003 • 6.004 → 6.033 • 6.033 → 6.857 • 6.046 → 6.840 September 28, 2005 September 28, 2005 L4-2.22 Constructing the DAG Remove minimal elements Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. • 6.042 • 18.02 • 18.03 • 8.02 • 6.034 • 6.042 → 6.046 • 18.03, 8.02 → 6.002 • 6.002 → 6.004 • 6.002 → 6.003 • 6.004 → 6.033 • 6.033 → 6.857 • 6.046 → 6.840 Remove minimal elements L4-2.23 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.24 4 Constructing the DAG • 6.042 • 18.02 • 18.03 • 8.02 • 6.034 • 6.042 → 6.046 Directed Acyclic Graph (DAG) • 18.03, 8.02 → 6.002 • 6.002 → 6.004 • 6.002 → 6.003 • 6.004 → 6.033 • 6.033 → 6.857 • 6.046 → 6.840 18.01 18.02 6.042 8.01 18.03 6.001 8.02 6.034 continue in this way… Identify new minimal elements L4-2.25 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Prerequisite graph Directed Acyclic Graph (DAG) 18.01 18.02 6.042 6.046 8.01 18.03 8.02 L4-2.26 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. 6.001 18.01 6.034 18.02 6.002 6.042 8.01 18.03 6.001 8.02 6.046 6.002 6.840 6.004 6.034 6.003 6.033 6.857 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.27 Topological sort L4-2.28 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. How many terms to graduate? 18.01 • Is there a way of graduating? (in any number of semesters?) 18.02 • Yes - take a minimal remaining course each semester 6.042 8.01 18.03 6.001 8.02 6.046 6.002 6.840 6.004 6.033 6.034 6.003 maximum chain 6.857 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.29 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.30 5 Parallel Task Scheduling and Sufficient… • 6 terms are necessary to complete the curriculum 18.01 18.02 • and sufficient (if you can take unlimited courses per term...) 6.042 8.01 18.03 6.001 8.02 6.046 6.002 6.840 6.004 6.034 6.003 6.033 6.857 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.31 Antichains Parallel Task Scheduling Set of courses that can be taken in any order: Theorem: If the longest chain has size t, then the elements can be partitioned into Any two courses in set are incomparable Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 t successive antichains, with no element in any block preceding anything in a preceding block L4-2.34 and Sufficient… 18.01 Take Bi = {a | largest chain ending in a is of size i} 18.02 If there is a y in Bi such that xÆ y and x not in B1….Bi-1 then there is a chain of size >i ending in y September 28, 2005 L4-2.35 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. Why sufficient? Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.32 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.36 6.042 8.01 18.03 6.001 8.02 6.046 6.002 6.840 6.004 6.034 6.003 6.033 6.857 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.37 6 Minimum “Parallel” Time Minimum “Parallel” Time parallel time = max chain size. required # processors ≤ max antichain size. L4-2.38 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. but 5-course term not necessary. Possible that min-time #processors < max antichain size Min-time Schedule 18.01 18.02 6.042 Another Min-time Schedule 8.01 18.03 6.001 8.02 6.046 6.002 6.840 6.004 18.01 6.034 6.042 18.02 6.003 18.03 6.001 8.02 6.002 6.840 6.004 6.034 6.003 6.033 6.857 6.857 September 28, 2005 L4-2.40 3 Subjects per Term Possible Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. 8.01 6.046 6.033 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. L4-2.39 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. 18.01 8.01 6.001 18.03 8.02 6.034 6.042 6.002 6.003 6.046 6.004 6.840 6.033 18.02 6.857 September 28, 2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.41 A 3-course term is necessary • 15 subjects • max chain size = 6 • size of some block must be ≥ ⎡15/6⎤ = 3. ∴ to finish in 6 terms, must take ≥3 classes some term L4-2.43 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.44 7 Dilworth’s Lemma Height/Birthday Partial Order A partial order on n items has • a chain of size ≥ t, or ⎡n⎤ • or an antichain of size ≥ ⎢ ⎥ ⎢t⎥ for all 1 ≤ t ≤ n. Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 Two students are related to each other iff one is shorter and younger than the other (s1, a1) Y (s2, a2) iff (s1 ≤ s2) and (a1 ≤ a2) L4-2.45 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.46 Dilworth Demo Height/Birthday Partial Order Chain of students: get older as they get taller. AntiChain of students: get younger as they get taller. Older Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.47 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.48 Team Problem Problem 4 Copyright © Albert R. Meyer and Ronitt Rubinfeld 2005. September 28, 2005 L4-2.49 8