Question: Ex. 2.30 A concrete DFS procedure Let T be an arbitrary tree with a very specific representation that will be specified four lines from now
Ex. 2.30 A concrete DFS procedure Let T be an arbitrary tree with a very specific representation that will be specified four lines from now Please use pseudocode or a real programming language of your choice to present a DFS procedure that will traverse T recursively just like our pseudcode - and print the vertex names in a postorder listing So the print statement executes at the postorder exit time for each vertex. The vertex names are 0, 1, 2, 3, n. For each vertex j, its children's names are stored in the array childlj, ] where: child j 01 is not a name, but is the number of children that j has. So this cquntb is zero if j is a leaf The names of j's children are therefore: childj, 1], childj,2., childlj, k]. where R equals childi.o Assume that vertex 0 is the root, so that T will be DFSed via the instruction DES(O) That is, this DFS procedure will have integer names as the vertex arguments. For that reason, the solution will use vertex identifiers such as i and j instead of u and v. Of course, all names are equally good The point of this exercise is to demonstrate how easily pseudocode can be turned into real code in a real programming language. You can assume that the atray child is globally accessible to your procedure
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
