sol13 - CS577 Spring09: Solution to Homework 13∗ 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS577 Spring09: Solution to Homework 13∗ 1 Butterfly Species Consistency This is an extension to the bipartiteness testing problem. Consider each butterfly specimen as a node in an undirected graph. The edges are defined by the given set of judgements, labeled “+1” (same) or “-1” (different). Now the “consistency” question becomes: is there a partition of V into A and B, s.t. all “+1” edges connect nodes from the same group while all “-1” edges connect one node from A and the other from B. We can test this extended “bipartiteness” property using binary coloring. Algorithm 1 Extended Bipartiteness Testing 1: INPUT: An undirected graph G = (V, E) where V = {1, 2, · · · , n} and E is represented by adjacency lists N (v) = {x|(v, x) ∈ E or (x, v) ∈ E} for v ∈ V . Each node v ∈ V has a label v.color ∈ {0, 9, −9} initialized to be 0. Each edge e ∈ E has a label e.label ∈ {+1, −1} as defined by the set of judgements. 2: OUTPUT: True iff G passes the test 3: DATA STRUCTURES: • Array visited[1 . . . n], all elements initially f alse 4: 5: 6: 7: 8: 9: 10: 11: while there exists some node u such that visited[u] = f alse do u.color ← 9 result ← BinColor(u) if result! = T rue then return F alse end if end while return T rue ∗ Please send any questions to Jason fniu@wisc.edu 1 Algorithm 2 BinColor(x) 1: visited[x] ← true 2: for all v ∈ N (x) and the corresponding edge e do 3: if visited[v] = f alse then 4: v.color ← x.color × e.label 5: result ← BinColor(v) 6: if result! = T rue then 7: return F alse 8: end if 9: else 10: if v.color! = x.color × e.label then 11: return F alse 12: end if 13: end if 14: end for 15: return T rue 2 ...
View Full Document

This note was uploaded on 10/02/2009 for the course CS 577 taught by Professor Nabil during the Spring '09 term at Lahore University of Management Sciences.

Page1 / 2

sol13 - CS577 Spring09: Solution to Homework 13∗ 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online