Skip to content

Instantly share code, notes, and snippets.

@Prottoy2938
Prottoy2938 / Hello
Last active February 26, 2020 06:49
Hello World!
@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 / 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 / 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) {
@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 / What's A Tree.txt
Created March 12, 2020 06:48
Tree Data Structure
In graph theory, a tree is an undirected graph in which any two vertices are connected by exactly one path,
or equivalently a connected acyclic undirected graph.
Which means, in a graph, we can reach a certain node in many different ways, but in a tree there should be only ONE way to reach that node.
@Prottoy2938
Prottoy2938 / Depth First Search.js
Last active March 13, 2020 05:56
Depth First Search Implementation in JavaScript. Works in Binary Tree
//The algorithm starts at the root node and explores as far as possible along each branch before backtracking
//To simplify, In Depth First Search in Binary Search Tree, travels through one side until it reaches its end and then tries the other side.
//============================================================================================================
//DFS_PreOrder
//This method, visits the one specific side(either left or right) at once, and after the whole side is finished, then visits the other side.
// as it goes through the tree, it pushes visited node continuously.
//Example: 10
// 6 15
// 3 8 20