26

This is the explanation in wikipedia: Data-flow analysis

This is a typical iteration order for forward data-flow problems. In reverse-postorder iteration, a node is visited before any of its successor nodes has been visited, except when the successor is reached by a back edge. (Note that this is not the same as preorder.)

Can someone explain this in greater detail?

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
lililqth
  • 378
  • 1
  • 3
  • 7

1 Answers1

33

Reverse postordering as the name suggests produces the exact opposite of postorder traversal.

Example

enter image description here

For the above referred directed graph

postorder traversals are D B C A and D C B A

reverse postorder traversals are A C B D and A B C D

How to obtain reverse postorder traversal

One way is to run postorder traversal and push the nodes in a stack in postorder.

Then pop out the nodes to get the reverse postorder.

Application

Topological sorting using depth first search.

Marcel
  • 1,443
  • 2
  • 14
  • 24
Biboswan
  • 1,145
  • 12
  • 15
  • 2
    What is the different between reverse post-order DFS and BFS?! –  Nov 11 '20 at 09:24
  • 3
    @YasamanGhassemi for trees, they are the same (and also to pre-order DFS). For graphs (well, DAGs), they can be different if there are nodes that are both siblings and parent-child. – TemplateRex Dec 15 '20 at 18:57