This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class MergeSort { | |
public static void main(String[] args) { | |
// get array and call mergeSort() on it | |
mergeSort(array); | |
} | |
public static void mergeSort(int[] array) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class LinkedListForEachDepth { | |
public static void main(String[] args) { | |
Node root = new Node(12); | |
// ... create BST with nodes | |
// create our list of LinkedLists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class MakeBSTFromArray { | |
public static void main(String[] args) { | |
int[] arr = {0,1,2,3}; | |
Node root = makeBSTShorter(arr, 0, arr.length-1); | |
System.out.println("Level order: "); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class DeleteNodeBST { | |
public static void main(String[] args) { | |
Node root = new Node(12); | |
// MAKE A TREE OF NODES... | |
delete(root, 14); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void DFS_Iterative(Node n) { | |
Stack<Node> stack = new Stack<Node>(); | |
stack.push(n); | |
while (!stack.isEmpty()) { | |
Node node = stack.pop(); | |
if (!node.visited) { | |
node.visited = true; | |
System.out.println(node); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class IsTreeBinarySearchTree { | |
public static void main(String[] args) { | |
// build a tree with Nodes...root is root Node | |
System.out.println((isTreeBST(root) ? "Tree is BST!" : "Tree is NOT BST!")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IsTreeBalanced { | |
public static void main(String[] args) { | |
// build a tree with Nodes...root is root Node | |
isBalanced(root); | |
} | |
public static int getHeight(Node root) { |