Computer notes - Recursive

We can implement non-recursive versions of the preorder, inorder and post order traversal by using an explicit stack. The stack will be used to store the tree nodes in the appropriate order. Here, for example, is the routine for inorder traversal that uses a stack.

Transcript of "Computer notes - Recursive"

1.
Class No.14 Data Structures http://ecomputernotes.com

2.
Recursive Call <ul><li>Recall that a stack is used during function calls. </li></ul><ul><li>The caller function places the arguments on the stack and passes control to the called function. </li></ul><ul><li>Local variables are allocated storage on the call stack. </li></ul><ul><li>Calling a function itself makes no difference as far as the call stack is concerned. </li></ul>http://ecomputernotes.com

8.
Non Recursive Traversal <ul><li>We can implement non-recursive versions of the preorder, inorder and postorder traversal by using an explicit stack. </li></ul><ul><li>The stack will be used to store the tree nodes in the appropriate order. </li></ul><ul><li>Here, for example, is the routine for inorder traversal that uses a stack. </li></ul>http://ecomputernotes.com

21.
Level-order Traversal <ul><li>There is yet another way of traversing a binary tree that is not related to recursive traversal procedures discussed previously. </li></ul><ul><li>In level-order traversal, we visit the nodes at each level before proceeding to the next level. </li></ul><ul><li>At each level, we visit the nodes in a left-to-right order. </li></ul>http://ecomputernotes.com