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 Percolation { | |
private WeightedQuickUnionUF unionUF, unionUFPerc; | |
private int N; | |
private boolean[][] open; | |
// create N-by-N grid, with all sites blocked | |
public Percolation(int N) | |
{ | |
if (N <= 0) | |
throw new IllegalArgumentException(); |
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
''' | |
Gabriel C. 2015 | |
Kosaraju's algorithm for strongly connected components in a DAG | |
''' | |
import sys | |
import resource | |
sys.setrecursionlimit(10 ** 6) |
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
''' | |
Gabriel C. 2015 | |
Karger's minimum-cut algorithm on a list of edges | |
(definitely not the best data structure choice) | |
''' | |
import random | |
def contract(edges, u, v, nodes): |
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
''' | |
Gabriel C. 2015 | |
Quicksort with 3 different pivot-choosing methods | |
''' | |
def quicksort(array, method): | |
return quicksort_aux(array, 0, len(array) - 1, method) | |
def swap(array, a, b): |
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
''' | |
Gabriel C. 2015 | |
Counting inversions in an array | |
using merge sort with an auxiliary array | |
''' | |
def count_inversions_and_sort(array): | |
if len(array) == 1: | |
return 0; |
NewerOlder