%$6'#%( # 
% %!#
$%'!' '% %
#!$,'%
QKKKM N L
-'#%#/5 ',%
1*)LMM
QKKKM N M
#!$,'(#  # 
.*.(/0#0#',3/3)./0)0#5*.')/*'4
,.1',.*'(/
5#*55*3'(,0#$)*.(',.*'(*
#**/$)5#00*0$)0*)*,1($81*),.*'(
)#*55*3'/$),.*.(0*/*'4$0
*55)00*'**0'//*(*'/''.,#/
QKKKM N N
0*)*/E4.1/F
W $#0#4,.*,.1///*$05$0#0#(
0*/E./F#*)/$/1)*,$.*)*/
W )$.0E.,#F
W $.0E$.,#F
W *3.E,.)0F)/1)1*)E#$'F)*/
W )5$#0*.5$#0
'5 %$2
QKKKM N O
'5 %$2
0*)*/E4.1/F
W $#0#4,.*,.1///*$05$0#0#(
0*/E./F#*)/$/1)*,$.*)*/
W )$.0E.,#F
W $.0E$.,#F
W *3.E,.)0F)/1)1*)E#$'F)*/
W )5$#0*.5$#0
QKKKM N P
LK
LM
N
/ %$2
*,03.3/3'.'1*)/#$,/(*))11/
W $''$)/05).$/) *)*)
W *50#0*(/$)(*'3'..'00**))*0#.
W )/0.'.'1*)/#$,/
QKKKM N Q
%4 !$#%''$ 
/,$'$)*$.0.,#$)5#$#)7,$.*
)*/$/*))07/$)',0#
W ''0#/.#0./53/0*/*'4),/
,.*'(
QKKKM N R
/ %$%#,
*.'$/3''*)05*.//*).'1*)/#$,/
W *(,30.)05*./
W .)/,*.01*))05*./
W $))$')05*./
W 5.*.50.)05*./
W *'$1')05*./
W .$($)')05*./
W *$')05*./
W 0

QKKKM N S
)'7/$/*@$8.*8A=
C/$8*)*. 0/)3(.*/)/
$)5#$##.0./#./$'*3
C*'*.*'3/0./. 0/)03.'
$)0.1*)/5$0##*0#.30)*0
*0#./
Wizard of Oz dialogue map © Mapr.com. All rights reserved. This content is
excluded from our Creative Commons license. For more information,
see https://ocw.mit.edu/help/faq-fair-use.
/ %$%#,
5$''/0#0)*0*)'7*.,#/,03.
.'1*)/#$,/$)*))0)05*./*'()0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(,%$
3$'$).,#/
W */
W /
W 10#$)0*0#.0*(.,#/
/$).,#/
W .#$)*.,0#/05))*/
W .#$)*.*,1(',0#/05))*/
QKKKM N LO
#
class Node(object):
def __init__(self, name):
Assumes name is a string
self.name = name
def getName(self):
return self.name
def __str__(self):
return self.name
QKKKM N LP
class Edge(object):
def __init__(self, src, dest):
Assumes src and dest are nodes
self.src = src
self.dest = dest
def getSource(self):
return self.src
def getDestination(self):
return self.dest
def __str__(self):
return self.src.getName() + '-’
+ self.dest.getName()
QKKKM N LQ
#!!#$%'(##%$
$.,#$/$.0.,#
W /,//$)*)$.1*)*)'7
%)7(0.$6
W *5/=/*3.)*/
W *'3()/=/1)1*))*/
W ''G/HUL$0#.$/).*(/0*
UK*0#.5$/
W *00#0$)$.,#(0.$6$/ /7((0.$
%)7'$/0
W //*$05$0##)*'$/0*/1)1*))*/
QKKKM N LR
%$3$%'9
class Digraph(object):
edges is a dict mapping each node to a list of
its children”
def __init__(self):
self.edges = {}
def addNode(self, node):
if node in self.edges:
raise ValueError('Duplicate node')
else:
self.edges[node] = []
def addEdge(self, edge):
src = edge.getSource()
dest = edge.getDestination()
if not (src in self.edges and dest in self.edges):
raise ValueError('Node not in graph')
self.edges[src].append(dest)
QKKKM N LS
mappi
ing each
h nod
de list
%$3$%':
def childrenOf(self, node):
return self.edges[node]
def hasNode(self, node):
return node in self.edges
def getNode(self, name):
for n in self.edges:
if n.getName() == name:
return n
raise NameError(name)
def __str__(self):
result = ''
for src in self.edges:
for dest in self.edges[src]:
result = result + src.getName() + '-'
+ dest.getName() + 'n'
return result[:-1] #omit final newline
QKKKM N LT
%$
class Graph(Digraph):
def addEdge(self, edge):
Digraph.addEdge(self, edge)
rev = Edge(edge.getDestination(), edge.getSource())
Digraph.addEdge(self, rev)
.,#*/)*0#4$.1*)'$07//*$05$0#)
W /''*5,//$)$0#.$.1*)
#7$/.,#/3'//*$.,#;
((.0#/3/1031*).3';
W '$)0*5*./*..0'73/$))$)/0)*0#
/3,.07,$0/#*3''/*5*.*..0'75#))$)/0)*
0#/307,$//3/1030*.0#$)/0)*0#/3,.07,
)7,.*.(0#05*./5$0#$.,#5$'''/*5*.5$0#
.,#E30)*0F
QKKKM N MK
%$$(!0(#%# !
#*.0/0,0#.*()L0*)M
W #*.0/0/-3)*//3#0#0
W *3.)**./0$/)L
W /1)1*)*'/0$/)M
W *./L)M$)0#/-3)$M*''*5/L$)0#
/-3)0#/*3.*M$/0#/1)1*)*L
#*.0/05$#0,0#
W $)$($80#/3(*0#5$#0/*0#/$)0#,0#
QKKKM N ML
#!#%'''%# !
$)$).*30.*(*)$070*)*0#.
/$)$)*((3)$1*))05*./
$)$),0#*.(*'3'0#.*3##($'
'7.$)0#
?
QKKKM N MM
,PDJHV‹VRXUFHVXQNQRZQ$OOULJKWVUHVHUYHG7KLVFRQWHQWLVH[FOXGHGIURPRXUUHDWLYH
RPPRQVOLFHQVH)RUPRUHLQIRUPDWLRQVHHKWWSVRFZPLWHGXKHOSIDTIDLUXVH
.!$ 

