Skip to content

Instantly share code, notes, and snippets.

@Prottoy2938
Prottoy2938 / Hello
Last active February 26, 2020 06:49
Hello World!
@Prottoy2938
Prottoy2938 / DoublyLinkedList.js
Last active March 4, 2020 12:01
Doubly Linked List example in JavaScript with multiple common methods
//Doubly Linked List is almost similar to singlyLinkedList, except every node has another pointer to the previous node.
class Node {
constructor(val, prev = null, next = null) {
this.val = val;
this.prev = prev;
this.next = next;
}
}
@Prottoy2938
Prottoy2938 / Stack and Queue.js
Last active March 7, 2020 18:14
Stack and Queue data structure in JavaScript
//Stack implementation==================================================================================
// Stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle.
class Node {
constructor(data, next = null) {
this.data = data;
this.next = next;
}
}
class Stack {
@Prottoy2938
Prottoy2938 / sizes.js
Created March 4, 2020 06:39
React JSS media query reusable component/snippet
export default {
up() {},
down(size) {
const sizes = {
xs: "575.98px",
sm: "767.98px",
md: "991.98px",
lg: "1199.98px",
xl: "1600px",
}
@Prottoy2938
Prottoy2938 / binarySearchTree.js
Last active September 3, 2024 10:02
Binary Search Tree implementation in JavaScript
// A binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.
// Left child is always less than it's parent and the right child is always bigger than it's parent.
class Node {
constructor(value) {
this.value = value;
this.right = null;
this.left = null;
}
}
@Prottoy2938
Prottoy2938 / Breadth First Search.js
Last active March 12, 2020 06:24
`Breadth-first search` algorithm for Binary Search Tree
//breadth_First_Search
//This method, visits tree's node horizontally and pushes them. It uses queue to keep track of its work.
//Example: 10
// 6 15
// 3 8 20
//result node would be =[10, 6, 15, 3, 8, 20]
//The Breadth-first search algorithm that's shown in here, is for data structures like `Binary Search Tree`.
@Prottoy2938
Prottoy2938 / treeTraversal.js
Last active March 12, 2020 06:46
Couple of Tree Traversal Methods in JavaScript - Includes `breadth-first-search`, `depth-first-search` (depth-first-search-PreOrder, depth-first-search-postOrder, depth-first-search-InOrder)
//IMPORTANT
//aLL the tree traversal comments are written in here are based on BST or Binary Search Tree.
//IMPORTANT
//============================================================================================================
//breadth_First_Search
//This method, visits tree's node horizontally and pushes them. It uses queue to keep track of its work.
@Prottoy2938
Prottoy2938 / Max Binary Heap.js
Last active March 18, 2020 09:47
Max Binary Heap implementation in JavaScript
//BinaryHeaps are very similar to Binary Tree with some slightly different rules. It has two catagories, Max Binary Heap and Min Binary Heap
//In a Max Binary Heap, parent node is always larger than its child nodes and In a Min Binary Heap, parent node is always smaller than its child node.
//This snippet implementation of Max Binary Heap with JavaScript Arrays.
//Parent idx=n; leftChild idx=[2 * n + 1 ] and rightChild Idx=[2 * n + 2 ]
class MaxBinaryHeap {
constructor() {
this.values = [];
}
@Prottoy2938
Prottoy2938 / PriorityQueue.js
Last active March 10, 2020 16:24
Priority Queue made in Min Binary Heap.
class Node {
constructor(value, priority) {
this.value = value;
this.priority = priority;
}
}
class PriorityQueue {
constructor() {
this.values = [];
@Prottoy2938
Prottoy2938 / Hash Tables.js
Created March 12, 2020 05:40
Simple Hash Table implementation in JavaScript
//Hash tables are collection of key value pairs.
//This hash function uses Array to store data and uses separate chaining to avoid key collusion.
//Only works on alphabetic character string keys.
class Hash {
constructor(size = 5) {
this.table = new Array(size);
}
//hashes the given key/value. Using the given key, it finds an index on the Table and returns that index.
_hash(key) {