Traversing a tree allows us to:
Types of traversing trees:
it has different paths:
The most common way to traverse through a tree is to use recursion.
Pre-order
ALGORITHM preOrder(root)
// INPUT <-- root node
// OUTPUT <-- pre-order output of tree node's values
OUTPUT <-- root.value
if root.left is not Null
preOrder(root.left)
if root.right is not NULL
preOrder(root.right)
In-order
ALGORITHM inOrder(root)
// INPUT <-- root node
// OUTPUT <-- in-order output of tree node's values
if root.left is not NULL
inOrder(root.left)
OUTPUT <-- root.value
if root.right is not NULL
inOrder(root.right)
Post-order
ALGORITHM postOrder(root)
// INPUT <-- root node
// OUTPUT <-- post-order output of tree node's values
if root.left is not NULL
postOrder(root.left)
if root.right is not NULL
postOrder(root.right)
OUTPUT <-- root.value
The biggest difference between each of the traversals is when you are looking at the root node.
Iterates through the tree by going through each level of the tree node-by-node

breadth first traversal uses a queue instead of the call stack via recursion.
ALGORITHM breadthFirst(root)
// INPUT <-- root node
// OUTPUT <-- front node of queue to console
Queue breadth <-- new Queue()
breadth.enqueue(root)
while ! breadth.is_empty()
node front = breadth.dequeue()
OUTPUT <-- front.value
if front.left is not NULL
breadth.enqueue(front.left)
if front.right is not NULL
breadth.enqueue(front.right)
Trees can have any number of children per node, but Binary Trees restrict the number of children to two.
Pushing nodes into a queue, but moving down a list of children of length k, instead of checking for the presence of a left and a right child.

Output: A, B, C, D, E, F, G, H
ALGORITHM breadthFirst(root)
// INPUT <-- root node
// OUTPUT <-- front node of queue to console
Queue breadth <-- new Queue()
breadth.enqueue(root)
while ! breadth.is_empty()
node front = breadth.dequeue()
OUTPUT <-- front.value
for child in front.children
breadth.enqueue(child)
It doesn’t matter where nodes are placed in a binary tree. you might add it to the spot where one of the roots doesn’t have a left or a right, or for adding it to a specific location you need to reference both the new node to create, and the parent node which the child is attached to.
Time
Space
A Binary Search Tree (BST) is a type of tree that does have some structure attached to it.
Compare the node you are searching for against the root of the tree or sub-tree. If the value is smaller, you only traverse the left side. If the value is larger, you only traverse the right side.
The best way to approach a BST search is with a while loop. We cycle through the while loop until we hit a leaf, or until we reach a match with what we’re searching for.
Time
The Big O time complexity of a Binary Search Tree’s search is O(h)
Space