I have a directed graph that looks sort of like this. All edges are unidirectional, cycles exist, and some nodes have no children.
I want a traversal algorithm where the goal is to find a path of length n nodes anywhere in the graph. The algorithm should do the following:
I'm not sure if an algorithm for this already exists. Most search algorithms seem to deal with finding shortest path, MSTs, and can't visit same nodes. Pathfinding algorithms like A* and Dijkstra's seem overcomplicated for my needs. I might need a modified version of one of these, but not sure exactly which one to use.
It sounds like you just want a simple recursive algorithm. Here's some basic pseudocode.
find_path(node, n):
if n == 1:
yield [node]
return
for each child of node n:
for each path in find_path(child, n - 1):
yield [node] + path