Skip to main content

Straight Traversal

Definition​

The Straight Traversal Algorithm is a method used in graph theory to traverse a graph by moving along edges in a straight path from one vertex to another, without revisiting any vertices

Practice​

straightTraversal(graph, startVertex):
stack = empty stack
visited = set() // Set to keep track of visited vertices
path = empty list

stack.push(startVertex)

while stack is not empty:
currentVertex = stack.pop()

if currentVertex is not in visited:
add currentVertex to visited set
add currentVertex to path list

for each neighbor in graph.adjacent(currentVertex):
if neighbor is not in visited:
stack.push(neighbor)

return path