algorithm - Enumerating all paths in a tree -


i've tried , tried; searched , searched, not find algorithm solve problem. want enumerate paths in tree, (not simple paths) start , end leaf nodes (this easy constraint though).

for example, tree;

      1     /   \     2     3   / \   / \  4   5 6   7 

i want able generate following paths:

4 4-2-5 4-2-5-2-1-3-6 4-2-5-2-1-3-7 4-2-5-2-1-3-6-3-7 4-2-1-3-6 4-2-1-3-7 4-2-1-3-6-3-7 5 5-2-1-3-6 5-2-1-3-7 5-2-1-3-6-3-7 6 6-3-7 7 

i guess that's all.

i have tried following solution complexity of finding simple paths using depth first search? . however, finds simple paths, therefore paths such 4-2-5-2-1-3-6 not found.

are there ways can guide me, algorithm perhaps ?

do paths 4-2-1-2-5 count? if so, think have answer:

it looks me want each edge visited "once" . take "dual" of graph , @ paths sequence of edges rather sequence of vertices. way, edges become "vertices" , vertices become "edges".

this should reduce problem generating simple paths of graph, problem know how do.

traverse(path, edg):     mark edg visited     print path     each edge (e2) sharing vertex edg:         traverse(e2, path+e2)  (with sort of precaution avoid duplicate paths being printed) 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -