Tree traversal Flashcards
Pre - order traversal
the value of the node is always output first before checking for nodes on the left and then for nodes on the right.
use of pre-order traversal:
copying a tree
Pre-fix of an expression
How does pre-order traversal implement a recursive algorithm?
it is repeatedly called until all of the nodes have been processed. The first time that the function is called, it will be passed the address (pointer) of the root node. Each time the function is called a new node will be referenced (the left or right child node), until the base case is reached.
In - order traversal:
the value of the node is output after the left-hand nodes are inspected but before the right hand node is inpsected.
Use of In-Order traversal:
In a binary search tree the nodes are arranged in correct order so, in-order traversal would output the nodes in correct order.
-In-fix of an expression
Post-order traversal:
the value of the node is output after both the left AND the right nodes have been explored.
use of Post-order traversal:
used to convert from infix to postfix notation
emptying a tree
What is the same as post-order traversal?
Depth first search because it uses a stack to manage the backtracking and the nodes are processed the final time they are visited