Give an algorithm for deleting the tree

package in.blogspot.arunj2ee.ds.tree.binary.que;

import in.blogspot.arunj2ee.ds.tree.BinaryTreeNode;
import in.blogspot.arunj2ee.ds.tree.util.BTreePrinter;
import in.blogspot.arunj2ee.ds.tree.util.TreeUtil;

/*
 *Que: Give an algorithm for deleting the tree
 *Time Complexity: O(n), Space Complexity: O(n)
 *To delete nodes in tree, nodes can be deleted in POST order traversal.
 * Although other traversal mechanisms can be used too.
 * @author Arun.Singh
 */
public class Que8 {
public static BinaryTreeNode deleteBinaryTree(BinaryTreeNode root) {
root = null; // In java, it will be taken care by garbage collector
return root;
}

public static void main(String []args){
BinaryTreeNode rootNode = TreeUtil.createRandomBinaryTree();
BTreePrinter.printBinaryTreeNode(rootNode);
rootNode = deleteBinaryTree(rootNode);
BTreePrinter.printBinaryTreeNode(rootNode);
}
}
========================================================================
Refer Core Classes: http://arunj2ee.blogspot.in/2017/05/tree-core-and-utility-classes.html
========================================================================
Share on Google Plus

About Admin

Arun is a JAVA/J2EE developer and passionate about coding and managing technical team.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment