Binary search traversal with in/pre/post order and BFS/DFS I have the following code for the BST for the inorder, postorder, preorder, breadth first and depth first traversals. Can you review and let me know the optimisation points and issues, if any?

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;


public class BST {

    static class Node {

        int data;
        Node right, left;

        Node(int data) {
            this.data = data;
            right = left = null;
        }

        @Override
        public String toString() {
            return "Node [data=" + data + ", right=" + right + ", left=" + left + "]";
        }

    }

    public static void preOrder(Node root) {
        if (root != null) {
            System.out.print(root.data + " ");
            preOrder(root.left);
            preOrder(root.right);
        }
    }

    public static void inOrder(Node root) {
        if (root != null) {
            inOrder(root.left);
            System.out.print(root.data + " ");
            inOrder(root.right);
        }
    }

    public static void postOrder(Node root) {
        if (root != null) {
            postOrder(root.left);
            postOrder(root.right);
            System.out.print(root.data + " ");
        }
    }

    public static void breadthFirstTraversal(Node root) {
        Queue&lt;Node&gt; queue = new ArrayDeque&lt;Node&gt;();
        if (root != null) {
            queue.add(root);
        }
        while (!queue.isEmpty()) {
            Node node = queue.remove();
            System.out.print(node.data + " ");
            if (node.left != null) {
                queue.add(node.left);
            }
            if (node.right != null) {
                queue.add(node.right);
            }
        }
    }

    public static void depthFirstTraversal(Node root) {
        Stack&lt;Node&gt; stack = new Stack&lt;Node&gt;();
        if (root != null) {
            stack.push(root);
        }
        while (!stack.isEmpty()) {
            Node node = stack.pop();
            System.out.print(node.data + " ");
            if (node.right != null) {
                stack.push(node.right);
            }
            if (node.left != null) {
                stack.push(node.left);
            }

        }
    }

    public static Node insert(Node node, int data) {
        if (node == null) {
            return new Node(data);
        }
        Node cur;
        if (data &lt;= node.data) {
            cur = insert(node.left, data);
            node.left = cur;
        } else {
            cur = insert(node.right, data);
            node.right = cur;
        }
        return node;
    }

    public static void main(String args[]) {
        BST bst = new BST();
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        Node root = null;
        while (t-- &gt; 0) {
            int data = sc.nextInt();
            root = insert(root, data);
        }

        System.out.println("Preorder :");
        preOrder(root);
        System.out.println("\nInOrder ");
        inOrder(root);
        System.out.println("\nPostOrder ");
        postOrder(root);
        System.out.println("\nBreadth First Traversal ");
        breadthFirstTraversal(root);
        System.out.println("\nDepth First Traversal ");
        depthFirstTraversal(root);
    }

}
There is only one point I can state: in your constructor of Node you don't need to explicitly set left and right to null. The Java runtime system will do that for you. Also, note that DFS and preorder traversal are doing the same thing so you might want to consider removing one. Since your binary tree is not guaranteed to be balanced, I would retain the DFS as it allocates your stack on the heap, and so it is invulnerable to stack overflow as your recursive preorder traversal routine.