Binary Tree Traversals ?


Traversing is the process of passing through every node exactly once in a binary tree. Traversing is also  called as visiting. There are 3- ways of traversing techniques.

1. preorder

2. Inorder

3. postorder

Preorder : In pre order traversal a root node is followed by its left sub tree and right sub tree.

    1.    Go to root node

    2.    Traversal the left sub tree

3.    Traversal the right sub tree

binary tree

O/P: ABCDEFGH

Inorder : In order traversal a root node is in between its left sub tree and right sub tree.

    1.    Traverse the left sub tree.

    2.    Process the root node.

    3.    Traverse the right sub tree.
binary tree


O/P: CBAEFDDG

Post Order:  In post order the left sub tree is traversed first and the right sub tree is traversal and then node is traversed . In this traversal the node is after its left and right sub tree.

    1.    Traverse the left sub tree.

    2.    Traverse the right sub tree.

3.    Process the root node.
binary tree


O/P:CBFEDGA


Related

STACKS USING ARRAYS

import java.io.*; class StackArray {   public static void main (String args[])throws IOException   {    BufferedReader br = new BufferedReader(new InputStreamReader(System....

SINGLE LINKED LIST

import java.io.*; class node {    int n;    node next; } class SingleLinkedList {  public static void main(String args[])throws IOException  {    Bu...

SELECTION SORT

import java.io.*; class SelectionSort {             public static void main(String args[])throws IOException      ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item