Two Easiest In Order Traverse (Java)
In order traverse for BST gives the natural order of numbers. No need to use array.\n\nRecursive:\n\n    int count = 0;\n    int result = Integer.MIN_VALUE;\n  
In order traverse for BST gives the natural order of numbers. No need to use array.\n\nRecursive:\n\n    int count = 0;\n    int result = Integer.MIN_VALUE;\n    \n    public int kthSmallest(TreeNode root, int k) {\n        traverse(root, k);\n        return result;\n    }\n    \n    public void traverse(TreeNode root, int k) {\n        if(root == null) {\n            return;\n        }\n        traverse(root.left, k);\n        //---------- real code starts here ----------\n        count++;\n        if(count == k) {\n            result = root.val;\n            return;\n        }       \n        //-------------------------------------------\n        traverse(root.right, k);       \n    }\n\nIterative:\n\n     public int kthSmallest(TreeNode root, int k) {\n         Stack<TreeNode> stack = new Stack<TreeNode>();\n         TreeNode p = root;\n         int count = 0;\n         \n         while (p != null || !stack.isEmpty()) {\n             if(p != null) {\n                 stack.push(p);  // similar to calling dfs(root.left)\n                 p = p.left;   \n             } else {\n                p = stack.pop();\n                //---------- real code starts here ----------\n                count++;\n                if(count == k) {\n                    return node.val; \n                }\n                //-------------------------------------------\n                p = node.right;  // similar to calling dfs(root.right)\n             }\n         }\n         \n         return Integer.MIN_VALUE;\n     }
['Java']