Section 8 Chapter 44 - Recursive Algorithms Flashcards
Recursion
An algorithm or subroutine that is defined in terms of itself
Characteristics of a recursive algorithm (3)
- A stopping condition / base case that when met will return a value not determined by calling itself again
- For other input values the algorithm must call itself
- The stopping condition must be reached after a finite number of calls
How to store a binary tree if you were gonna program with it
A list of records. Each record holds the left branch index, right branch index and the data
Pseudocode for in-order traversal
Traverse left subtree
Visit this node (the parent of the two subtrees)
Traverse right subtree
Pseudocode for pre-order traversal
Visit this node (the parent of the two subtrees)
Traverse left subtree
Traverse right subtree
Pseudocode for post-order traversal
Traverse left subtree
Traverse right subtree
Visit this node (the parent of the two subtrees)
Use of a pre order traversal
Copying a tree
Use of an in order traversal
Outputting the contents of a binary search tree in ascending order
Use of a post order traversal (2)
Converting infix to postfix (Reverse Polish Notation), emptying a tree