reading-notes


Project maintained by Razan-am Hosted on GitHub Pages — Theme by mattgraham

Trees

Common Terminology

Binary Tree

Traversals for binary trees

Depth First

Example: image1


When the root.left and root.right will return null the next node will act as the root to continue execution

Here is the pseudocode for this traversal method: preorder

Here is the pseudocode for this traversal method: inorder

Here is the pseudocode for this traversal method: postorder

The previous tree traversals are similar but the difference between each of the traversals is when you are looking at the root node.

Breadth First

Example: image2

Here is the pseudocode, utilizing a built-in queue to implement a breadth first traversal. breadth

K-ary Trees

Traversals for K-ary trees

Breadth First Traversal

Example: ktree

Here is the pseudocode kpesodu

Binary Search Trees

Example: image3


References:

@By codefellows/Trees