serialization - All permutations of a tree -
i need algorithm computes all possible permutations of given tree structure, example:
4 3 \ | \ 2 \ / 1 this means, (4) needs ordered before (1), (3) before (2) , (2) before (1).thus output should contain of , not more following:
[4,3,2,1] [3,4,2,1] [3,2,4,1] an invalid order example
[4,2,3,1] as (2) before (3), (2) successor of (3) in graph. computing permutations , filtering invalid orderings doesn't work reasons of efficiency.
i don't need exact code, idea of how done helpful.
this problem topological sort directed graph.
resolved dfs time complexity o(e+v).
http://en.wikipedia.org/wiki/topological_sorting
Comments
Post a Comment