a b c d a b c d e 5 e 7

Size: px
Start display at page:

Download "a b c d a b c d e 5 e 7"

Transcription

1 COMPSCI 230 Homework 9 Due on April 5, 2016 Work on this assignment either alone or in pairs. You may work with different partners on different assignments, but you can only have up to one partner for any one assignment. You may not talk about this assignment with others until all of you have handed in their work. See Mechanics Homework on the class web page for details on the homework policy. This assignment comes with auxiliary files hw.tex and hw.py. Remember to put your name in the right place in the.tex file before starting to work with it. Usual formatting instructions hold, including instructions about proof style (see Homework 8 for those). 1. The.tex template file shows how to draw the graph G shown below and write its adjacency matrix in L A TEX. Vertex labels are placed on a 2 by 2 grid (with the same ampersand and double-backslash notation you would use in the tabular environment) and then the \ncline and \nccircle commands add edges. For instance, \ncline{1, 1}{1, 2} draws a line between vertex a (in position (1, 1) on the grid) and vertex b (in position (1, 2)); the command \nccircle draws a circular arc from a vertex to itself. The command right after each \ncline or \nccircle command places labels. You need not concern yourself with how to do all this, because this problem asks you only to remove existing edges. When you do so, remove both the line-drawing command and the corresponding labeling command (that is, remove the whole line in the hw.tex file). The file hw.tex has a drawing, an adjacency matrix for G, and an arbitrary path repeated where appropriate. Just modify those for your answers to this and the following questions. If you use L A TEX, you will notice that compilation is slow when graphs are involved. This is normal. Use your own favorite drawing program if you are not planning to use L A TEX. Several of the following questions admit more than one acceptable answer. However, you will be penalized for removing more edges than needed. A graph may or may not have an open Euler tour (an open tour is a tour that is not a circuit), an Euler circuit, an open Hamilton tour, or a Hamilton circuit. Let us call these four types of tour special. (a) Is the graph G above simple? Why or why not? e 2 a c e 4 e 3 e 1 e 6 b d e 5 e 7 a b c d a b c d (b) Without removing any vertices, remove as few edges from G as possible, if any, until the new graph G 1 has an open Euler tour that is not also a special tour of a different type (it is OK for G 1 to have other tours that are special, regardless of their types). If multiple open Euler tours are possible on G 1, give one of them. Show the drawing and adjacency matrix for G 1 as indicated in the file hw.pdf, and then show your tour as a sequence of the following form: (vertex, edge, vertex,..., edge, vertex). (c) Without removing any vertices, remove as few edges from G as possible, if any, until the new graph G 2 has an Euler circuit that is not also a special tour of a different type. If multiple Euler circuits are possible on G 2, give one of them. Show the drawing and adjacency matrix for G 2, and then show your circuit as a sequence. No explanations needed. (d) Without removing any vertices, remove as few edges from G as possible, if any, until the new graph G 3 has an open Hamilton tour that is not also a special tour of a different type. Show the drawing and adjacency matrix for G 3, and then show your tour as a sequence. No explanations needed. (e) Without removing any vertices, remove as few edges from G as possible, if any, until the new graph G 4 has a Hamilton circuit that is not also a special tour of a different type. Show the drawing and adjacency matrix for G 4, and then show your circuit as a sequence. No explanations needed. [Assignment continues on the next page]

