1. Data Structures
1.1. Queue
A queue is an ordered collection of items that follows the FIFO (First In First Out), also known as the first-come first-served principle. The addition of new elements in a queue is at the tail, and the removal is from the front. The newest element added to the queue must wait at the end of the queue.
Reference: https://github.com/trekhleb/javascript-algorithms/tree/master/src/data-structures/queue
const queue = [];
queue.push(2); // queue is now [2]
queue.push(5); // queue is now [2, 5]
queue.push(7); // queue is now [2, 5, 7]
const i = queue.shift(); // queue is now [5, 7]
console.log(i); // displays 2
1.2. Stack
A stack is an ordered collection of items that follows the LIFO (Last In First Out) principle. The addition of new items or the removal of existing items takes place at the same end. The end of the stack is known as the top, and the opposite side is known as the base. The newest elements are near the top, and the oldest elements are near the base.
Reference: https://github.com/trekhleb/javascript-algorithms/tree/master/src/data-structures/stack
A stack is a linear data structure. A stack organizes data into sequential order.
//Stack with Array - First in, Last out
const stack = [];
stack.push(2); // stack is now [2]
stack.push(5); // stack is now [2, 5]
const i = stack.pop(); // stack is now [2]
console.log(i); // displays 5
1.3. Linked List
...
1.4. Doubly Linked List
...
1.5. Tree
In computer science, a tree is a widely used abstract data type (ADT) — or data structure implementing this ADT—that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes.
A tree data structure can be defined recursively (locally) as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of references to nodes (the "children"), with the constraints that no reference is duplicated, and none points to the root.
A simple unordered tree; in this diagram, the node labeled 7 has two children, labeled 2 and 6, and one parent, labeled 2. The root node, at the top, has no parent.
Reference: https://github.com/trekhleb/javascript-algorithms/tree/master/src/data-structures/tree
1.5.1. Binary Search Tree
In computer science, binary search trees (BST), sometimes called ordered or sorted binary trees, are a particular type of container: data structures that store "items" (such as numbers, names etc.) in memory. They allow fast lookup, addition and removal of items, and can be used to implement either dynamic sets of items, or lookup tables that allow finding an item by its key (e.g., finding the phone number of a person by name).
1.6. Graph
In computer science, a graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from mathematics, specifically the field of graph theory
A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph. These pairs are known as edges, arcs, or lines for an undirected graph and as arrows, directed edges, directed arcs, or directed lines for a directed graph. The vertices may be part of the graph structure, or may be external entities represented by integer indices or references.
Reference: https://github.com/trekhleb/javascript-algorithms/tree/master/src/data-structures/graph
1.7. Heap
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property described below.
In a min heap, if P is a parent node of C, then the key (the value) of P is less than or equal to the key of C.
In a max heap, the key of P is greater than or equal to the key of C
The node at the "top" of the heap with no parents is called the root node.
Reference: https://github.com/trekhleb/javascript-algorithms/tree/master/src/data-structures/heap
1.8. Priority Queue
...
1.9. Hash Table
A hash table is as simple as a map. The Map object is a simple key/value map. Any value (both objects and primitive values) may be used as either a key or a value.
Also known as an associative array, a hash map is one of the most useful and widely used data structures.
// Code