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);
}
}
========================================================================
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========================================================================
0 comments:
Post a Comment