Revised constraints and algorithm. Added comment denoting key/value for each dictionary in the code section.

This commit is contained in:
Donne Martin
2015-08-04 08:09:16 -04:00
parent 91dc014573
commit 9dc4116256
6 changed files with 349 additions and 16 deletions

View File

@@ -33,12 +33,10 @@
"source": [
"## Constraints\n",
"\n",
"* I plan to use a Node and Graph class. \n",
" * Node will keep track of its id, visit state, and connections. \n",
" * Connections will be a dictionary with the key = node id and value being the edge weight\n",
" * Graph will hold all of the nodes and have functions to add nodes and edges. \n",
" * Is this in line with what you have in mind?\n",
" * Yes"
"* Is the graph directed?\n",
" * Yes\n",
"* Do the edges have weights?\n",
" * Yes"
]
},
{
@@ -72,7 +70,23 @@
"source": [
"## Algorithm\n",
"\n",
"### add_node\n",
"### Node\n",
"\n",
"Node will keep track of its:\n",
"* id\n",
"* visit state\n",
"* connections\n",
" * key: node\n",
" * value: weight\n",
"\n",
"### Graph\n",
"\n",
"Graph will keep track of its:\n",
"* Nodes\n",
" * key: node id\n",
" * value: node\n",
"\n",
"#### add_node\n",
"\n",
"* Create a node with the input id\n",
"* Add the newly created node to the list of nodes\n",
@@ -81,7 +95,7 @@
"* Time: O(1)\n",
"* Space: O(1)\n",
"\n",
"### add_edge\n",
"#### add_edge\n",
"\n",
"* If the source node is not in the list of nodes, add it\n",
"* If the dest node is not in the list of nodes, add it\n",
@@ -122,13 +136,13 @@
" def __init__(self, id):\n",
" self.id = id\n",
" self.state = State.unvisited\n",
" self.connections = {}\n",
" self.connections = {} # key = node, val = weight\n",
"\n",
"\n",
"class Graph:\n",
"\n",
" def __init__(self):\n",
" self.nodes = {}\n",
" self.nodes = {} # key = node id, val = node\n",
"\n",
" def add_node(self, id):\n",
" node = Node(id)\n",