and code to see how moving graphs to classes using dictionaries to represent graphs is efficientconnected nodes are located by fast hashing operation but depending on the applicationother representations might make more sense for instanceclasses can be used to model nodes in networktoomuch like the binary tree example earlier as classesnodes may contain content useful for more sophisticated searches they may also participate in inheritance hierarchiesto acquire additional behaviors to illustrate the basic ideaexample - shows an alternative coding for our graph searcherits algorithm is closest to gsearch example - pp \dstruct\classics\graph py "build graph with objects that know how to searchclass graphdef __init__(selflabelextra=none)self name label self data extra self arcs [nodes=inst objects graph=linked objs def __repr__(self)return self name def search(selfgoal)graph solns [self generate([self]goalgraph solns sort(key=lambda xlen( )return graph solns def generate(selfpathgoal)if self =goalgraph solns append(pathelsefor arc in self arcsif arc not in patharc generate(path [arc]goalclass =tests addr or self solnssame in this versiongraphs are represented as network of embedded class instance objects each node in the graph contains list of the node objects it leads to (arcs)which it knows how to search the generate method walks through the objects in the graph but this timelinks are directly available on each node' arcs listthere is no need to index (or passa dictionary to find linked objects the search is effectively spread across the graph' linked objects to testthe module in example - builds the test graph againthis time using linked instances of the graph class notice the use of exec in this codeit executes dynamically graph searching