Skip to content

Instantly share code, notes, and snippets.

@jharris-code
jharris-code / rinkeby-address
Created October 13, 2017 19:31
testnet rinkeby
0x9f24ff18549A8B41C06a5fC732a2b90d459C249c
0x60d8734a039616163d84749ba10c9492f876928e
0xfb671a57270318f595eb2844aeb6ca82599eb76d
pragma solidity ^0.4.0;
contract WolframPocV1 {
address private owner;
struct Work {
bytes32 title;
address validator;
uint baselineUsers;
uint validatedUsers;
@jharris-code
jharris-code / linkedlist.js
Last active January 14, 2019 18:51
JavaScript Linked List Implementation
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
class LinkedList {
constructor() {
this.head = null;
@jharris-code
jharris-code / graph_adjacency_list.js
Last active January 8, 2019 20:52
Directed Graph Javascript Implementation
//Space Complexity: O(V + E)
class Graph {
constructor() {
this.vertices = new Map();
}
//O(V) time complexity of Map.prototype.set
addVertex(v) {
this.vertices.set(v, [])
}
@jharris-code
jharris-code / graph_adjacency_matrix.js
Last active January 8, 2019 20:51
Graph Directed Adjacency Matrix
//Storage: O(V^2)
class Graph {
//O(V^2)
constructor(size){
this.vertices = [];
for(let i = 0; i < size; i++){
this.vertices.push([]);
for(let j = 0; j < size; j++){
this.vertices[i].push(false);
@jharris-code
jharris-code / insertion_sort.js
Created January 8, 2019 23:38
JavaScript Insertion Sort
let a = [3,1,2,15,4,3,8,8,0];
let c = 0;
//Time Complexity: O(N^2)
//Space Complexity: O(1) because auxiliary space required (above original data set) is 0.
const insertionSort = (arr) => {
for(let i=0; i < arr.length; i++){
let j = i;
while(j > 0 && arr[j] < arr[j-1]) {
@jharris-code
jharris-code / heapify_array.js
Last active January 10, 2019 18:56
Heapify Array
//converting an array to a heap is performed with two functions, heapify and siftDown.
//The result is an array representation of a max heap.
//A max heap is required to perform a heap sort.
//Time Complexity: O(N). Although siftDown is O(log n), the overall runtime is O(N).
//Good info here on time complexity: https://www.growingwiththeweb.com/data-structures/binary-heap/build-heap-proof/
//Space Complexity: O(1) auxiliary space is 0 since the array is converted to a heap in place.
const heapify = (arr) => {
//end is the last element of the array
@jharris-code
jharris-code / heap_sort.js
Last active January 22, 2019 20:54
Heap Sort
//Create a sorted array (ascending) from a max heap
//Time Complexity: O(N log N)
//Space Complexity: O(1) because array is sorted in place
const heapSort = (arr, end) => {
while(end > 0){
let tmp = arr[end];
arr[end] = arr[0];
arr[0] = tmp;
end -= 1;