Skip to content

Instantly share code, notes, and snippets.

Zach Schultz zachschultz

Block or report user

Report or block zachschultz

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
@zachschultz
zachschultz / MergeSort.java
Created Mar 2, 2015
Java code for Merge Sort
View MergeSort.java
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) {
@zachschultz
zachschultz / LinkedListForEachDepth.java
Created Mar 1, 2015
Create a Linked List for each depth of a Binary Search Tree
View LinkedListForEachDepth.java
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
@zachschultz
zachschultz / MakeBSTFromArray.java
Created Mar 1, 2015
Create a minimum height BST from a sorted array
View MakeBSTFromArray.java
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: ");
@zachschultz
zachschultz / DeleteNodeBST.java
Created Feb 28, 2015
Delete a node from a Binary Search Tree
View DeleteNodeBST.java
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);
@zachschultz
zachschultz / DFS_Iterative.java
Created Feb 27, 2015
Iterative Depth First Search on Nodes
View DFS_Iterative.java
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);
@zachschultz
zachschultz / IsTreeBalanced.java
Last active Aug 29, 2015
Check if a Binary Tree is balanced
View IsTreeBalanced.java
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) {
View IsTreeBinarySearchTree.java
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!"));
}
You can’t perform that action at this time.