Sunday, May 20, 2018

what do you mean by Preorder Traversal in tree?

Problem statement: what do you mean by Preorder traversal in tree?
  • Preorder traversal is defined as follows:
  1. visit the root
  2. traverse the left subtree in preorder
  3. traverse the right subtree in preorder 
  • Recursive Preorder Traversal:
  1. void  PreOrder(BinaryTreeNode root){
  2. if(root !=null){
  3. System.out.println(root.getData());
  4. PreOrder(root.getLeft());
  5. PreOrder(root.getRight());
  6. }
  7. }

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...