QKKKM N MN
*/0*)
*/0*)
.*4$)
.*4$) 5*.
5*.
#$*
#$* )4.
)4.
#*)$6
#*)$6
*/)'/
*/)'/
%)7 $/0
*/0*)=.*4$)5*.
.*4$)=*/0*)5*.
5*.=#$*
#$*=)4.#*)$6
)4.=#*)$65*.
*/)'/=*/0*)
#*)$6=
, ' %$
def buildCityGraph(graphType):
g = graphType()
for name in ('Boston', 'Providence', 'New York', 'Chicago',
'Denver', 'Phoenix', 'Los Angeles'): #Create 7 nodes
g.addNode(Node(name))
g.addEdge(Edge(g.getNode('Boston'), g.getNode('Providence')))
g.addEdge(Edge(g.getNode('Boston'), g.getNode('New York')))
g.addEdge(Edge(g.getNode('Providence'), g.getNode('Boston')))
g.addEdge(Edge(g.getNode('Providence'), g.getNode('New York')))
g.addEdge(Edge(g.getNode('New York'), g.getNode('Chicago')))
g.addEdge(Edge(g.getNode('Chicago'), g.getNode('Denver')))
g.addEdge(Edge(g.getNode('Chicago'), g.getNode('Phoenix')))
g.addEdge(Edge(g.getNode('Denver'), g.getNode('Phoenix')))
g.addEdge(Edge(g.getNode('Denver'), g.getNode(’New York')))
g.addEdge(Edge(g.getNode('Los Angeles'), g.getNode('Boston')))
QKKKM N MO
'#%'''
'*.$0#(L,0#C./0/.#EF
$($'.0*'!C./0,0#C./0(0#**)3(.1)
/.#0.E 03.MF
 $)$.)$/0#0.,#($#0#47'//*5
(3/0,0.*5#0)*/5#44$/$00*4*$
*$)$)$))$0'**,/
QKKKM N MP
*00#05.3/$)$4$C)C*)-3.=$5)),0#
.*(/*3.0*)$)0.($0)*),0#.*(0#
$)0.($0)*0*0#/1)1*)0#*($)1*)$/,0#
.*(/*3.0*/1)1*)
$'%'%
0.00)$)$1')*
*)/$.''0#/0#0'40#0)*$)/*(
*..
*''*50#./0)#0*/$0*')*
 )*0.,00#,.*//.*()5)*
