Real world pre/post-order tree traversal examples?

Topological sorting is a post-order traversal of trees (or directed acyclic graphs).

Topological sorting is a post-order traversal of trees (or directed acyclic graphs). The idea is that the nodes of the graph represent tasks and an edge from A to B indicates that A has to be performed before B. A topological sort will arrange these tasks in a sequence such that all the dependencies of a task appear earlier than the task itself.

Any build system like UNIX make has to implement this algorithm. The example that Dario mentioned — destroying all nodes of a tree with manual memory management — is an instance of this problem. After all, the task of destroying a node depends on the destruction of its children.

This is a great answer. Remembering that trees are degenerate graphs opens up all kinds of functionality. And topological sorting is hugely useful.

– Plutor Aug 23 '10 at 13:57 Why is it called topological sorting instead of, say, scheduling or something, or what is "Topological" supposed to mean in this context? – Shawn Apr 30 at 3:08 @Shawn: Beats me. It's probably because only the topology of the graph/network matters.

– Heinrich Apfelmus May 3 at 18:12.

Post order is (can be) used by compilers. Consider an expression tree for a + be + c, the machine language would require a sequence like a be + c +. This is also called Reverse polish Notation (RPN).

On the Wikipedia page it says: "RPN aka Postfix" Post-order is required for destroying a tree, just like pre-order is needed to create/clone it.

1 Destroying a tree, that's a good point. – Plutor Aug 20 '10 at 16:08 +1 Its like you can clone a tree using pre order and destroy it using the reverse steps i.e. Post order.

There should be some other areas where pre/post order would be very efficient. – Lazer Aug 20 '10 at 22:38.

As Henk Holterman pointed out, destroying a tree using manual memory management usually is a post-order traversal. Pseudocode: destroy(node) { if (node == null) return; destroy(node. Left) destroy(node.

Right) // Post-order freeing of current node free(node) }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions