This file contains hidden or 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
| /** | |
| * First clears this BST, then reconstructs the BST that is | |
| * uniquely defined by the given preorder and inorder traversals | |
| * | |
| * (When you finish, this BST should produce the same preorder and | |
| * inorder traversals as those given) | |
| * | |
| * @param preorder a preorder traversal of the BST to reconstruct | |
| * @param inorder an inorder traversal of the BST to reconstruct | |
| */ |
This file contains hidden or 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
| /* | |
| * if BF is less than -1 | |
| * if right child - bf <=0 | |
| do left rotation | |
| * if right child - bf > 0 | |
| do right-left rotation | |
| * if BF is more than 1 | |
| * if left child - bf >=0 | |
| do right rotation | |
| * if left child - bf < 0 |
This file contains hidden or 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 static org.junit.Assert.assertEquals; | |
| import org.junit.Test; | |
| public class BinaryHeapTest { | |
| @Test (timeout=1000) | |
| public void testSimpleAdd1() { | |
| BinaryHeap<String> heap = new BinaryHeap<String>(); | |
| heap.add("6"); |
This file contains hidden or 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
| /** | |
| * Performs a left rotation on a node | |
| * | |
| * @param n The node to have the left rotation performed on | |
| * @return The new root of the subtree that is now balanced due to the rotation | |
| */ | |
| private Node<T> left(Node<T> n) { | |
| if(n != null){ | |
| Node<T> temp = n.getRight(); | |
| n.setRight(temp.getLeft()); |
This file contains hidden or 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
| from Myro import * | |
| def collageMaker(fileName, files, newFileName): | |
| picList = [] | |
| for myNum in range(files+1): | |
| newPic = makePicture("{}.jpg".format(myNum)) | |
| newRedSum = 0 | |
| newGreenSum = 0 | |
| newBlueSum = 0 | |
| for newPixel in getPixels(newPic): | |
| newRed = getRed(newPixel) |
This file contains hidden or 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.HashMap; | |
| import java.util.Set; | |
| public class DisjointSets<T> { | |
| private HashMap<T,Node> map; | |
| /** | |
| * @param setItems | |
| * the initial items (sameSet and merge will never be called with |
This file contains hidden or 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.ArrayList; | |
| import java.util.Collection; | |
| import java.util.PriorityQueue; | |
| public class MST { | |
| /** | |
| * Run Kruskal's algorithm on the given graph and return the MST, return | |
| * null if no MST exists for the graph | |
| * |
This file contains hidden or 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.Collection; | |
| import java.util.HashSet; | |
| import java.util.Scanner; | |
| import java.util.Set; | |
| public class Graph { | |
| private Collection<Edge> edges = new HashSet<Edge>(); | |
| private Set<Vertex> vertices = new HashSet<Vertex>(); |
This file contains hidden or 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 Vertex { | |
| private int id; | |
| /** | |
| * A simple vertex class | |
| * | |
| * @param id | |
| */ | |
| public Vertex(int id) { |
This file contains hidden or 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 Edge implements Comparable<Edge> { | |
| private Vertex u, v; | |
| private int weight; | |
| /** | |
| * Comparable edge class based on weight. Order of u and v does not matter. | |
| * | |
| * @param u | |
| * @param v |