Skip to content

Instantly share code, notes, and snippets.

View abenteuerzeit's full-sized avatar
💭
Open to collaborate

Adrian Mróz abenteuerzeit

💭
Open to collaborate
View GitHub Profile
@abenteuerzeit
abenteuerzeit / Graph.js
Last active August 17, 2023 18:44 — forked from codecademydev/Graph.js
DIJKSTRA'S ALGORITHM
class Graph {
constructor(isDirected = false, isWeighted = false) {
this.vertices = [];
this.isDirected = isDirected;
this.isWeighted = isWeighted;
}
addVertex(data) {
const newVertex = new Vertex(data);
this.vertices.push(newVertex);
@abenteuerzeit
abenteuerzeit / Graph.js
Created August 17, 2023 17:53 — forked from codecademydev/Graph.js
Graphs: Depth First Traversal
class Graph {
constructor(isDirected = false, isWeighted = false) {
this.vertices = [];
this.isDirected = isDirected;
this.isWeighted = isWeighted;
}
addVertex(data) {
const newVertex = new Vertex(data);
this.vertices.push(newVertex);
@abenteuerzeit
abenteuerzeit / Graph.js
Last active August 17, 2023 17:52 — forked from codecademydev/Graph.js
Graphs: Breadth First Traversal
class Graph {
constructor(isDirected = false, isWeighted = false) {
this.vertices = [];
this.isDirected = isDirected;
this.isWeighted = isWeighted;
}
addVertex(data) {
const newVertex = new Vertex(data);
this.vertices.push(newVertex);
@abenteuerzeit
abenteuerzeit / BinaryTree.js
Created August 17, 2023 16:36 — forked from codecademydev/BinaryTree.js
Binary Search Tree
class BinaryTree {
constructor(value, depth = 1) {
this.value = value;
this.depth = depth;
this.left = null;
this.right = null;
}
insert(value) {
if (value < this.value) {
@abenteuerzeit
abenteuerzeit / index.js
Created August 17, 2023 16:23 — forked from codecademydev/index.js
Binary Search
const binarySearch = (arr, target) => {
let left = 0;
let right = arr.length;
while (right > left) {
const indexToCheck = Math.floor((left + right) / 2);
const checking = arr[indexToCheck];
console.log(indexToCheck);
if (checking === target) {
@abenteuerzeit
abenteuerzeit / quicksort.js
Last active August 17, 2023 15:49 — forked from codecademydev/quicksort.js
Quicksort
const swap = require('./swap');
const quicksort = (array, leftBound = 0, rightBound = array.length - 1) => {
if (leftBound < rightBound) {
console.log('. Calling partition', array, `with leftBound ${leftBound} and rightBound ${rightBound}`);
const pivotIndex = partition(array, leftBound, rightBound);
console.log(`. Returning pivotIndex = ${pivotIndex}`);
console.log(`\nCalling quicksort for left partition with leftBound ${leftBound} and (pivotIndex-1) ${pivotIndex - 1}`);
quicksort(array, leftBound, pivotIndex - 1);
console.log(`\nCalling quicksort for right partition with pivotIndex ${pivotIndex} and rightBound ${rightBound}`);
@abenteuerzeit
abenteuerzeit / index.js
Created August 17, 2023 13:21 — forked from codecademydev/index.js
Merge Sort
const mergeSort = (startArray) => {
const length = startArray.length;
if (length === 1) {
return startArray;
}
const mid = Math.floor(length / 2);
const leftArray = startArray.slice(0, mid);
const rightArray = startArray.slice(mid, length);
@abenteuerzeit
abenteuerzeit / bubbleSort.js
Created August 17, 2023 12:45 — forked from codecademydev/bubbleSort.js
Bubble sort
const swap = require("./swap");
const bubbleSort = (input) => {
let swapCount = 0;
let swapping = true;
while (swapping) {
swapping = false;
for (let i = 0; i < input.length - 1; i++) {
if (input[i] > input[i + 1]) {
@abenteuerzeit
abenteuerzeit / LinkedList.js
Last active August 15, 2023 17:33 — forked from codecademydev/LinkedList.js
Recursion
const Node = require("./Node");
class LinkedList {
constructor() {
this.head = null;
}
addToHead(data) {
const nextNode = new Node(data);
const currentHead = this.head;
@abenteuerzeit
abenteuerzeit / Edge.js
Created August 15, 2023 11:14 — forked from codecademydev/Edge.js
Graph
class Edge {
constructor(start, end, weight = null) {
this.start = start;
this.end = end;
this.weight = weight;
}
}
module.exports = Edge;