Skip to content

Instantly share code, notes, and snippets.

View adslaton's full-sized avatar

A.D. Slaton adslaton

View GitHub Profile
@adslaton
adslaton / quick-union-merge.js
Created April 25, 2020 18:55
quick-union-merge
const connections = new Map();
// create objects in the array
const uf = (n) => {
for (const x of Array(n).keys()) {
connections.set({ id: x, name: x}, x);
}
}
// root
@adslaton
adslaton / quick-union-type.js
Last active April 25, 2020 18:27
quick-union-type
const connections = [];
// create objects in the array
const uf = (n) => {
for (const x of Array(n).keys()) {
connections.push({ id: x, name: x});
}
}
// root
@adslaton
adslaton / deduce-dynamic-connectivity.js
Last active April 25, 2020 17:43
deduce-dynamic-connectivity
const connections = [ // O(1)
{
id: 1,
name: 1
},
{
id: 2,
name: 2
},
{
@adslaton
adslaton / quick-find-eager-solution.js
Last active April 25, 2020 06:05
quick-find-eager-solution
const connections = [
{
id: 0,
name: 0
},
{
id: 1,
name: 1
},
{
@adslaton
adslaton / quick-find-eager.js
Last active April 25, 2020 05:13
quick-find-eager
const connections = [
{
id: 0,
name: 0
},
{
id: 1,
name: 1
},
{
@adslaton
adslaton / union-find-type.js
Last active April 25, 2020 04:38
union-find-type
const connections = [];
// create objects in the array
const uf = (n) => {
for (const x of Array(n).keys()) {
connections.push({ id: x, name: x});
}
}
// union
@adslaton
adslaton / dynamic-connectivity.js
Last active April 25, 2020 04:37
dynamic-connectivity
const connections = [
{
id: 1,
name: 1
},
{
id: 2,
name: 2
},
{
@adslaton
adslaton / bigO-logarithmic-time.js
Last active April 24, 2020 16:42
Big O Logarithmic Time
// Represents an algorithm that runs in proportionally to the logarithm of the input size
const f = (n) => {
for (let i = 1; i < n.length; i = i * 2) { //
console.log(array[n]); // O(log(n))
} //
}
@adslaton
adslaton / bigO-quadratic-tmie.js
Last active April 24, 2020 16:43
Big O Quadratic Time
// Represents an algorithm whose performance is directly proportional to the squared size of the input data set
for (const x of Array(n).keys()) { // O(n)
for (const y of Array(n).keys()) { //
console.log(x, y); // O(n)
} //
}
// O(n) * O(n) * O(1) = O(n * n) = O(n^2)
@adslaton
adslaton / bigO-linear-time.js
Last active April 24, 2020 16:43
Big O Linear Time
// Represents an algorithm who’s complexity will grow in direct proportion to the size of the input data
// 1.
for (const x of Array(n).keys()) { // n
console.log(x); // O(1)
}
// n * O(1) = O(n)