------------------------------------------------------------------------------ Mohamed G. Gouda CS 311 Fall 2015 Homework 2 ------------------------------------------------------------------------------ 1. (5 points) Verify that the following program specification holds: (T) if x<9 then y:=0 else y:=1 fi (Q(x,y)) where Q(x,y) is the predicate (x<9 and y=0) or (x>=9 and y=1) Hint: You can use the following hints in proving predicates: {T => 0=0} {T => 1=1} {P => (P or F)} {F => (P and F)} {F => 0=1} {F => 1=0} ------------------------------------------------------------------------------- 2. (2.5 points) Let G=(V,E) be any graph whose chromatic number is 3 and let u and v be any two non-neighboring vertices in G. Also let G' be the graph that results from adding an edge between vertices u and v in graph G. What are the possible values of the chromatic number of graph G'? Explain your answer. ------------------------------------------------------------------------------- 3. (2.5 points) Let G=(V,E) be a bipartite graph and let u and v be two vertices in graph G where deg(u) is 0. Is the graph that results from adding an edge between the two vertices u and v bipartite? Explain your answer. ------------------------------------------------------------------------------- Solutions: ------------------------------------------------------------------------------- 1. We need to verify that the following two program specifications hold: (T and x<9) y:=0 (Q(x,y)) (T and x>=9) y:=1 (Q(x,y)) Thus we need to prove the following two predicates: (All x,y, (T and x<9) => ((x<9 and 0=0) or (x>=9 and 0=1)) ) (All x,y, (T and x>=9) => ((x<9 and 1=0) or (x>=9 and 1=1)) ) Proof of the First Predicate: T and x<9 => {T => 0=0} x<9 and 0=0 => {P => (P or F)} (x<9 and 0=0) or F => {F => (P and F)} (x<9 and 0=0) or (x>=9 and F) => {F => 0=1} (x<9 and 0=0) or (x>=9 and 0=1) Proof of the Second Predicate: T and x>=9 => {T => 1=1} x>=9 and 1=1 => {P => (P or F)} (x>=9 and 1=1) or F => {F => (P and F)} (x>=9 and 1=1) or (x<9 and F) => {F => 1=0} (x>=9 and 1=1) or (x<9 and 1=0) ------------------------------------------------------------------------------- 2. The possible values of the chromatic number of G' is 3 or 4. Let C1, C2, ..., Cm be all the colorings of G'that use 3 colors. If in one of these colorings, say Ci, the two vertices u and v are assigned distinct colors, then adding an edge between u and v does not require to use more than the three original colors. In this case, the chromatic number of G' is 3. Otherwise an additional fourth color needs to be used to color vertex u. In this case, the chromatic number of G' is 4. --------------------------------------------------------------------------------- 3. The resulting graph is guaranteed to be bipartite. Because the original graph G is bipartite, the set V of the vertices of G can be partitioned into two subsets V1 V2 such that the two ends of every edge in G belong to distinct subsets. Moreover, because the degree of vertex u is 0, vertex u can be chosen to belong to either one of the two subsets. Therefore, vertices u and v can be chosen to belong to distinct subsets and the resulting graph is bipartite. ---------------------------------------------------------------------------------