@@ -0,0 +1,2195 @@
+//  Copyright 2016 The Sawdust Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A//%0A%0Apackage treesimple.binarytree.bst;%0A%0A/**%0A * Time Complexity: O(n)%0A *%0A * @see %3Ca href = %22http://www.geeksforgeeks.org/a-program-to-check-if-a-binary-tree-is-bst-or-not/%22 %3E geeksforgeeks%3C/a%3E%0A */%0Apublic class CheckIfBTisBST %7B%0A    static class Node %7B%0A        int data;%0A        Node left, right;%0A%0A        public Node(int item) %7B%0A            data = item;%0A            left = right = null;%0A        %7D%0A    %7D%0A%0A    public static void main(String args%5B%5D) %7B%0A        /**%0A         * %3Cpre%3E%0A         *            4%0A         *          /   %5C%0A         *         2     5%0A         *       /  %5C%0A         *      1    3%0A         *     /%0A         *     1%0A         */%0A        Node root = new Node(4);%0A        root.left = new Node(2);%0A        root.right = new Node(5);%0A        //root.right.left = new Node(6);%0A        root.left.left = new Node(1);%0A        root.left.left.left = new Node(1);%0A        root.left.right = new Node(3);%0A%0A        if (isBST(root))%0A            System.out.println(%22IS BST%22);%0A        else%0A            System.out.println(%22Not a BST%22);%0A    %7D%0A    //--------------------------------------------%0A%0A    public static boolean isBST(Node root) %7B%0A        return check(root, Integer.MIN_VALUE,%0A                Integer.MAX_VALUE);%0A    %7D%0A%0A    public static boolean check(Node node, int min, int max) %7B%0A        if (node == null)%0A            return true;%0A%0A        if (min %3C node.data && node.data %3C= max) %7B // same value as left child of the same node%0A            return (check(node.left, min, node.data) &&%0A                    check(node.right, node.data, max));%0A        %7D%0A        return false;%0A    %7D%0A%7D%0A

Check if a BT is a BST