Sunday, February 16, 2014

Binary Trees

In the previous week we have learned about binary trees. A binary tree is, not surprisingly, a specific kind of abstract data type called trees. Below I will give a recursive definition of a binary tree:

- A binary tree consists of a root.
- A root can be empty or it can have two parents as a child.
- A parent can either be empty or it can have two parents as a child.

So, a tree will have a root, which may or may not have a left and a right child. Moreover, those child nodes may or may not be parents. We also learned three ways of traversing a tree. Which are preorder, postorder and inorder traversal.
Here is how each of them traverse recursively:

Preorder

  1. root
  2. left
  3. right
Postorder
  1. left
  2. right
  3. root
Inorder
  1. left
  2. root
  3. right

-----------more will be added soon-----------

No comments:

Post a Comment