- Remove unnecessary path from DFS - Take filenames as command line arguments - Update notes
996 B
996 B
Search Algorithm 1
O(n^2)
Visit all nodes with shortest path
- Create a set for visited nodes
- Set current node to start node
- From the current node compare all outgoing nodes
- Select the outgoing node with lowest weight that is not marked as visited
- If a node was found:
- Mark current node as visited
- Push next node to stack
- Set next node to current node
- Otherwise:
- Return with current stack
Search Algorithm 2 (Depth First Search)
O(n^2)
Visit all nodes with longest path
- Create a set for visited nodes
- Begin search at start node
- Mark current node as visited
- Iterate through all outgoing nodes that are not marked as visited
- Add edge weight to local length
- Recursively repeat steps 3 to 7 with outgoing nodes until all were visited
- When encountering a visited node compare max distance with local distance
- Replace max distance with local distance if max distance is smaller
- Reset local length for next node