*)1)33)1'$0#.)*')**..3)*30*
*,1*)/
W #).3)*30**,1*)/0.0*0#,.4$*3/)*
)0.70#)60.,1)0#$/,.*//
QKKKM N MQ
$'%'%78
def DFS(graph, start, end, path, shortest, toPrint = False):
path = path + [start]
if toPrint:
print('Current DFS path:', printPath(path))
if start == end:
return path
for node in graph.childrenOf(start):
if node not in path: #avoid cycles
if shortest == None or len(path)  len(shortest):
newPath = DFS(graph, node, end, path, shortest, toPrint)
if newPath != None:
shortest = newPath
elif toPrint:
print('Already visited', node)
return shortest
def shortestPath(graph, start, end, toPrint = False):
return DFS(graph, start, end, [], None, toPrint)
''.*( 0/.3./$*)/0.0,.*,.'7
5.,,.3)1*)=
shortestPath      
QKKKM N MR
'
def testSP(source, destination):
g = buildCityGraph(DiGraph)
sp = shortestPath(g, g.getNode(source), g.getNode(destination)
toPrint = True)
if sp != None:
print('Shortest path from', source, 'to',
destination, 'is', printPath(sp))
else:
print('There is no path from', source, 'to', destination)
testSP('Boston', ’Chicago')
QKKKM N MS
.!$ 
QKKKM N MT
*/0*)
*/0*)
.*4$)
.*4$) 5*.
5*.
#$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)0#
.,#E'')*/*)/0,3.0#..*(/0.0F).,0
QKKKM N NM
#%'!:4%'6%'%78
def BFS(graph, start, end, toPrint = False):
initPath = [start]
pathQueue = [initPath]
while len(pathQueue) != 0:
#Get and remove oldest element in pathQueue
tmpPath = pathQueue.pop(0)
if toPrint:
print('Current BFS path:', printPath(tmpPath))
lastNode = tmpPath[-1]
if lastNode == end:
return tmpPath
for nextNode in graph.childrenOf(lastNode):
if nextNode not in tmpPath:
newPath = tmpPath + [nextNode]
pathQueue.append(newPath)
return None
QKKKM N NN
;
6,'*.'',0#/5$0#)#*,/*.
6,'*.$))7,0#5$0#(*.0#))#*,/
,'$,'7#'#'##.8
3..)0,0#=*/0*)
3..)0,0#=*/0*)CV.*4$)
3..)0,0#=*/0*)CV5*.
3..)0,0#=*/0*)CV.*4$)CV5*.
3..)0,0#=*/0*)CV5*.CV#$*
3..)0,0#=*/0*)CV.*4$)CV5*.CV#$*
3..)0,0#=*/0*)CV5*.CV#$*CV)4.
3..)0,0#=*/0*)CV5*.CV#$*CV#*)$6
#*.0/0,0#.*(*/0*)0*#*)$6$/*/0*)CV5*.CV#$*CV#*)$6
QKKKM N NO
3..)0,0#=*/0*)
3..)0,0#=*/0*)CV.*4$)
3..)0,0#=*/0*)CV5*.
3..)0,0#=*/0*)CV.*4$)CV5*.
3..)0,0#=*/0*)CV5*.CV#$*
3..)0,0#=*/0*)CV.*4$)CV5*.CV#$*
3..)0,0#=*/0*)CV5*.CV#$*CV)4.
3..)0,0#=*/0*)CV5*.CV#$*CV#*)$6
#*.0/0,0#.*(*/0*)0*#*)$6$/*/0*)CV5*.CV#$*CV#*)$6
*/0*)
*/0*)
.*4$)
.*4$) 5*.
5*.
#$*
#$* )4.
)4.
#*)$6
#*)$6
*/)'/
*/)'/
,'$,'7#'#'##.8
QKKKM N NP
*00#05
/$,,0#
0#0.4$/$0/
)*
'#,''#%'''
)00*($)$($80#/3(*0#5$#0/*0#/
)*00#)3(.*/
)/$'7(*$0**0#$/
))*0/$)/#*.0/05$#0,0#(7#4
(*.0#)0#($)$(3()3(.*#*,/
QKKKM N NQ
$
.,#/.**'
W /0570*.0(*'*()70#$)/
W ,03..'1*)/#$,/(*)*%0/
W )7$(,*.0)0,.*'(/),*//.,#
*,1($81*),.*'(/5'.7)*5#*50*/*'4
,0#C./0).0#C./0/.#.$(,*.0)0
'*.$0#(/
W )3/0*/*'4()7,.*'(/
QKKKM N NR
MIT OpenCourseWare
https://ocw.mit.edu
6.0002 Introduction to Computational Thinking and Data Science
Fall 2016
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.

graph-theoretic Models.pdf