| OCR Text |
Show 5 requires recomputation. It is also clear from the graph that the order of dependency propagation should be: pl :• pt( zl, yl ); line :• lineThru2Pta( pl, p2 ); In this particular situation, the recomputation ordering can be detennined by performing a depth first search of the dependency graph, beginning at the modified root of the graph, evaluating the objects as they are encountered in the search. However, if both x1 and x2 are changed, then a depth first search of the dependency graph starting at the modified roots would propagate dependencies in the following order: pl :• pt( zl, yl ); line : E lineThru2Pta ( pl, p2 ) ; p2 :• pt( z2, y2 ); line := lineThru2Pts( pl, p2 ); The depth first search recomputes a node in the graph each time the node is visited. If the same node can be reached by muttiple paths, then the node will be recomputed many times, once for each path leading to the node. A correct way to propagate dependencies is to perform a topological sort of the nodes reachable from the modified roots of the graph. A simple algorithm for finding the topological ordering of a DAG can be found in (1]. The basic idea is to perform a depth first search of the graph, placing a node on a list of nodes the first time the node is exited by the search. This list of nodes is in reverse topological order. The nodes may be evaluated in reverse order to correctly propagate the dependencies. The basic topological sort is: aortLiat :• nil; -- node list in reverse order procedure topologicalSort ( node begin if node ia not marked then mark node; for each dependent in node' a dependents do topoloqicalSort dependent; push node on aortList; andif; end; H both x1 and x2 are changed, then the topological sort produces the list: |