Main.Assignment2 History
Hide minor edits - Show changes to output
Changed line 20 from:
The return value of your @@has_cycle@@ function should be a Boolean value that indicates if the given graph is bipartite or not.
to:
The return value of your @@has_cycle@@ function should be a Boolean value that indicates if the given graph has a cycle or not.
Changed lines 1-7 from:
!!Programming Assignment 2 - Testing if a graph is bipartite
!!!Due: Feb 20th at5pm.
In this assignment you will program a graph class and a method for testing whether a given graphis bipartite.
Use the adjacency list representation to implement the graph class and BFS to implement a function called @@is_bipartite@@. Your function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part. You may use the python Queue class.
!!!Due: Feb 20th at
In this assignment you will program a graph class and a method for testing whether a given graph
to:
!!Programming Assignment 2 - Testing for cycles
!!!Due: Oct 1st at 5pm.
In this assignment you will program a graph class and a method for testing whether a given undirected graph has a cycle.
Your algorithm should be based on BFS; use the adjacency list representation to implement the graph class and should run in O(m + n) time, where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part. You may use the python Queue class.
!!!Due: Oct 1st at 5pm.
In this assignment you will program a graph class and a method for testing whether a given undirected graph has a cycle.
Your algorithm should be based on BFS; use the adjacency list representation to implement the graph class and should run in O(m + n) time, where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part. You may use the python Queue class.
Changed lines 14-17 from:
to:
# loading the graph
has_cycle = HW2.has_cycle(g)
# testing whether it has a cycle
# your function should return a Boolean value
has_cycle = HW2.has_cycle(g)
# testing whether it has a cycle
# your function should return a Boolean value
Changed lines 20-21 from:
The return value of your @@is_bipartite@@ function should be a Boolean value that indicates if the given graph is bipartite or not.
to:
The return value of your @@has_cycle@@ function should be a Boolean value that indicates if the given graph is bipartite or not.
Changed lines 32-70 from:
Here's some code to get you started:
(:source lang=python:)
import os
from Queue import Queue
class graph (object) :
"""
A class that represents an undirected graph as an adjacency list
"""
pass
def is_bipartite(g)
pass
def load_dot(file_name) :
g = graph()
if not os.path.isfile(file_name) :
raise ValueError, 'file does not exist at ' + file_name
file_handle = open(file_name)
file_handle.readline()
for line in file_handle :
if line.find(';') > 0 :
tokens = line[:line.find(';')].split('--')
else :
tokens = line.split('--')
if len(tokens) < 2 : continue
node1 = tokens[0].strip()
node2 = tokens[1].strip()
g.add_edge(node1, node2)
return g
if __name__ == '__main__' :
g = load_dot('test.dot')
print 'the graph is bipartite?', is_bipartite(g)
(:sourceend:)
to:
Note that node names can be longer than a single character.
Changed line 6 from:
Use the adjacency list representation to implement the graph class and BFS to implement a function called @@is_bipartite@@. Your function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part. You may also use the python Queue class.
to:
Use the adjacency list representation to implement the graph class and BFS to implement a function called @@is_bipartite@@. Your function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part. You may use the python Queue class.
Changed line 14 from:
test_result = HW2.is_bipartite(gr)
to:
test_result = HW2.is_bipartite(g)
Changed line 65 from:
print 'the graph is bipartite?', is_bipartite(graph)
to:
print 'the graph is bipartite?', is_bipartite(g)
Changed lines 10-14 from:
@@
@@
to:
(:source lang=python:)
import HW2
g = HW2.load_dot(file_name)
test_result = HW2.is_bipartite(gr)
(:sourceend:)
import HW2
g = HW2.load_dot(file_name)
test_result = HW2.is_bipartite(gr)
(:sourceend:)
Added lines 21-27:
graph G {
n1 -- n2
n3 -- n4
n3 -- n2
n5 -- n2
}
Changed lines 1-6 from:
!!Programming Assignment 2 - Graphs and Connected Components
!!!Due: Feb 18th at 5pm.
In this assignment you will program a graph class and a method forcomputing its connected components. Use the adjacency list representation to implement the graph class and BFS to implement the connected components method. Your connected components function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part, although that is allowed to help you construct the adjacency list (useful for mapping node IDs to indices). You may also use the python Queue class.
In this assignment you will program a graph class and a method for
to:
!!Programming Assignment 2 - Testing if a graph is bipartite
!!!Due: Feb 20th at 5pm.
In this assignment you will program a graph class and a method for testing whether a given graph is bipartite.
Use the adjacency list representation to implement the graph class and BFS to implement a function called @@is_bipartite@@. Your function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part. You may also use the python Queue class.
!!!Due: Feb 20th at 5pm.
In this assignment you will program a graph class and a method for testing whether a given graph is bipartite.
Use the adjacency list representation to implement the graph class and BFS to implement a function called @@is_bipartite@@. Your function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part. You may also use the python Queue class.
Changed lines 13-24 from:
The return value of your @@
The graph is loaded from
Here's how part of it looks like:
%width=300px%http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
to:
@@test_result = HW2.is_bipartite(gr)@@
The return value of your @@is_bipartite@@ function should be a Boolean value that indicates if the given graph is bipartite or not.
The graph is loaded from a file in @@dot@@ format.
Here's an example of a graph in this format:
Below we provide a function that loads a graph in @@dot@@ format which will work for the limited subset of @@dot@@ markup that we will use. Make sure your graph class implements the interface required for it to work.
The return value of your @@is_bipartite@@ function should be a Boolean value that indicates if the given graph is bipartite or not.
The graph is loaded from a file in @@dot@@ format.
Here's an example of a graph in this format:
Below we provide a function that loads a graph in @@dot@@ format which will work for the limited subset of @@dot@@ markup that we will use. Make sure your graph class implements the interface required for it to work.
Deleted lines 30-52:
"""
Construct an empty graph
"""
pass
def __len__(self) :
"""
Returns the number of nodes in the graph
"""
pass
def add_edge(self, node1, node2) :
"""
Add an edge to the graph between
"""
pass
def connected_components(g) :
"""
A method for computing the connected components of a graph
"""
Added lines 33-35:
def is_bipartite(g)
pass
pass
Changed line 56 from:
to:
print 'the graph is bipartite?', is_bipartite(graph)
Changed line 17 from:
@@\[\['1','2','3','4','5','7','8','6'],['9','10'],['11','12','13'\]\]@@
to:
@@[ ['1','2','3','4','5','7','8','6'],['9','10'],['11','12','13'] ]@@
Changed line 17 from:
@@[['1','2','3','4','5','7','8','6'],['9','10'],['11','12','13']]@@
to:
@@\[\['1','2','3','4','5','7','8','6'],['9','10'],['11','12','13'\]\]@@
Changed lines 17-19 from:
@@
[['1','2','3','4','5','7','8','6'],['9','10'],['11','12','13']]
@@
@@
to:
@@[['1','2','3','4','5','7','8','6'],['9','10'],['11','12','13']]@@
Added lines 14-19:
The return value of your @@connected_components@@ function should be a list whose elements are the connected components of the graph. Running it on the graph given in Figure 3.2 in the textbook should return:
@@
[['1','2','3','4','5','7','8','6'],['9','10'],['11','12','13']]
@@
Changed line 18 from:
%width=30px%http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
to:
%width=300px%http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
Changed lines 18-21 from:
%block rframe width=30px%http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
%%
, and its structure should follow the skeleton code below. In addition to the @@Heap@@ class, your module should include a method called @@heap_sort@@ that sorts a list using the heap-sort algorithm. Some of comments are place-holders for your own comments.
, and its structure should follow the skeleton code below. In addition to the @@Heap@@ class, your module should include a method called @@heap_sort@@ that sorts a list using the heap-sort algorithm. Some of comments are place-holders for your own comments.
to:
%width=30px%http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
Here's some code to get you started:
Here's some code to get you started:
Changed lines 17-18 from:
%block rframe width=300px%
http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
to:
%block rframe width=30px%http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
Added line 17:
%block rframe width=300px%
Changed line 19 from:
to:
%%
Changed lines 16-19 from:
Here's how it looks like:
[[Path:../../pdfs/facebook_graph.gif]]
to:
Here's how part of it looks like:
http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
http://www.cs.colostate.edu/~asa/courses/cs320/spr11/pdfs/facebook_graph.gif
Changed lines 76-77 from:
(:sourceend:)
to:
(:sourceend:)
Changed lines 1-2 from:
!!Programming Assignment 2 Graphs and Connected Components
to:
!!Programming Assignment 2 - Graphs and Connected Components
Changed lines 15-16 from:
The graph is loaded from a file in @@dot@@ format. An example graph is provided [[Path:../../data/facebook_graph.dot|here]], and the provided function should work for the limited subset of @@dot@@ markup that we will use. Make sure your graph class implements the interface required for it to work. The graph we provide you is a small sample of a facebook friendship graph (this is a small sample of another sample that is available [[here]].
to:
The graph is loaded from a file in @@dot@@ format. An example graph is provided [[Path:../../data/facebook_graph.dot|here]], and the provided function should work for the limited subset of @@dot@@ markup that we will use. Make sure your graph class implements the interface required for it to work. The graph we provide you is a small sample of a facebook friendship graph (this is a small sample of another sample that is available [[http://odysseas.calit2.uci.edu/wiki/doku.php?id=public:online_social_networks#datasets|here]].
Here's how it looks like:
[[Path:../../pdfs/facebook_graph.gif]]
Here's how it looks like:
[[Path:../../pdfs/facebook_graph.gif]]
Changed lines 23-74 from:
to:
from Queue import Queue
class graph (object) :
"""
A class that represents an undirected graph as an adjacency list
"""
def __init__(self) :
"""
Construct an empty graph
"""
pass
def __len__(self) :
"""
Returns the number of nodes in the graph
"""
pass
def add_edge(self, node1, node2) :
"""
Add an edge to the graph between
"""
pass
def connected_components(g) :
"""
A method for computing the connected components of a graph
"""
pass
def load_dot(file_name) :
g = graph()
if not os.path.isfile(file_name) :
raise ValueError, 'file does not exist at ' + file_name
file_handle = open(file_name)
file_handle.readline()
for line in file_handle :
if line.find(';') > 0 :
tokens = line[:line.find(';')].split('--')
else :
tokens = line.split('--')
if len(tokens) < 2 : continue
node1 = tokens[0].strip()
node2 = tokens[1].strip()
g.add_edge(node1, node2)
return g
if __name__ == '__main__' :
g = load_dot('test.dot')
components = connected_components(g)
class graph (object) :
"""
A class that represents an undirected graph as an adjacency list
"""
def __init__(self) :
"""
Construct an empty graph
"""
pass
def __len__(self) :
"""
Returns the number of nodes in the graph
"""
pass
def add_edge(self, node1, node2) :
"""
Add an edge to the graph between
"""
pass
def connected_components(g) :
"""
A method for computing the connected components of a graph
"""
pass
def load_dot(file_name) :
g = graph()
if not os.path.isfile(file_name) :
raise ValueError, 'file does not exist at ' + file_name
file_handle = open(file_name)
file_handle.readline()
for line in file_handle :
if line.find(';') > 0 :
tokens = line[:line.find(';')].split('--')
else :
tokens = line.split('--')
if len(tokens) < 2 : continue
node1 = tokens[0].strip()
node2 = tokens[1].strip()
g.add_edge(node1, node2)
return g
if __name__ == '__main__' :
g = load_dot('test.dot')
components = connected_components(g)
Added lines 1-22:
!!Programming Assignment 2 Graphs and Connected Components
!!!Due: Feb 18th at 5pm.
In this assignment you will program a graph class and a method for computing its connected components. Use the adjacency list representation to implement the graph class and BFS to implement the connected components method. Your connected components function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part, although that is allowed to help you construct the adjacency list (useful for mapping node IDs to indices). You may also use the python Queue class.
Your code should be structured as a single python file called @@HW2.py@@. We will call to test your code as:
@@import HW2@@
@@g = HW2.load_dot(file_name)@@
@@connected_components = HW2.connected_components(g)@@
The graph is loaded from a file in @@dot@@ format. An example graph is provided [[Path:../../data/facebook_graph.dot|here]], and the provided function should work for the limited subset of @@dot@@ markup that we will use. Make sure your graph class implements the interface required for it to work. The graph we provide you is a small sample of a facebook friendship graph (this is a small sample of another sample that is available [[here]].
, and its structure should follow the skeleton code below. In addition to the @@Heap@@ class, your module should include a method called @@heap_sort@@ that sorts a list using the heap-sort algorithm. Some of comments are place-holders for your own comments.
(:source lang=python:)
(:sourceend:)
!!!Due: Feb 18th at 5pm.
In this assignment you will program a graph class and a method for computing its connected components. Use the adjacency list representation to implement the graph class and BFS to implement the connected components method. Your connected components function should run in O(m + n) time where m is the number of edges of the graph and n is the number of nodes. We will look at the code to verify that your implementation satisfies this bound. This means that you can't use python dictionaries in the graph traversal part, although that is allowed to help you construct the adjacency list (useful for mapping node IDs to indices). You may also use the python Queue class.
Your code should be structured as a single python file called @@HW2.py@@. We will call to test your code as:
@@import HW2@@
@@g = HW2.load_dot(file_name)@@
@@connected_components = HW2.connected_components(g)@@
The graph is loaded from a file in @@dot@@ format. An example graph is provided [[Path:../../data/facebook_graph.dot|here]], and the provided function should work for the limited subset of @@dot@@ markup that we will use. Make sure your graph class implements the interface required for it to work. The graph we provide you is a small sample of a facebook friendship graph (this is a small sample of another sample that is available [[here]].
, and its structure should follow the skeleton code below. In addition to the @@Heap@@ class, your module should include a method called @@heap_sort@@ that sorts a list using the heap-sort algorithm. Some of comments are place-holders for your own comments.
(:source lang=python:)
(:sourceend:)
