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 quickFind { | |
| private int [] id; | |
| public void QuickFindUF (int N){ | |
| id = new int [N]; | |
| for(int i = 0; i< N; i++){ | |
| id[i]=i; | |
| } | |
| } |
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 quickUnion { | |
| private int[] id; | |
| public void QuickUnionUF(int N){ | |
| id = new int [N]; | |
| for(int i = 0; i < N; i++){ | |
| id[i] = i; | |
| } | |
| } |
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.Scanner; | |
| public class Eratosthenes { | |
| /** | |
| * Sieve of Eratosthenes. | |
| * Generates prime numbers. | |
| * You can find more about the algorithm here: | |
| * http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
| * @author gtkesh | |
| */ |
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 static int partition(int arr[], int left, int right){ | |
| int i = left, j = right; | |
| int temp; | |
| int pivot = arr[(left + right) / 2]; | |
| while (i <= j) { | |
| while (arr[i] < pivot) | |
| i++; | |
| while (arr[j] > pivot) | |
| j--; |
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.List; | |
| /** | |
| * BST | |
| * @author gtkesh | |
| */ | |
| public class BST<T extends Comparable<T>> { |
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
| /** | |
| * Adds a data entry to the BST | |
| * | |
| * null is positive infinity | |
| * | |
| * @param data The data entry to add | |
| */ | |
| public void add(T data) { | |
| root = add(data, root); | |
| } |
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 boolean search(T data, Node<T> node){ | |
| if(data != null){ | |
| if(data.compareTo(node.getData()) == 0){ | |
| return true; | |
| }else{ | |
| if(data.compareTo(node.getData()) < 0){ | |
| if(node.left == null){ | |
| return false; | |
| }else{ | |
| return search(data, node.left); |
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
| /** | |
| * Finds the in-order traversal of the BST | |
| * | |
| * @return A list of the data set in the BST in in-order | |
| */ | |
| public List<T> inOrder() { | |
| List<T> list = new ArrayList<T>(); | |
| inOrder(root, list); | |
| return list; | |
| } |
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
| /** | |
| * Removes a data entry from the BST | |
| * | |
| * null is positive infinity | |
| * | |
| * @param data The data entry to be removed | |
| * @return The removed data entry (null if nothing is removed) | |
| * | |
| */ | |
| public T remove(T data) { |
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
| /** | |
| * Checks if the BST contains a data entry | |
| * | |
| * null is positive infinity | |
| * | |
| * @param data The data entry to be checked | |
| * @return If the data entry is in the BST | |
| */ | |
| public boolean contains(T data) { | |
| if(root == null){ |
OlderNewer