If we go through the AIGraphAlgorithm class, while adding each node we see that we are searching if the node exists.
nodes: aNodeList
aNodeList do: [ :model | self addNodeFor: model ]
addNodeFor: aModel
^ self
findNode: aModel
ifAbsent: [ nodes add: (self nodeClass with: aModel) ]
findNode: aModel ifAbsent: aBlock
"^ nodes findBinary: (self findBinaryBlock: aModel) ifNone: aBlock"
^ nodes detect: [ :node | node model = aModel ] ifNone: aBlock
The searching is done in O(V) operations, which makes creation of the graph take O(V^2) operations. Hence it is important to analyse improvements on this.
If we go through the AIGraphAlgorithm class, while adding each node we see that we are searching if the node exists.
The searching is done in O(V) operations, which makes creation of the graph take O(V^2) operations. Hence it is important to analyse improvements on this.