Showing posts with label BST. Show all posts
Showing posts with label BST. Show all posts

Sunday, January 25, 2015

Find Maximum Sum In Binary Tree Path

Following program does all the below mentioned work:
1) Print all nodes
2) Find if a value exists in a tree or not
3) Find value sum in any of the path
4) Find maximum sum in any of the path


Binary Search Tree


Binary Search Tree(BST) is a hierarchical data structure which is tree with a single reference to root node where each node has at most two child nodes (a left and a right child)

Nodes are organized by the Binary Search property:
• Every node is ordered by some key data field(s)
• For every node in the tree, its key is greater than its left child’s key and less than its right child’s key

Following implementation of BST





Input:
BinaryTree<String> tree = new BinaryTree<String>();
tree.add("Python");
tree.add("Java");
tree.add("Node.js");
tree.add("Angular.js");

Output:
[Angular.js, Java, Node.js, Python]