Skip to content

Instantly share code, notes, and snippets.

Christian Vielma cvielma

Block or report user

Report or block cvielma

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
cvielma /
Last active Dec 23, 2015
Largest BST in a Tree - A full Java Solution
* Proposed solution to find the largest Binary Search Tree in a Binary Tree.
* Proposed Solution:
* To find the largest BST in a tree there are different options to traverse the tree: we could take an top-down approach
* or a bottom-up.
* The top-down approach require us to check at each node from the root if the tree starting at that node is a BST. This
* makes us traverse multiple times the tree to find the bst. Although it stops as soon as it find a BST because it will be
* the largest. This solution has a time complexity of O(n^2) in worst-case (degenerated tree into list) or O(nLogn) (balanced tree)
cvielma /
Last active Dec 23, 2015
Largest BST in a Tree - Java Solution (short)
public class LargestBst{
public static class TreeNode {
int value;
TreeNode left;
TreeNode right;
public static class TreeNodeHelper {
TreeNode node;
You can’t perform that action at this time.