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 NaiveUnionFind{ | |
private int[] id; | |
public NaiveUnionFind(int N){ | |
id = new int[N]; | |
for (int i = 0; i < N; i++){ | |
id[i] = i; | |
} | |
} | |
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 WeightedQuickUnionFind{ | |
private int[] id; | |
private int[] sz; | |
private int[] height; // this is for union-by-height | |
private int count; // the number of connected components | |
private int[] maximum; // keep track of the maximum object in each connected component | |
public WeightedQuickUnionFind(int N){ | |
id = new int[N]; | |
sz = new int[N]; |
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 SuccessorDelete{ | |
private int[] id; | |
private int[] sz; | |
private int[] maximum; | |
public SuccessorDelete(int N){ | |
id = new int[N]; | |
sz = new int[N]; | |
maximum = new int[N]; | |
for (int i = 0; i < N; i++){ |
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.Hashtable; | |
public class ThreeSum{ | |
private int[] numbers; | |
private Hashtable<Integer, Boolean> numTable; | |
public ThreeSum(int[] numbers){ | |
this.numbers = numbers; | |
numTable = new Hashtable(); | |
for(int num: numbers){ |
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 BitonicArraySearch{ | |
private int[] numbers; | |
private int len; | |
private int turningPointIndex = -1; | |
public BitonicArraySearch(int[] numbers){ | |
this.numbers = numbers; | |
len = numbers.length; | |
} | |
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.Iterator; | |
import java.util.NoSuchElementException; | |
public class LinkedListStack<Item> implements Iterable<Item> { | |
private class Node { | |
Item value; | |
Node next; | |
} | |
private Node top; |
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.Iterator; | |
import java.util.NoSuchElementException; | |
public class ResizingArrayStack<Item> implements Iterable<Item>{ | |
private Item[] values; | |
private int count; | |
public ResizingArrayStack(){ | |
values = (Item[]) new Object[1]; // initialize the array to hold 1 element | |
count = 0; | |
} |
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.NoSuchElementException; | |
import java.util.Iterator; | |
public class LinkedListQueue<Item> implements Iterable<Item>{ | |
private class Node{ | |
Item item; | |
Node next; | |
} | |
private Node head; // head of the queue; we dequeue at the head |
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.Iterator; | |
import java.util.NoSuchElementException; | |
public class ResizingArrayQueue<Item> implements Iterable<Item>{ | |
private Item[] items; // the actual array holding the items | |
private int head; // the index of the head of the queue | |
private int tail; // the index of the tail of the queue | |
private int count; // the number of items in the queue | |
public ResizingArrayQueue(){ |
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.Arrays; | |
import java.util.ArrayList; | |
public class Subsets{ | |
public ArrayList<ArrayList<Integer>> subsets(int[] S) { | |
// sort the array first | |
Arrays.sort(S); | |
ArrayList<ArrayList<Integer>> results = new ArrayList<ArrayList<Integer>>(); | |
ArrayList<Integer> emptySet = new ArrayList<Integer>(); | |
results.add(emptySet); |
OlderNewer