2 2. Let A be the adjacency matrix of some graph G = (V, E). If G has n vertices numbered 1 through n, then A is n n and symmetric 1, and the entry a uv = a vu of A is the number of distinct edges between vertices u and v. We now prove that entry a (p) uv = a (p) vu of the p-th power of A { A p A if p = 1 = A A p 1 otherwise is the number of distinct paths of length p between vertices u and v. Recall that path length is measured by the number of edges, and that the product AB of two n n matrices A and B is another n n matrix C that is symmetric if both A and B are, and whose entry u, v is n c uv = a uk b kv. k=1 Your task is to fill the boxes in the proof below. The proof itself is repeated in the file hw.tex. Just put your text between braces wherever you see \answer{}. Do not remove the \answer{} command itself. This will put your text in a box, and will make it easier for us to find it in your solution. If you use something other than L A TEX, make sure that your text is boxed in a similar way. Be careful with math mode if you use L A TEX: If the \answer{} command appears inside an equation or another expression in math mode, do not put dollar signs around your formulas, since you are in math mode already. If the command is not inside text in math mode, you need to use dollar signs inside it to switch to/from math mode as appropriate. CAVEAT: We saw in class that it is safest to restate results so that a proof by induction is on a variable called n. However, choosing n to denote the number of vertices of a graph is a very widely accepted convention, so this proof will be by induction on p. Just be mindful of this. Proof. We prove this result by induction on p. Specifically, we want to prove that p 1 P (p) where the predicate P (p) means that if A is the adjacency matrix of a graph, then entry a (p) uv = a (p) vu of the symmetric matrix A p is the number of distinct paths of length p between vertices u and v. For the base case p = [your text here], the matrix A p is [your text here] by definition, and entry a uv = a vu of A is the number of [your text here]. A path of length 1 is [your text here], so for p = 1 the matrix A p is the number of distinct paths of length p between vertex u and vertex v. This proves [your text here]. For the inductive step, make the inductive assumption that for any k 1 the predicate P (k) holds, that is, [your text here]. Let us subdivide all the paths of length k + 1 from u to v into n groups. Group w contains all those paths that have edge (w, v) as their last edge. Let i w be the number of paths of length k + 1 in group w. [i w = [your text here] if there is no edge between w and v.] Paths in different groups are distinct from each other, because [your text here], so a (k+1) uv = [your text here]. We can determine i w as follows: By the inductive assumption, there are [your text here] paths of length k from u to w. To go from u to v over k + 1 edges and passing through w, we can choose one of [your text here] ways to reach w in k edges. For each of these choices, we can choose any one of the [your text here] edges to take the last step from w to v. Thus, we have i w = [your text here]. In conclusion, since the number of paths from u to v is the same as that from v to u, we can combine the last two equations to obtain a (k+1) uv = a (k+1) vu = [your text here], which is entry u, v of [your text here] by the definition of this matrix and of matrix product. This establishes the inductive step P (k) P (k + 1) for k 1 and completes the proof. [Assignment continues on the next page] 1 A matrix A with entries a uv is symmetric if a uv = a vu for all u and v.

3 3. In this problem you will implement an algorithm in Python to find an Euler tour (either open or a circuit) for a given graph G. The output is in the form of a Python list that represents the desired tour. If no such tour exists, the algorithm returns the empty list. The algorithm is due to a Monsieur Fleury, who devised it in (a) Suppose that a graph G is given through its adjacency matrix A. In light of the result you proved in the previous problem, what is a simple way to check if the graph G is connected, without running any graph search? Recall that a graph is connected if for all pairs (u, v) of distinct vertices in G there is a path from u to v. Prove your statement. [Hint: A graph is not connected iff there is a pair of vertices for which there is no path of length 1, and no path of length 2,.... When do the dots stop? In other words, what is the longest possible shortest path between any two distinct vertices of a graph G with n vertices, and why?] (b) Write a Python function def isconnected(a): that takes an adjacency matrix A and returns True if the graph A represents is connected and returns False otherwise. An empty graph or a single vertex, regardless of whether there are edges back to itself or not, is connected. You will get full credit for a correct and simple implementation that uses a good answer to the previous question. There are also more complicated ways to check for graph connectedness, based on searching the graph for paths between any two vertices. This type of solution is not recommended, and will only earn half credit, assuming that it is correct and well implemented. To help you with this programming exercise, the file hw.py contains implementations of the following items: A class called sdict that is exactly the same as Python s standard dictionary class dict (more on this below), except that sdict always prints dictionary keys in sorted order. This ordering makes it easier to inspect dictionaries while debugging code. 2 To take advantage of this feature, just use sdict wherever you would otherwise use dict. Do not use dict directly, since this would make our grading much harder. A Python dictionary dict is a set of (key, value) pairs. If you are not familiar with dict, please study the tutorial at Try some of the examples there, to make sure you understand how dictionaries work and what methods they provide. The file hw.py implements adjacency matrices as dictionaries of dictionaries. Consider for instance a graph with three vertices called 'a', 'b', 'c' with two edges between 'a' and 'b' and one edge between 'a' and 'c'. The adjacency matrix of this graph is a b c a A =. b c We could enter A by hand as a dictionary of dictionaries by typing A = {'a': {'a': 0, 'b': 2, 'c': 1}, 'b': {'a': 2, 'b': 0, 'c': 0}, 'c': {'a': 1, 'b': 0, 'c': 0}} to the Python interpreter (where optional newline characters were added for readability). To access entry for vertex pair ('b', 'c') we would say A['b']['c']. So you can think of A as of a list of lists, A = [[0, 2, 1], [2, 0, 0], [1, 0, 0]] except that you can use something other than consecutive integers (single characters in the example) to index rows and columns. This will become crucial when we remove vertices from a graph, because the explicit key values 'a', 'b', 'c' keep track of which entry corresponds to which vertex as we manipulate A. To enter A as an sdict of sdicts, which will make inspecting variables easier, you would type A = sdict({'a': sdict({'a': 0, 'b': 2, 'c': 1}), 'b': sdict({'a': 2, 'b': 0, 'c': 0}), 'c': sdict({'a': 1, 'b': 0, 'c': 0})}) 2 You can also use the function adjprint provided in hw.py for prettier printing.

4 Functions def adjsum(a, B): def adjproduct(a, B): that respectively add and multiply (using the matrix product we saw in the previous problems) two adjacency matrices and return the resulting adjacency matrix. Functions def degrees(a): def nedges(a): def firstvertex(a): def oddvertices(a): def neighbors(a, u): that respectively return (i) a dictionary with the degrees of the vertices in A; (ii) the number of edges in A; (iii) the (key of the) first vertex in A (iv) a list (not a dictionary) of the (keys of the) vertices in A that have odd degree; and (v) a list of the (keys of the) vertices in A that are adjacent to vertex u. These functions are useful in answering this or subsequent questions, and also as examples of how to program with dictionaries. Refer back to the tutorial mentioned earlier or to the full Python 3 documentation for dictionaries if you have questions or doubts. (c) Write a function def iseuler(a): that returns True if the adjacency matrix A represents a graph with an Euler tour (either open or circuit), and returns False otherwise. A graph with no edges (including the empty graph) is Euler, and its Euler tour is the empty tour. A disconnected graph is not Euler. Include your code in both your.pdf and.py files, and show in your.pdf file the outputs on the test cases given in hw.py. [Hint: Remember that a characterization of these graphs was given in the March 24 lecture notes.] (d) Write functions def removeedge(a, u, v): def addedge(a, u, v): def removevertex(a, u): that respectively (i) remove one of the edges between vertices u and v; (ii) add one edge between vertices u and v; and (iii) remove vertex u. These functions do not return anything, but rather modify their first argument A. Also include an assert statement that ensures that the vertices and/or edges being passed as arguments are in A whenever appropriate. Include your code in both your.pdf and.py files, and show in your.pdf file the outputs on the test cases given in hw.py. [Hints: To remove or add the edge between vertices u and v you need to modify two entries of A, except when u and v are the same. The first two functions do not change the size of A. The third one makes A smaller by one in each dimension. To ensure that u is in A you say assert i in A.] (e) We saw both in FDM and in class that a path in a graph is specified in the form described in problem 1(b) above. For the current question, however, we specify a path as a list of edges for simplicity: (edge,..., edge). In addition, we specify each edge as a pair of vertices, listing the vertices in each pair in the order in which they are encountered in the path. For instance, referring to the graph G in problem 1, the path will be specified as (a, e 2, c, e 6, d, e 7, d) [(a, c), (c, d), (d, d)] where we use brackets rather than parentheses to remind us to use a Python list to represent the sequence. Each pair, on the other hand, is a Python tuple (use parentheses). With this representation, multiple edges between any two given vertices (including between a vertex and itself) are still allowed, but are treated as being indistinguishable from each other. For instance, if there are three edges between vertices a and b, then the edge (a, b) will appear three times in the Euler tour. [Assignment continues on the next page]

5 Algorithm 1 below is pseudocode for Fleury s algorithm. The general idea behind the algorithm is as follows: If the graph is not connected or does not satisfy the conditions for having an Euler tour (either an open Euler tour or an Euler circuit), then return the null object None. In all other cases, an Euler tour exists, and can be constructed as follows. Initialize the tour to the empty sequence. If the graph has no edges, return the tour. Otherwise, initialize a current vertex u to an appropriate vertex in the graph. If the graph admits an open Euler tour, there are two appropriate vertices one could start from (remember how you wrote your iseuler function), so just pick either one. If the graph admits an Euler circuit, you can start anywhere, so pick any vertex. Remove edges from the graph one at at time and add them to the tour as follows. As long as there are edges in the graph, For each neighbor v of the current vertex u, * Tentatively remove the edge (u, v) from the graph. * If the reduced graph is still connected, then (u, v) is a good edge to add to the tour, so stop considering other neighbors of u (that is, break out of the loop that examines the neighbors of u). * Otherwise, edge (u, v) cannot be used in the Euler path yet, so put it back into the graph. If, after examining all the neighbors v of u, no edge (u, v) was found whose removal leaves the graph connected, then it can be proven that u has exactly one neighbor v left, and the edge (u, v) is the next edge in the tour. In this case, remove both the edge (u, v) and the vertex u from the graph. Do not append (u, v) to the tour yet, you will do that next. At this point, the examination above has led to a new vertex v. Append the edge (u, v) to the tour and replace u with v. When the graph has no more edges, return the tour. Algorithm 1 Fleury s algorithm for finding an Euler tour in the graph specified by the given adjacency matrix. Input: The adjacency matrix A of a graph. Output: An Euler tour (either open or a circuit) if one exists, and the null object None otherwise. if the graph is not Euler then return None else tour [] if the graph has no edges then return tour if the graph has an open Euler tour then u either of the two appropriate starting vertices else u any vertex while there are edges in the graph do found False for v adjacent to u do Remove edge (u, v) from A if A is connected then found True break else Reinsert edge (u, v) into A end for if not found then Remove edge (u, v) from A Remove vertex u from A Append edge (u, v) to tour u v end while return tour

6 Use the functions you wrote in answer to the previous questions to write a Python function def fleury(a0): that takes the adjacency matrix A0 for a graph and uses Fleury s algorithm to return an Euler tour (either an open one or a circuit) if one exists, or the empty list otherwise. The tour is to be represented as discussed earlier. Include your code in both your.pdf and.py files, and show in your.pdf file the outputs on the test cases given in hw.py. You may have to add newlines manually to make the outputs print correctly on the page. PROGRAMMING NOTES: [Important!] The first order of business after having established that an Euler tour exists is to make a deep copy of A0 as follows: A = deepcopy(a0) and then work with A. In this way, we prevent fleury to have undesired side effects on A0. The function deepcopy ensures that the objects A and A0 and all the objects they contain in turn are unrelated to each other. This function is defined in the module copy, hence the import statement included in the file hw.py. Your code will be made mostly of calls to the functions provided and the ones you wrote earlier. The functions isconnected and iseuler you wrote are of course crucial for writing fleury. If you were not able to write those correctly, you can use ad hoc versions defined as follows to implement fleury: For each of the test cases in the assignment, determine by hand whether the function in question should return True or False. Then, make the function a long if... elif... statement that tests if A is empty and so forth, and returns the appropriate value in each case. If you adopt this solution, state so very explicitly in your file hw.pdf, and show your code in both hw.pdf and hw.py. Not doing so would lose you credit for this question too, and would be a violation of academic integrity.

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points MC 0 GRAPH THEORY 0// Solutions to HW # 0 points + XC points ) [CH] p.,..7. This problem introduces an important class of graphs called the hypercubes or k-cubes, Q, Q, Q, etc. I suggest that before you

More information

2. CONNECTIVITY Connectivity

2. CONNECTIVITY Connectivity 2. CONNECTIVITY 70 2. Connectivity 2.1. Connectivity. Definition 2.1.1. (1) A path in a graph G = (V, E) is a sequence of vertices v 0, v 1, v 2,..., v n such that {v i 1, v i } is an edge of G for i =

More information

STUDENT NUMBER: MATH Final Exam. Lakehead University. April 13, Dr. Adam Van Tuyl

STUDENT NUMBER: MATH Final Exam. Lakehead University. April 13, Dr. Adam Van Tuyl Page 1 of 13 NAME: STUDENT NUMBER: MATH 1281 - Final Exam Lakehead University April 13, 2011 Dr. Adam Van Tuyl Instructions: Answer all questions in the space provided. If you need more room, answer on

More information

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G. MAD 3105 Spring 2006 Solutions for Review for Test 2 1. Define a graph G with V (G) = {a, b, c, d, e}, E(G) = {r, s, t, u, v, w, x, y, z} and γ, the function defining the edges, is given by the table ɛ

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

CSE 21 Spring 2016 Homework 5. Instructions

CSE 21 Spring 2016 Homework 5. Instructions CSE 21 Spring 2016 Homework 5 Instructions Homework should be done in groups of one to three people. You are free to change group members at any time throughout the quarter. Problems should be solved together,

More information

CSE 21 Spring 2016 Homework 5. Instructions

CSE 21 Spring 2016 Homework 5. Instructions CSE 21 Spring 2016 Homework 5 Instructions Homework should be done in groups of one to three people. You are free to change group members at any time throughout the quarter. Problems should be solved together,

More information

Programming with Python

Programming with Python Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2

More information

Basic Combinatorics. Math 40210, Section 01 Fall Homework 4 Solutions

Basic Combinatorics. Math 40210, Section 01 Fall Homework 4 Solutions Basic Combinatorics Math 40210, Section 01 Fall 2012 Homework 4 Solutions 1.4.2 2: One possible implementation: Start with abcgfjiea From edge cd build, using previously unmarked edges: cdhlponminjkghc

More information

ASSIGNMENT 4 SOLUTIONS

ASSIGNMENT 4 SOLUTIONS MATH 71 ASSIGNMENT SOLUTIONS 1. If F : X X is a function, define f (x) to be (f f)(x), and inductively define f k (x) (f f k 1 )(x) for each integer k. (So f (x) (f f )(x) f(f(f(x))) for instance.) We

More information

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1 Graph fundamentals Bipartite graph characterization Lemma. If a graph contains an odd closed walk, then it contains an odd cycle. Proof strategy: Consider a shortest closed odd walk W. If W is not a cycle,

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #17 Loops: Break Statement (Refer Slide Time: 00:07) In this session we will see one more feature that is present

More information

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60 CPS 102: Discrete Mathematics Instructor: Bruce Maggs Quiz 3 Date: Wednesday November 30, 2011 NAME: Prob # Score Max Score 1 10 2 10 3 10 4 10 5 10 6 10 Total 60 1 Problem 1 [10 points] Find a minimum-cost

More information

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE Professor Kindred Math 104, Graph Theory Homework 2 Solutions February 7, 2013 Introduction to Graph Theory, West Section 1.2: 26, 38, 42 Section 1.3: 14, 18 Section 2.1: 26, 29, 30 DO NOT RE-DISTRIBUTE

More information

Elements of Graph Theory

Elements of Graph Theory Elements of Graph Theory Quick review of Chapters 9.1 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly skip shortest paths (Chapter 9.6), as that was covered

More information

Basics of Graph Theory

Basics of Graph Theory Basics of Graph Theory 1 Basic notions A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Simple graphs have their

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 4 Graphs Definitions Traversals Adam Smith 9/8/10 Exercise How can you simulate an array with two unbounded stacks and a small amount of memory? (Hint: think of a

More information

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL: Notes slides from before lecture CSE 21, Winter 2017, Section A00 Lecture 9 Notes Class URL: http://vlsicad.ucsd.edu/courses/cse21-w17/ Notes slides from before lecture Notes February 8 (1) HW4 is due

More information

Introduction to Computer Science and Programming for Astronomers

Introduction to Computer Science and Programming for Astronomers Introduction to Computer Science and Programming for Astronomers Lecture 3. István Szapudi Institute for Astronomy University of Hawaii January 24, 2018 Outline Reminder 1 Reminder 2 3 Where were we last

More information

Week - 01 Lecture - 04 Downloading and installing Python

Week - 01 Lecture - 04 Downloading and installing Python Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and

More information

(Refer Slide Time: 01:12)

(Refer Slide Time: 01:12) Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #22 PERL Part II We continue with our discussion on the Perl

More information

CS2 Practical 1 CS2A 22/09/2004

CS2 Practical 1 CS2A 22/09/2004 CS2 Practical 1 Basic Java Programming The purpose of this practical is to re-enforce your Java programming abilities. The practical is based on material covered in CS1. It consists of ten simple programming

More information

MATH10001 Mathematical Workshop. Graphs, Trees and Algorithms Part 2. Trees. From Trees to Prüfer Codes

MATH10001 Mathematical Workshop. Graphs, Trees and Algorithms Part 2. Trees. From Trees to Prüfer Codes MATH10001 Mathematical Workshop Graphs, Trees and Algorithms Part 2 Trees Recall that a simple graph is one without loops or multiple edges. We are interested in a special type of simple graph: A tree

More information

Packet #6: Counting & Graph Theory. Applied Discrete Mathematics

Packet #6: Counting & Graph Theory. Applied Discrete Mathematics Packet #6: Counting & Graph Theory Applied Discrete Mathematics Table of Contents Counting Pages 1-8 Graph Theory Pages 9-16 Exam Study Sheet Page 17 Counting Information I. Product Rule: A B C = A * B

More information

Introduction to Graph Theory

Introduction to Graph Theory Introduction to Graph Theory Tandy Warnow January 20, 2017 Graphs Tandy Warnow Graphs A graph G = (V, E) is an object that contains a vertex set V and an edge set E. We also write V (G) to denote the vertex

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Module 11. Directed Graphs. Contents

Module 11. Directed Graphs. Contents Module 11 Directed Graphs Contents 11.1 Basic concepts......................... 256 Underlying graph of a digraph................ 257 Out-degrees and in-degrees.................. 258 Isomorphism..........................

More information

14 More Graphs: Euler Tours and Hamilton Cycles

14 More Graphs: Euler Tours and Hamilton Cycles 14 More Graphs: Euler Tours and Hamilton Cycles 14.1 Degrees The degree of a vertex is the number of edges coming out of it. The following is sometimes called the First Theorem of Graph Theory : Lemma

More information

(Refer Slide Time 3:31)

(Refer Slide Time 3:31) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 5 Logic Simplification In the last lecture we talked about logic functions

More information

Eulerian tours. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. April 20, 2016

Eulerian tours. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck.  April 20, 2016 Eulerian tours Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ April 20, 2016 Seven Bridges of Konigsberg Is there a path that crosses each

More information

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: 1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: Input: A CNF formula ϕ with n variables x 1, x 2,..., x n. Output: True if there is an

More information

Math 15 - Spring Homework 5.2 Solutions

Math 15 - Spring Homework 5.2 Solutions Math 15 - Spring 2017 - Homework 5.2 Solutions 1. (5.2 # 14 (not assigned)) Use Prim s algorithm to construct a minimal spanning tree for the following network. Draw the minimal tree and compute its total

More information

Treewidth and graph minors

Treewidth and graph minors Treewidth and graph minors Lectures 9 and 10, December 29, 2011, January 5, 2012 We shall touch upon the theory of Graph Minors by Robertson and Seymour. This theory gives a very general condition under

More information

Problem One: A Quick Algebra Review

Problem One: A Quick Algebra Review CS103A Winter 2019 Solutions for Week One Handout 01S Problem One: A Quick Algebra Review In the first week of CS103, we'll be doing a few proofs that will require some algebraic manipulations and reasoning

More information

Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008

Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008 Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008 Ten questions, each worth the same amount. Complete six of your choice. I will only grade the first six I see. Make sure your name

More information

Math 15 - Spring Homework 2.6 Solutions 1. (2.6 # 20) The following graph has 45 vertices. In Sagemath, we can define it like so:

Math 15 - Spring Homework 2.6 Solutions 1. (2.6 # 20) The following graph has 45 vertices. In Sagemath, we can define it like so: Math 15 - Spring 2017 - Homework 2.6 Solutions 1. (2.6 # 20) The following graph has 45 vertices. In Sagemath, we can define it like so: dm = {0: [1,15], 1: [2,16,31], 2: [3,17,32], 3: [4,18,33], 4: [5,19,34],

More information

An Introduction to Graph Theory

An Introduction to Graph Theory An Introduction to Graph Theory Evelyne Smith-Roberge University of Waterloo March 22, 2017 What is a graph? Definition A graph G is: a set V (G) of objects called vertices together with: a set E(G), of

More information

Spring 2012 Homework 10

Spring 2012 Homework 10 15-150 Spring 2012 Homework 10 Out: 24 April, 2012 Due: 2 May, 2012, 0900 EST 1 Introduction This homework will give you additional practice with imperative programming in SML. It is slightly short to

More information

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18 CS 124 Quiz 2 Review 3/25/18 1 Format You will have 83 minutes to complete the exam. The exam may have true/false questions, multiple choice, example/counterexample problems, run-this-algorithm problems,

More information

CS70 - Lecture 6. Graphs: Coloring; Special Graphs. 1. Review of L5 2. Planar Five Color Theorem 3. Special Graphs:

CS70 - Lecture 6. Graphs: Coloring; Special Graphs. 1. Review of L5 2. Planar Five Color Theorem 3. Special Graphs: CS70 - Lecture 6 Graphs: Coloring; Special Graphs 1. Review of L5 2. Planar Five Color Theorem 3. Special Graphs: Trees: Three characterizations Hypercubes: Strongly connected! Administration You need

More information

Graph Theory Questions from Past Papers

Graph Theory Questions from Past Papers Graph Theory Questions from Past Papers Bilkent University, Laurence Barker, 19 October 2017 Do not forget to justify your answers in terms which could be understood by people who know the background theory

More information

Algorithms CMSC Homework set #2 due January 21, 2015

Algorithms CMSC Homework set #2 due January 21, 2015 Algorithms CMSC-27200 http://alg15.cs.uchicago.edu Homework set #2 due January 21, 2015 Read the homework instructions on the website. The instructions that follow here are only an incomplete summary.

More information

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees. Tree 1. Trees and their Properties. Spanning trees 3. Minimum Spanning Trees 4. Applications of Minimum Spanning Trees 5. Minimum Spanning Tree Algorithms 1.1 Properties of Trees: Definition: A graph G

More information

Lab 7 1 Due Thu., 6 Apr. 2017

Lab 7 1 Due Thu., 6 Apr. 2017 Lab 7 1 Due Thu., 6 Apr. 2017 CMPSC 112 Introduction to Computer Science II (Spring 2017) Prof. John Wenskovitch http://cs.allegheny.edu/~jwenskovitch/teaching/cmpsc112 Lab 7 - Using Stacks to Create a

More information

Starting Boolean Algebra

Starting Boolean Algebra Boolean Algebra March 2, 27 Diagram for FunChip2 Here is a picture of FunChip2 that we created more or less randomly in class on /25 (used in various Activities): Starting Boolean Algebra Boolean algebra

More information

(Refer Slide Time 6:48)

(Refer Slide Time 6:48) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 8 Karnaugh Map Minimization using Maxterms We have been taking about

More information

MITOCW watch?v=kz7jjltq9r4

MITOCW watch?v=kz7jjltq9r4 MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection

More information

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm Homework Sample Solution Due Date: Thursday, May 31, 11:59 pm Directions: Your solutions should be typed and submitted as a single pdf on Gradescope by the due date. L A TEX is preferred but not required.

More information

Graph Theory: Starting Out

Graph Theory: Starting Out Graph Theory: Starting Out Administrivia To read: Chapter 7, Sections 1-3 (Ensley/Crawley) Problem Set 5 sent out; due Monday 12/8 in class. There will be two review days next week (Wednesday and Friday)

More information

Ramsey s Theorem on Graphs

Ramsey s Theorem on Graphs Ramsey s Theorem on Graphs 1 Introduction Exposition by William Gasarch Imagine that you have 6 people at a party. We assume that, for every pair of them, either THEY KNOW EACH OTHER or NEITHER OF THEM

More information

Solutions to relevant spring 2000 exam problems

Solutions to relevant spring 2000 exam problems Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Graphs (MTAT , 6 EAP) Lectures: Mon 14-16, hall 404 Exercises: Wed 14-16, hall 402

Graphs (MTAT , 6 EAP) Lectures: Mon 14-16, hall 404 Exercises: Wed 14-16, hall 402 Graphs (MTAT.05.080, 6 EAP) Lectures: Mon 14-16, hall 404 Exercises: Wed 14-16, hall 402 homepage: http://courses.cs.ut.ee/2012/graafid (contains slides) For grade: Homework + three tests (during or after

More information

CSE : Python Programming

CSE : Python Programming CSE 399-004: Python Programming Lecture 11: Regular expressions April 2, 2007 http://www.seas.upenn.edu/~cse39904/ Announcements About those meeting from last week If I said I was going to look into something

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Computational Geometry: Lecture 5

Computational Geometry: Lecture 5 Computational Geometry: Lecture 5 Don Sheehy January 29, 2010 1 Degeneracy In many of the algorithms that we have discussed so far, we have run into problems when that input is somehow troublesome. For

More information

HMC CS 158, Fall 2017 Problem Set 3 Programming: Regularized Polynomial Regression

HMC CS 158, Fall 2017 Problem Set 3 Programming: Regularized Polynomial Regression HMC CS 158, Fall 2017 Problem Set 3 Programming: Regularized Polynomial Regression Goals: To open up the black-box of scikit-learn and implement regression models. To investigate how adding polynomial

More information

Dr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions.

Dr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions. 1.0 Expressions Dr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions. Numbers are examples of primitive expressions, meaning

More information

MA 111 Review for Exam 3

MA 111 Review for Exam 3 MA 111 Review for Exam 3 Exam 3 (given in class on Tuesday, March 27, 2012) will cover Chapter 5. You should: know what a graph is and how to use graphs to model geographic relationships. know how to describe

More information

SOFTWARE ENGINEERING DESIGN I

SOFTWARE ENGINEERING DESIGN I 2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique

More information

Privacy and Security in Online Social Networks Department of Computer Science and Engineering Indian Institute of Technology, Madras

Privacy and Security in Online Social Networks Department of Computer Science and Engineering Indian Institute of Technology, Madras Privacy and Security in Online Social Networks Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 08 Tutorial 2, Part 2, Facebook API (Refer Slide Time: 00:12)

More information

Bases of topologies. 1 Motivation

Bases of topologies. 1 Motivation Bases of topologies 1 Motivation In the previous section we saw some examples of topologies. We described each of them by explicitly specifying all of the open sets in each one. This is not be a feasible

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

More information

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs CS 70 Discrete Mathematics for CS Spring 2008 David Wagner Note 13 An Introduction to Graphs Formulating a simple, precise specification of a computational problem is often a prerequisite to writing a

More information

Lecture Notes on Contracts

Lecture Notes on Contracts Lecture Notes on Contracts 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 30, 2012 1 Introduction For an overview the course goals and the mechanics and schedule of the course,

More information

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

Statistics Case Study 2000 M. J. Clancy and M. C. Linn Statistics Case Study 2000 M. J. Clancy and M. C. Linn Problem Write and test functions to compute the following statistics for a nonempty list of numeric values: The mean, or average value, is computed

More information

GRAPH THEORY: AN INTRODUCTION

GRAPH THEORY: AN INTRODUCTION GRAPH THEORY: AN INTRODUCTION BEGINNERS 3/4/2018 1. GRAPHS AND THEIR PROPERTIES A graph G consists of two sets: a set of vertices V, and a set of edges E. A vertex is simply a labeled point. An edge is

More information

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1 CS 70 Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1 PRINT Your Name:, (last) SIGN Your Name: (first) PRINT Your Student ID: CIRCLE your exam room: 1 Pimentel 141 Mccone

More information

Definition 1.1. A matching M in a graph G is called maximal if there is no matching M in G so that M M.

Definition 1.1. A matching M in a graph G is called maximal if there is no matching M in G so that M M. 1 Matchings Before, we defined a matching as a set of edges no two of which share an end in common. Suppose that we have a set of jobs and people and we want to match as many jobs to people as we can.

More information

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

More information

Graphs. The ultimate data structure. graphs 1

Graphs. The ultimate data structure. graphs 1 Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely

More information

Week 8: The fundamentals of graph theory; Planar Graphs 25 and 27 October, 2017

Week 8: The fundamentals of graph theory; Planar Graphs 25 and 27 October, 2017 (1/25) MA284 : Discrete Mathematics Week 8: The fundamentals of graph theory; Planar Graphs 25 and 27 October, 2017 1 Definitions 1. A graph 2. Paths and connected graphs 3. Complete graphs 4. Vertex degree

More information

Chapter 11: Graphs and Trees. March 23, 2008

Chapter 11: Graphs and Trees. March 23, 2008 Chapter 11: Graphs and Trees March 23, 2008 Outline 1 11.1 Graphs: An Introduction 2 11.2 Paths and Circuits 3 11.3 Matrix Representations of Graphs 4 11.5 Trees Graphs: Basic Definitions Informally, a

More information

Notes for Recitation 8

Notes for Recitation 8 6.04/8.06J Mathematics for Computer Science October 5, 00 Tom Leighton and Marten van Dijk Notes for Recitation 8 Build-up error Recall a graph is connected iff there is a path between every pair of its

More information

Discrete Mathematics and Probability Theory Summer 2016 Dinh, Psomas, and Ye HW 2

Discrete Mathematics and Probability Theory Summer 2016 Dinh, Psomas, and Ye HW 2 CS 70 Discrete Mathematics and Probability Theory Summer 2016 Dinh, Psomas, and Ye HW 2 Due Tuesday July 5 at 1:59PM 1. (8 points: 3/5) Hit or miss For each of the claims and proofs below, state whether

More information

Solutions to Homework 10

Solutions to Homework 10 CS/Math 240: Intro to Discrete Math 5/3/20 Instructor: Dieter van Melkebeek Solutions to Homework 0 Problem There were five different languages in Problem 4 of Homework 9. The Language D 0 Recall that

More information

Math 485, Graph Theory: Homework #3

Math 485, Graph Theory: Homework #3 Math 485, Graph Theory: Homework #3 Stephen G Simpson Due Monday, October 26, 2009 The assignment consists of Exercises 2129, 2135, 2137, 2218, 238, 2310, 2313, 2314, 2315 in the West textbook, plus the

More information

11.2 Eulerian Trails

11.2 Eulerian Trails 11.2 Eulerian Trails K.. onigsberg, 1736 Graph Representation A B C D Do You Remember... Definition A u v trail is a u v walk where no edge is repeated. Do You Remember... Definition A u v trail is a u

More information

Building a system for symbolic differentiation

Building a system for symbolic differentiation Computer Science 21b Structure and Interpretation of Computer Programs Building a system for symbolic differentiation Selectors, constructors and predicates: (constant? e) Is e a constant? (variable? e)

More information

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur Lecture : Graphs Rajat Mittal IIT Kanpur Combinatorial graphs provide a natural way to model connections between different objects. They are very useful in depicting communication networks, social networks

More information

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

More information

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7 CS 70 Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7 An Introduction to Graphs A few centuries ago, residents of the city of Königsberg, Prussia were interested in a certain problem.

More information

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

More information

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE Professor Kindred Math 104, Graph Theory Homework 3 Solutions February 14, 2013 Introduction to Graph Theory, West Section 2.1: 37, 62 Section 2.2: 6, 7, 15 Section 2.3: 7, 10, 14 DO NOT RE-DISTRIBUTE

More information

15-780: Problem Set #4

15-780: Problem Set #4 15-780: Problem Set #4 April 21, 2014 1. Image convolution [10 pts] In this question you will examine a basic property of discrete image convolution. Recall that convolving an m n image J R m n with a

More information

CS195H Homework 1 Grid homotopies and free groups. Due: February 5, 2015, before class

CS195H Homework 1 Grid homotopies and free groups. Due: February 5, 2015, before class CS195H Homework 1 Grid homotopies and free groups This second homework is almost all about grid homotopies and grid curves, but with a little math in the middle. This homework, last year, took people about

More information

CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism

CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism CHAPTER 2 Graphs 1. Introduction to Graphs and Graph Isomorphism 1.1. The Graph Menagerie. Definition 1.1.1. A simple graph G = (V, E) consists of a set V of vertices and a set E of edges, represented

More information

6.001 Notes: Section 4.1

6.001 Notes: Section 4.1 6.001 Notes: Section 4.1 Slide 4.1.1 In this lecture, we are going to take a careful look at the kinds of procedures we can build. We will first go back to look very carefully at the substitution model,

More information

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department CS473-Algorithms I Lecture 3-A Graphs Graphs A directed graph (or digraph) G is a pair (V, E), where V is a finite set, and E is a binary relation on V The set V: Vertex set of G The set E: Edge set of

More information

Homework #3 (Search) Out: 1/24/11 Due: 2/1/11 (at noon)

Homework #3 (Search) Out: 1/24/11 Due: 2/1/11 (at noon) CS121 Introduction to Artificial Intelligence Winter 2011 Homework #3 (Search) Out: 1/24/11 Due: 2/1/11 (at noon) How to complete this HW: First copy this file; then type your answers in the file immediately

More information

CSE 101 Homework 5. Winter 2015

CSE 101 Homework 5. Winter 2015 CSE 0 Homework 5 Winter 205 This homework is due Friday March 6th at the start of class. Remember to justify your work even if the problem does not explicitly say so. Writing your solutions in L A TEXis

More information

Eulerian Paths and Cycles

Eulerian Paths and Cycles Eulerian Paths and Cycles What is a Eulerian Path Given an graph. Find a path which uses every edge exactly once. This path is called an Eulerian Path. If the path begins and ends at the same vertex, it

More information

CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points

CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points Files to submit: 1. HW4.py This is a PAIR PROGRAMMING Assignment: Work with your partner!

More information

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4) S-72.2420/T-79.5203 Basic Concepts 1 S-72.2420/T-79.5203 Basic Concepts 3 Characterizing Graphs (1) Characterizing Graphs (3) Characterizing a class G by a condition P means proving the equivalence G G

More information

Notebook Assignments

Notebook Assignments Notebook Assignments These six assignments are a notebook using techniques from class in the single concrete context of graph theory. This is supplemental to your usual assignments, and is designed for

More information

Lecture 3 - Template and Vectors

Lecture 3 - Template and Vectors Lecture - Template and Vectors Homework Format and Template: We ll each develop a simple template to use to start any new homework. The idea of a template is to layout the basic structure of what goes

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #06 Loops: Operators

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #06 Loops: Operators Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #06 Loops: Operators We have seen comparison operators, like less then, equal to, less than or equal. to and

More information

Midterm I Practice Problems

Midterm I Practice Problems 15-112 Midterm I Practice Problems Name: Section: andrewid: This PRACTICE midterm is not meant to be a perfect representation of the upcoming midterm! You are responsible for knowing all material covered

More information