diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000000..cf658d3d34
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,3 @@
+*.md
+*.jpg
+*.png
\ No newline at end of file
diff --git a/.eslintrc b/.eslintrc
index e1c40a0adb..652979a1ed 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -5,7 +5,9 @@
"env": {
"jest/globals": true
},
+ "parser": "@babel/eslint-parser",
"rules": {
+ "linebreak-style": 0,
"no-bitwise": "off",
"no-lonely-if": "off",
"class-methods-use-this": "off",
diff --git a/README.md b/README.md
index d00945e5a5..6af0e59cbb 100644
--- a/README.md
+++ b/README.md
@@ -27,8 +27,8 @@ _Read this in other languages:_
[_Arabic_](README.ar-AR.md),
[_Deutsch_](README.de-DE.md)
-*☝ Note that this project is meant to be used for learning and researching purposes
-only, and it is **not** meant to be used for production.*
+_☝ Note that this project is meant to be used for learning and researching purposes
+only, and it is **not** meant to be used for production._
## Data Structures
@@ -39,23 +39,23 @@ the data.
`B` - Beginner, `A` - Advanced
-* `B` [Linked List](src/data-structures/linked-list)
-* `B` [Doubly Linked List](src/data-structures/doubly-linked-list)
-* `B` [Queue](src/data-structures/queue)
-* `B` [Stack](src/data-structures/stack)
-* `B` [Hash Table](src/data-structures/hash-table)
-* `B` [Heap](src/data-structures/heap) - max and min heap versions
-* `B` [Priority Queue](src/data-structures/priority-queue)
-* `A` [Trie](src/data-structures/trie)
-* `A` [Tree](src/data-structures/tree)
- * `A` [Binary Search Tree](src/data-structures/tree/binary-search-tree)
- * `A` [AVL Tree](src/data-structures/tree/avl-tree)
- * `A` [Red-Black Tree](src/data-structures/tree/red-black-tree)
- * `A` [Segment Tree](src/data-structures/tree/segment-tree) - with min/max/sum range queries examples
- * `A` [Fenwick Tree](src/data-structures/tree/fenwick-tree) (Binary Indexed Tree)
-* `A` [Graph](src/data-structures/graph) (both directed and undirected)
-* `A` [Disjoint Set](src/data-structures/disjoint-set)
-* `A` [Bloom Filter](src/data-structures/bloom-filter)
+- `B` [Linked List](src/data-structures/linked-list)
+- `B` [Doubly Linked List](src/data-structures/doubly-linked-list)
+- `B` [Queue](src/data-structures/queue)
+- `B` [Stack](src/data-structures/stack)
+- `B` [Hash Table](src/data-structures/hash-table)
+- `B` [Heap](src/data-structures/heap) - max and min heap versions
+- `B` [Priority Queue](src/data-structures/priority-queue)
+- `A` [Trie](src/data-structures/trie)
+- `A` [Tree](src/data-structures/tree)
+ - `A` [Binary Search Tree](src/data-structures/tree/binary-search-tree)
+ - `A` [AVL Tree](src/data-structures/tree/avl-tree)
+ - `A` [Red-Black Tree](src/data-structures/tree/red-black-tree)
+ - `A` [Segment Tree](src/data-structures/tree/segment-tree) - with min/max/sum range queries examples
+ - `A` [Fenwick Tree](src/data-structures/tree/fenwick-tree) (Binary Indexed Tree)
+- `A` [Graph](src/data-structures/graph) (both directed and undirected)
+- `A` [Disjoint Set](src/data-structures/disjoint-set)
+- `A` [Bloom Filter](src/data-structures/bloom-filter)
## Algorithms
@@ -66,106 +66,107 @@ a set of rules that precisely define a sequence of operations.
### Algorithms by Topic
-* **Math**
- * `B` [Bit Manipulation](src/algorithms/math/bits) - set/get/update/clear bits, multiplication/division by two, make negative etc.
- * `B` [Binary Floating Point](src/algorithms/math/binary-floating-point) - binary representation of the floating-point numbers.
- * `B` [Factorial](src/algorithms/math/factorial)
- * `B` [Fibonacci Number](src/algorithms/math/fibonacci) - classic and closed-form versions
- * `B` [Prime Factors](src/algorithms/math/prime-factors) - finding prime factors and counting them using Hardy-Ramanujan's theorem
- * `B` [Primality Test](src/algorithms/math/primality-test) (trial division method)
- * `B` [Euclidean Algorithm](src/algorithms/math/euclidean-algorithm) - calculate the Greatest Common Divisor (GCD)
- * `B` [Least Common Multiple](src/algorithms/math/least-common-multiple) (LCM)
- * `B` [Sieve of Eratosthenes](src/algorithms/math/sieve-of-eratosthenes) - finding all prime numbers up to any given limit
- * `B` [Is Power of Two](src/algorithms/math/is-power-of-two) - check if the number is power of two (naive and bitwise algorithms)
- * `B` [Pascal's Triangle](src/algorithms/math/pascal-triangle)
- * `B` [Complex Number](src/algorithms/math/complex-number) - complex numbers and basic operations with them
- * `B` [Radian & Degree](src/algorithms/math/radian) - radians to degree and backwards conversion
- * `B` [Fast Powering](src/algorithms/math/fast-powering)
- * `B` [Horner's method](src/algorithms/math/horner-method) - polynomial evaluation
- * `B` [Matrices](src/algorithms/math/matrix) - matrices and basic matrix operations (multiplication, transposition, etc.)
- * `B` [Euclidean Distance](src/algorithms/math/euclidean-distance) - distance between two points/vectors/matrices
- * `A` [Integer Partition](src/algorithms/math/integer-partition)
- * `A` [Square Root](src/algorithms/math/square-root) - Newton's method
- * `A` [Liu Hui π Algorithm](src/algorithms/math/liu-hui) - approximate π calculations based on N-gons
- * `A` [Discrete Fourier Transform](src/algorithms/math/fourier-transform) - decompose a function of time (a signal) into the frequencies that make it up
-* **Sets**
- * `B` [Cartesian Product](src/algorithms/sets/cartesian-product) - product of multiple sets
- * `B` [Fisher–Yates Shuffle](src/algorithms/sets/fisher-yates) - random permutation of a finite sequence
- * `A` [Power Set](src/algorithms/sets/power-set) - all subsets of a set (bitwise and backtracking solutions)
- * `A` [Permutations](src/algorithms/sets/permutations) (with and without repetitions)
- * `A` [Combinations](src/algorithms/sets/combinations) (with and without repetitions)
- * `A` [Longest Common Subsequence](src/algorithms/sets/longest-common-subsequence) (LCS)
- * `A` [Longest Increasing Subsequence](src/algorithms/sets/longest-increasing-subsequence)
- * `A` [Shortest Common Supersequence](src/algorithms/sets/shortest-common-supersequence) (SCS)
- * `A` [Knapsack Problem](src/algorithms/sets/knapsack-problem) - "0/1" and "Unbound" ones
- * `A` [Maximum Subarray](src/algorithms/sets/maximum-subarray) - "Brute Force" and "Dynamic Programming" (Kadane's) versions
- * `A` [Combination Sum](src/algorithms/sets/combination-sum) - find all combinations that form specific sum
-* **Strings**
- * `B` [Hamming Distance](src/algorithms/string/hamming-distance) - number of positions at which the symbols are different
- * `A` [Levenshtein Distance](src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
- * `A` [Knuth–Morris–Pratt Algorithm](src/algorithms/string/knuth-morris-pratt) (KMP Algorithm) - substring search (pattern matching)
- * `A` [Z Algorithm](src/algorithms/string/z-algorithm) - substring search (pattern matching)
- * `A` [Rabin Karp Algorithm](src/algorithms/string/rabin-karp) - substring search
- * `A` [Longest Common Substring](src/algorithms/string/longest-common-substring)
- * `A` [Regular Expression Matching](src/algorithms/string/regular-expression-matching)
-* **Searches**
- * `B` [Linear Search](src/algorithms/search/linear-search)
- * `B` [Jump Search](src/algorithms/search/jump-search) (or Block Search) - search in sorted array
- * `B` [Binary Search](src/algorithms/search/binary-search) - search in sorted array
- * `B` [Interpolation Search](src/algorithms/search/interpolation-search) - search in uniformly distributed sorted array
-* **Sorting**
- * `B` [Bubble Sort](src/algorithms/sorting/bubble-sort)
- * `B` [Selection Sort](src/algorithms/sorting/selection-sort)
- * `B` [Insertion Sort](src/algorithms/sorting/insertion-sort)
- * `B` [Heap Sort](src/algorithms/sorting/heap-sort)
- * `B` [Merge Sort](src/algorithms/sorting/merge-sort)
- * `B` [Quicksort](src/algorithms/sorting/quick-sort) - in-place and non-in-place implementations
- * `B` [Shellsort](src/algorithms/sorting/shell-sort)
- * `B` [Counting Sort](src/algorithms/sorting/counting-sort)
- * `B` [Radix Sort](src/algorithms/sorting/radix-sort)
-* **Linked Lists**
- * `B` [Straight Traversal](src/algorithms/linked-list/traversal)
- * `B` [Reverse Traversal](src/algorithms/linked-list/reverse-traversal)
-* **Trees**
- * `B` [Depth-First Search](src/algorithms/tree/depth-first-search) (DFS)
- * `B` [Breadth-First Search](src/algorithms/tree/breadth-first-search) (BFS)
-* **Graphs**
- * `B` [Depth-First Search](src/algorithms/graph/depth-first-search) (DFS)
- * `B` [Breadth-First Search](src/algorithms/graph/breadth-first-search) (BFS)
- * `B` [Kruskal’s Algorithm](src/algorithms/graph/kruskal) - finding Minimum Spanning Tree (MST) for weighted undirected graph
- * `A` [Dijkstra Algorithm](src/algorithms/graph/dijkstra) - finding the shortest paths to all graph vertices from single vertex
- * `A` [Bellman-Ford Algorithm](src/algorithms/graph/bellman-ford) - finding the shortest paths to all graph vertices from single vertex
- * `A` [Floyd-Warshall Algorithm](src/algorithms/graph/floyd-warshall) - find the shortest paths between all pairs of vertices
- * `A` [Detect Cycle](src/algorithms/graph/detect-cycle) - for both directed and undirected graphs (DFS and Disjoint Set based versions)
- * `A` [Prim’s Algorithm](src/algorithms/graph/prim) - finding Minimum Spanning Tree (MST) for weighted undirected graph
- * `A` [Topological Sorting](src/algorithms/graph/topological-sorting) - DFS method
- * `A` [Articulation Points](src/algorithms/graph/articulation-points) - Tarjan's algorithm (DFS based)
- * `A` [Bridges](src/algorithms/graph/bridges) - DFS based algorithm
- * `A` [Eulerian Path and Eulerian Circuit](src/algorithms/graph/eulerian-path) - Fleury's algorithm - Visit every edge exactly once
- * `A` [Hamiltonian Cycle](src/algorithms/graph/hamiltonian-cycle) - Visit every vertex exactly once
- * `A` [Strongly Connected Components](src/algorithms/graph/strongly-connected-components) - Kosaraju's algorithm
- * `A` [Travelling Salesman Problem](src/algorithms/graph/travelling-salesman) - shortest possible route that visits each city and returns to the origin city
-* **Cryptography**
- * `B` [Polynomial Hash](src/algorithms/cryptography/polynomial-hash) - rolling hash function based on polynomial
- * `B` [Rail Fence Cipher](src/algorithms/cryptography/rail-fence-cipher) - a transposition cipher algorithm for encoding messages
- * `B` [Caesar Cipher](src/algorithms/cryptography/caesar-cipher) - simple substitution cipher
- * `B` [Hill Cipher](src/algorithms/cryptography/hill-cipher) - substitution cipher based on linear algebra
-* **Machine Learning**
- * `B` [NanoNeuron](https://github.com/trekhleb/nano-neuron) - 7 simple JS functions that illustrate how machines can actually learn (forward/backward propagation)
- * `B` [k-NN](src/algorithms/ml/knn) - k-nearest neighbors classification algorithm
- * `B` [k-Means](src/algorithms/ml/k-means) - k-Means clustering algorithm
-* **Image Processing**
- * `B` [Seam Carving](src/algorithms/image-processing/seam-carving) - content-aware image resizing algorithm
-* **Uncategorized**
- * `B` [Tower of Hanoi](src/algorithms/uncategorized/hanoi-tower)
- * `B` [Square Matrix Rotation](src/algorithms/uncategorized/square-matrix-rotation) - in-place algorithm
- * `B` [Jump Game](src/algorithms/uncategorized/jump-game) - backtracking, dynamic programming (top-down + bottom-up) and greedy examples
- * `B` [Unique Paths](src/algorithms/uncategorized/unique-paths) - backtracking, dynamic programming and Pascal's Triangle based examples
- * `B` [Rain Terraces](src/algorithms/uncategorized/rain-terraces) - trapping rain water problem (dynamic programming and brute force versions)
- * `B` [Recursive Staircase](src/algorithms/uncategorized/recursive-staircase) - count the number of ways to reach to the top (4 solutions)
- * `B` [Best Time To Buy Sell Stocks](src/algorithms/uncategorized/best-time-to-buy-sell-stocks) - divide and conquer and one-pass examples
- * `A` [N-Queens Problem](src/algorithms/uncategorized/n-queens)
- * `A` [Knight's Tour](src/algorithms/uncategorized/knight-tour)
+- **Math**
+ - `B` [Bit Manipulation](src/algorithms/math/bits) - set/get/update/clear bits, multiplication/division by two, make negative etc.
+ - `B` [Binary Floating Point](src/algorithms/math/binary-floating-point) - binary representation of the floating-point numbers.
+ - `B` [Factorial](src/algorithms/math/factorial)
+ - `B` [Fibonacci Number](src/algorithms/math/fibonacci) - classic and closed-form versions
+ - `B` [Prime Factors](src/algorithms/math/prime-factors) - finding prime factors and counting them using Hardy-Ramanujan's theorem
+ - `B` [Primality Test](src/algorithms/math/primality-test) (trial division method)
+ - `B` [Euclidean Algorithm](src/algorithms/math/euclidean-algorithm) - calculate the Greatest Common Divisor (GCD)
+ - `B` [Least Common Multiple](src/algorithms/math/least-common-multiple) (LCM)
+ - `B` [Sieve of Eratosthenes](src/algorithms/math/sieve-of-eratosthenes) - finding all prime numbers up to any given limit
+ - `B` [Is Power of Two](src/algorithms/math/is-power-of-two) - check if the number is power of two (naive and bitwise algorithms)
+ - `B` [Pascal's Triangle](src/algorithms/math/pascal-triangle)
+ - `B` [Complex Number](src/algorithms/math/complex-number) - complex numbers and basic operations with them
+ - `B` [Radian & Degree](src/algorithms/math/radian) - radians to degree and backwards conversion
+ - `B` [Fast Powering](src/algorithms/math/fast-powering)
+ - `B` [Horner's method](src/algorithms/math/horner-method) - polynomial evaluation
+ - `B` [Matrices](src/algorithms/math/matrix) - matrices and basic matrix operations (multiplication, transposition, etc.)
+ - `B` [Euclidean Distance](src/algorithms/math/euclidean-distance) - distance between two points/vectors/matrices
+ - `A` [Integer Partition](src/algorithms/math/integer-partition)
+ - `A` [Square Root](src/algorithms/math/square-root) - Newton's method
+ - `A` [Liu Hui π Algorithm](src/algorithms/math/liu-hui) - approximate π calculations based on N-gons
+ - `A` [Discrete Fourier Transform](src/algorithms/math/fourier-transform) - decompose a function of time (a signal) into the frequencies that make it up
+- **Sets**
+ - `B` [Cartesian Product](src/algorithms/sets/cartesian-product) - product of multiple sets
+ - `B` [Fisher–Yates Shuffle](src/algorithms/sets/fisher-yates) - random permutation of a finite sequence
+ - `A` [Power Set](src/algorithms/sets/power-set) - all subsets of a set (bitwise and backtracking solutions)
+ - `A` [Permutations](src/algorithms/sets/permutations) (with and without repetitions)
+ - `A` [Combinations](src/algorithms/sets/combinations) (with and without repetitions)
+ - `A` [Longest Common Subsequence](src/algorithms/sets/longest-common-subsequence) (LCS)
+ - `A` [Longest Increasing Subsequence](src/algorithms/sets/longest-increasing-subsequence)
+ - `A` [Shortest Common Supersequence](src/algorithms/sets/shortest-common-supersequence) (SCS)
+ - `A` [Knapsack Problem](src/algorithms/sets/knapsack-problem) - "0/1" and "Unbound" ones
+ - `A` [Maximum Subarray](src/algorithms/sets/maximum-subarray) - "Brute Force" and "Dynamic Programming" (Kadane's) versions
+ - `A` [Combination Sum](src/algorithms/sets/combination-sum) - find all combinations that form specific sum
+- **Strings**
+ - `B` [Hamming Distance](src/algorithms/string/hamming-distance) - number of positions at which the symbols are different
+ - `A` [Levenshtein Distance](src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
+ - `A` [Knuth–Morris–Pratt Algorithm](src/algorithms/string/knuth-morris-pratt) (KMP Algorithm) - substring search (pattern matching)
+ - `A` [Z Algorithm](src/algorithms/string/z-algorithm) - substring search (pattern matching)
+ - `A` [Rabin Karp Algorithm](src/algorithms/string/rabin-karp) - substring search
+ - `A` [Longest Common Substring](src/algorithms/string/longest-common-substring)
+ - `A` [Regular Expression Matching](src/algorithms/string/regular-expression-matching)
+- **Searches**
+ - `B` [Linear Search](src/algorithms/search/linear-search)
+ - `B` [Jump Search](src/algorithms/search/jump-search) (or Block Search) - search in sorted array
+ - `B` [Binary Search](src/algorithms/search/binary-search) - search in sorted array
+ - `B` [Interpolation Search](src/algorithms/search/interpolation-search) - search in uniformly distributed sorted array
+- **Sorting**
+ - `B` [Bubble Sort](src/algorithms/sorting/bubble-sort)
+ - `B` [Selection Sort](src/algorithms/sorting/selection-sort)
+ - `B` [Insertion Sort](src/algorithms/sorting/insertion-sort)
+ - `B` [Heap Sort](src/algorithms/sorting/heap-sort)
+ - `B` [Merge Sort](src/algorithms/sorting/merge-sort)
+ - `B` [Quicksort](src/algorithms/sorting/quick-sort) - in-place and non-in-place implementations
+ - `B` [Shellsort](src/algorithms/sorting/shell-sort)
+ - `B` [Counting Sort](src/algorithms/sorting/counting-sort)
+ - `B` [Radix Sort](src/algorithms/sorting/radix-sort)
+ - `B` [Pancake Sort](src/algorithms/sorting/pancake-sort)
+- **Linked Lists**
+ - `B` [Straight Traversal](src/algorithms/linked-list/traversal)
+ - `B` [Reverse Traversal](src/algorithms/linked-list/reverse-traversal)
+- **Trees**
+ - `B` [Depth-First Search](src/algorithms/tree/depth-first-search) (DFS)
+ - `B` [Breadth-First Search](src/algorithms/tree/breadth-first-search) (BFS)
+- **Graphs**
+ - `B` [Depth-First Search](src/algorithms/graph/depth-first-search) (DFS)
+ - `B` [Breadth-First Search](src/algorithms/graph/breadth-first-search) (BFS)
+ - `B` [Kruskal’s Algorithm](src/algorithms/graph/kruskal) - finding Minimum Spanning Tree (MST) for weighted undirected graph
+ - `A` [Dijkstra Algorithm](src/algorithms/graph/dijkstra) - finding the shortest paths to all graph vertices from single vertex
+ - `A` [Bellman-Ford Algorithm](src/algorithms/graph/bellman-ford) - finding the shortest paths to all graph vertices from single vertex
+ - `A` [Floyd-Warshall Algorithm](src/algorithms/graph/floyd-warshall) - find the shortest paths between all pairs of vertices
+ - `A` [Detect Cycle](src/algorithms/graph/detect-cycle) - for both directed and undirected graphs (DFS and Disjoint Set based versions)
+ - `A` [Prim’s Algorithm](src/algorithms/graph/prim) - finding Minimum Spanning Tree (MST) for weighted undirected graph
+ - `A` [Topological Sorting](src/algorithms/graph/topological-sorting) - DFS method
+ - `A` [Articulation Points](src/algorithms/graph/articulation-points) - Tarjan's algorithm (DFS based)
+ - `A` [Bridges](src/algorithms/graph/bridges) - DFS based algorithm
+ - `A` [Eulerian Path and Eulerian Circuit](src/algorithms/graph/eulerian-path) - Fleury's algorithm - Visit every edge exactly once
+ - `A` [Hamiltonian Cycle](src/algorithms/graph/hamiltonian-cycle) - Visit every vertex exactly once
+ - `A` [Strongly Connected Components](src/algorithms/graph/strongly-connected-components) - Kosaraju's algorithm
+ - `A` [Travelling Salesman Problem](src/algorithms/graph/travelling-salesman) - shortest possible route that visits each city and returns to the origin city
+- **Cryptography**
+ - `B` [Polynomial Hash](src/algorithms/cryptography/polynomial-hash) - rolling hash function based on polynomial
+ - `B` [Rail Fence Cipher](src/algorithms/cryptography/rail-fence-cipher) - a transposition cipher algorithm for encoding messages
+ - `B` [Caesar Cipher](src/algorithms/cryptography/caesar-cipher) - simple substitution cipher
+ - `B` [Hill Cipher](src/algorithms/cryptography/hill-cipher) - substitution cipher based on linear algebra
+- **Machine Learning**
+ - `B` [NanoNeuron](https://github.com/trekhleb/nano-neuron) - 7 simple JS functions that illustrate how machines can actually learn (forward/backward propagation)
+ - `B` [k-NN](src/algorithms/ml/knn) - k-nearest neighbors classification algorithm
+ - `B` [k-Means](src/algorithms/ml/k-means) - k-Means clustering algorithm
+- **Image Processing**
+ - `B` [Seam Carving](src/algorithms/image-processing/seam-carving) - content-aware image resizing algorithm
+- **Uncategorized**
+ - `B` [Tower of Hanoi](src/algorithms/uncategorized/hanoi-tower)
+ - `B` [Square Matrix Rotation](src/algorithms/uncategorized/square-matrix-rotation) - in-place algorithm
+ - `B` [Jump Game](src/algorithms/uncategorized/jump-game) - backtracking, dynamic programming (top-down + bottom-up) and greedy examples
+ - `B` [Unique Paths](src/algorithms/uncategorized/unique-paths) - backtracking, dynamic programming and Pascal's Triangle based examples
+ - `B` [Rain Terraces](src/algorithms/uncategorized/rain-terraces) - trapping rain water problem (dynamic programming and brute force versions)
+ - `B` [Recursive Staircase](src/algorithms/uncategorized/recursive-staircase) - count the number of ways to reach to the top (4 solutions)
+ - `B` [Best Time To Buy Sell Stocks](src/algorithms/uncategorized/best-time-to-buy-sell-stocks) - divide and conquer and one-pass examples
+ - `A` [N-Queens Problem](src/algorithms/uncategorized/n-queens)
+ - `A` [Knight's Tour](src/algorithms/uncategorized/knight-tour)
### Algorithms by Paradigm
@@ -173,67 +174,67 @@ An algorithmic paradigm is a generic method or approach which underlies the desi
of algorithms. It is an abstraction higher than the notion of an algorithm, just as an
algorithm is an abstraction higher than a computer program.
-* **Brute Force** - look at all the possibilities and selects the best solution
- * `B` [Linear Search](src/algorithms/search/linear-search)
- * `B` [Rain Terraces](src/algorithms/uncategorized/rain-terraces) - trapping rain water problem
- * `B` [Recursive Staircase](src/algorithms/uncategorized/recursive-staircase) - count the number of ways to reach to the top
- * `A` [Maximum Subarray](src/algorithms/sets/maximum-subarray)
- * `A` [Travelling Salesman Problem](src/algorithms/graph/travelling-salesman) - shortest possible route that visits each city and returns to the origin city
- * `A` [Discrete Fourier Transform](src/algorithms/math/fourier-transform) - decompose a function of time (a signal) into the frequencies that make it up
-* **Greedy** - choose the best option at the current time, without any consideration for the future
- * `B` [Jump Game](src/algorithms/uncategorized/jump-game)
- * `A` [Unbound Knapsack Problem](src/algorithms/sets/knapsack-problem)
- * `A` [Dijkstra Algorithm](src/algorithms/graph/dijkstra) - finding the shortest path to all graph vertices
- * `A` [Prim’s Algorithm](src/algorithms/graph/prim) - finding Minimum Spanning Tree (MST) for weighted undirected graph
- * `A` [Kruskal’s Algorithm](src/algorithms/graph/kruskal) - finding Minimum Spanning Tree (MST) for weighted undirected graph
-* **Divide and Conquer** - divide the problem into smaller parts and then solve those parts
- * `B` [Binary Search](src/algorithms/search/binary-search)
- * `B` [Tower of Hanoi](src/algorithms/uncategorized/hanoi-tower)
- * `B` [Pascal's Triangle](src/algorithms/math/pascal-triangle)
- * `B` [Euclidean Algorithm](src/algorithms/math/euclidean-algorithm) - calculate the Greatest Common Divisor (GCD)
- * `B` [Merge Sort](src/algorithms/sorting/merge-sort)
- * `B` [Quicksort](src/algorithms/sorting/quick-sort)
- * `B` [Tree Depth-First Search](src/algorithms/tree/depth-first-search) (DFS)
- * `B` [Graph Depth-First Search](src/algorithms/graph/depth-first-search) (DFS)
- * `B` [Matrices](src/algorithms/math/matrix) - generating and traversing the matrices of different shapes
- * `B` [Jump Game](src/algorithms/uncategorized/jump-game)
- * `B` [Fast Powering](src/algorithms/math/fast-powering)
- * `B` [Best Time To Buy Sell Stocks](src/algorithms/uncategorized/best-time-to-buy-sell-stocks) - divide and conquer and one-pass examples
- * `A` [Permutations](src/algorithms/sets/permutations) (with and without repetitions)
- * `A` [Combinations](src/algorithms/sets/combinations) (with and without repetitions)
-* **Dynamic Programming** - build up a solution using previously found sub-solutions
- * `B` [Fibonacci Number](src/algorithms/math/fibonacci)
- * `B` [Jump Game](src/algorithms/uncategorized/jump-game)
- * `B` [Unique Paths](src/algorithms/uncategorized/unique-paths)
- * `B` [Rain Terraces](src/algorithms/uncategorized/rain-terraces) - trapping rain water problem
- * `B` [Recursive Staircase](src/algorithms/uncategorized/recursive-staircase) - count the number of ways to reach to the top
- * `B` [Seam Carving](src/algorithms/image-processing/seam-carving) - content-aware image resizing algorithm
- * `A` [Levenshtein Distance](src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
- * `A` [Longest Common Subsequence](src/algorithms/sets/longest-common-subsequence) (LCS)
- * `A` [Longest Common Substring](src/algorithms/string/longest-common-substring)
- * `A` [Longest Increasing Subsequence](src/algorithms/sets/longest-increasing-subsequence)
- * `A` [Shortest Common Supersequence](src/algorithms/sets/shortest-common-supersequence)
- * `A` [0/1 Knapsack Problem](src/algorithms/sets/knapsack-problem)
- * `A` [Integer Partition](src/algorithms/math/integer-partition)
- * `A` [Maximum Subarray](src/algorithms/sets/maximum-subarray)
- * `A` [Bellman-Ford Algorithm](src/algorithms/graph/bellman-ford) - finding the shortest path to all graph vertices
- * `A` [Floyd-Warshall Algorithm](src/algorithms/graph/floyd-warshall) - find the shortest paths between all pairs of vertices
- * `A` [Regular Expression Matching](src/algorithms/string/regular-expression-matching)
-* **Backtracking** - similarly to brute force, try to generate all possible solutions, but each time you generate next solution you test
-if it satisfies all conditions, and only then continue generating subsequent solutions. Otherwise, backtrack, and go on a
-different path of finding a solution. Normally the DFS traversal of state-space is being used.
- * `B` [Jump Game](src/algorithms/uncategorized/jump-game)
- * `B` [Unique Paths](src/algorithms/uncategorized/unique-paths)
- * `B` [Power Set](src/algorithms/sets/power-set) - all subsets of a set
- * `A` [Hamiltonian Cycle](src/algorithms/graph/hamiltonian-cycle) - Visit every vertex exactly once
- * `A` [N-Queens Problem](src/algorithms/uncategorized/n-queens)
- * `A` [Knight's Tour](src/algorithms/uncategorized/knight-tour)
- * `A` [Combination Sum](src/algorithms/sets/combination-sum) - find all combinations that form specific sum
-* **Branch & Bound** - remember the lowest-cost solution found at each stage of the backtracking
-search, and use the cost of the lowest-cost solution found so far as a lower bound on the cost of
-a least-cost solution to the problem, in order to discard partial solutions with costs larger than the
-lowest-cost solution found so far. Normally BFS traversal in combination with DFS traversal of state-space
-tree is being used.
+- **Brute Force** - look at all the possibilities and selects the best solution
+ - `B` [Linear Search](src/algorithms/search/linear-search)
+ - `B` [Rain Terraces](src/algorithms/uncategorized/rain-terraces) - trapping rain water problem
+ - `B` [Recursive Staircase](src/algorithms/uncategorized/recursive-staircase) - count the number of ways to reach to the top
+ - `A` [Maximum Subarray](src/algorithms/sets/maximum-subarray)
+ - `A` [Travelling Salesman Problem](src/algorithms/graph/travelling-salesman) - shortest possible route that visits each city and returns to the origin city
+ - `A` [Discrete Fourier Transform](src/algorithms/math/fourier-transform) - decompose a function of time (a signal) into the frequencies that make it up
+- **Greedy** - choose the best option at the current time, without any consideration for the future
+ - `B` [Jump Game](src/algorithms/uncategorized/jump-game)
+ - `A` [Unbound Knapsack Problem](src/algorithms/sets/knapsack-problem)
+ - `A` [Dijkstra Algorithm](src/algorithms/graph/dijkstra) - finding the shortest path to all graph vertices
+ - `A` [Prim’s Algorithm](src/algorithms/graph/prim) - finding Minimum Spanning Tree (MST) for weighted undirected graph
+ - `A` [Kruskal’s Algorithm](src/algorithms/graph/kruskal) - finding Minimum Spanning Tree (MST) for weighted undirected graph
+- **Divide and Conquer** - divide the problem into smaller parts and then solve those parts
+ - `B` [Binary Search](src/algorithms/search/binary-search)
+ - `B` [Tower of Hanoi](src/algorithms/uncategorized/hanoi-tower)
+ - `B` [Pascal's Triangle](src/algorithms/math/pascal-triangle)
+ - `B` [Euclidean Algorithm](src/algorithms/math/euclidean-algorithm) - calculate the Greatest Common Divisor (GCD)
+ - `B` [Merge Sort](src/algorithms/sorting/merge-sort)
+ - `B` [Quicksort](src/algorithms/sorting/quick-sort)
+ - `B` [Tree Depth-First Search](src/algorithms/tree/depth-first-search) (DFS)
+ - `B` [Graph Depth-First Search](src/algorithms/graph/depth-first-search) (DFS)
+ - `B` [Matrices](src/algorithms/math/matrix) - generating and traversing the matrices of different shapes
+ - `B` [Jump Game](src/algorithms/uncategorized/jump-game)
+ - `B` [Fast Powering](src/algorithms/math/fast-powering)
+ - `B` [Best Time To Buy Sell Stocks](src/algorithms/uncategorized/best-time-to-buy-sell-stocks) - divide and conquer and one-pass examples
+ - `A` [Permutations](src/algorithms/sets/permutations) (with and without repetitions)
+ - `A` [Combinations](src/algorithms/sets/combinations) (with and without repetitions)
+- **Dynamic Programming** - build up a solution using previously found sub-solutions
+ - `B` [Fibonacci Number](src/algorithms/math/fibonacci)
+ - `B` [Jump Game](src/algorithms/uncategorized/jump-game)
+ - `B` [Unique Paths](src/algorithms/uncategorized/unique-paths)
+ - `B` [Rain Terraces](src/algorithms/uncategorized/rain-terraces) - trapping rain water problem
+ - `B` [Recursive Staircase](src/algorithms/uncategorized/recursive-staircase) - count the number of ways to reach to the top
+ - `B` [Seam Carving](src/algorithms/image-processing/seam-carving) - content-aware image resizing algorithm
+ - `A` [Levenshtein Distance](src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
+ - `A` [Longest Common Subsequence](src/algorithms/sets/longest-common-subsequence) (LCS)
+ - `A` [Longest Common Substring](src/algorithms/string/longest-common-substring)
+ - `A` [Longest Increasing Subsequence](src/algorithms/sets/longest-increasing-subsequence)
+ - `A` [Shortest Common Supersequence](src/algorithms/sets/shortest-common-supersequence)
+ - `A` [0/1 Knapsack Problem](src/algorithms/sets/knapsack-problem)
+ - `A` [Integer Partition](src/algorithms/math/integer-partition)
+ - `A` [Maximum Subarray](src/algorithms/sets/maximum-subarray)
+ - `A` [Bellman-Ford Algorithm](src/algorithms/graph/bellman-ford) - finding the shortest path to all graph vertices
+ - `A` [Floyd-Warshall Algorithm](src/algorithms/graph/floyd-warshall) - find the shortest paths between all pairs of vertices
+ - `A` [Regular Expression Matching](src/algorithms/string/regular-expression-matching)
+- **Backtracking** - similarly to brute force, try to generate all possible solutions, but each time you generate next solution you test
+ if it satisfies all conditions, and only then continue generating subsequent solutions. Otherwise, backtrack, and go on a
+ different path of finding a solution. Normally the DFS traversal of state-space is being used.
+ - `B` [Jump Game](src/algorithms/uncategorized/jump-game)
+ - `B` [Unique Paths](src/algorithms/uncategorized/unique-paths)
+ - `B` [Power Set](src/algorithms/sets/power-set) - all subsets of a set
+ - `A` [Hamiltonian Cycle](src/algorithms/graph/hamiltonian-cycle) - Visit every vertex exactly once
+ - `A` [N-Queens Problem](src/algorithms/uncategorized/n-queens)
+ - `A` [Knight's Tour](src/algorithms/uncategorized/knight-tour)
+ - `A` [Combination Sum](src/algorithms/sets/combination-sum) - find all combinations that form specific sum
+- **Branch & Bound** - remember the lowest-cost solution found at each stage of the backtracking
+ search, and use the cost of the lowest-cost solution found so far as a lower bound on the cost of
+ a least-cost solution to the problem, in order to discard partial solutions with costs larger than the
+ lowest-cost solution found so far. Normally BFS traversal in combination with DFS traversal of state-space
+ tree is being used.
## How to use this repository
@@ -291,7 +292,7 @@ npm test -- 'playground'
### Big O Notation
-*Big O notation* is used to classify algorithms according to how their running time or space requirements grow as the input size grows.
+_Big O notation_ is used to classify algorithms according to how their running time or space requirements grow as the input size grows.
On the chart below you may find most common orders of growth of algorithms specified in Big O notation.

@@ -300,44 +301,44 @@ Source: [Big O Cheat Sheet](http://bigocheatsheet.com/).
Below is the list of some of the most used Big O notations and their performance comparisons against different sizes of the input data.
-| Big O Notation | Computations for 10 elements | Computations for 100 elements | Computations for 1000 elements |
-| -------------- | ---------------------------- | ----------------------------- | ------------------------------- |
-| **O(1)** | 1 | 1 | 1 |
-| **O(log N)** | 3 | 6 | 9 |
-| **O(N)** | 10 | 100 | 1000 |
-| **O(N log N)** | 30 | 600 | 9000 |
-| **O(N^2)** | 100 | 10000 | 1000000 |
-| **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 |
-| **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 |
+| Big O Notation | Computations for 10 elements | Computations for 100 elements | Computations for 1000 elements |
+| -------------- | ---------------------------- | ----------------------------- | ------------------------------ |
+| **O(1)** | 1 | 1 | 1 |
+| **O(log N)** | 3 | 6 | 9 |
+| **O(N)** | 10 | 100 | 1000 |
+| **O(N log N)** | 30 | 600 | 9000 |
+| **O(N^2)** | 100 | 10000 | 1000000 |
+| **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 |
+| **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 |
### Data Structure Operations Complexity
-| Data Structure | Access | Search | Insertion | Deletion | Comments |
-| ----------------------- | :-------: | :-------: | :-------: | :-------: | :-------- |
-| **Array** | 1 | n | n | n | |
-| **Stack** | n | n | 1 | 1 | |
-| **Queue** | n | n | 1 | 1 | |
-| **Linked List** | n | n | 1 | n | |
-| **Hash Table** | - | n | n | n | In case of perfect hash function costs would be O(1) |
-| **Binary Search Tree** | n | n | n | n | In case of balanced tree costs would be O(log(n)) |
-| **B-Tree** | log(n) | log(n) | log(n) | log(n) | |
-| **Red-Black Tree** | log(n) | log(n) | log(n) | log(n) | |
-| **AVL Tree** | log(n) | log(n) | log(n) | log(n) | |
-| **Bloom Filter** | - | 1 | 1 | - | False positives are possible while searching |
+| Data Structure | Access | Search | Insertion | Deletion | Comments |
+| ---------------------- | :----: | :----: | :-------: | :------: | :--------------------------------------------------- |
+| **Array** | 1 | n | n | n | |
+| **Stack** | n | n | 1 | 1 | |
+| **Queue** | n | n | 1 | 1 | |
+| **Linked List** | n | n | 1 | n | |
+| **Hash Table** | - | n | n | n | In case of perfect hash function costs would be O(1) |
+| **Binary Search Tree** | n | n | n | n | In case of balanced tree costs would be O(log(n)) |
+| **B-Tree** | log(n) | log(n) | log(n) | log(n) | |
+| **Red-Black Tree** | log(n) | log(n) | log(n) | log(n) | |
+| **AVL Tree** | log(n) | log(n) | log(n) | log(n) | |
+| **Bloom Filter** | - | 1 | 1 | - | False positives are possible while searching |
### Array Sorting Algorithms Complexity
-| Name | Best | Average | Worst | Memory | Stable | Comments |
-| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
-| **Bubble sort** | n | n2 | n2 | 1 | Yes | |
-| **Insertion sort** | n | n2 | n2 | 1 | Yes | |
-| **Selection sort** | n2 | n2 | n2 | 1 | No | |
-| **Heap sort** | n log(n) | n log(n) | n log(n) | 1 | No | |
-| **Merge sort** | n log(n) | n log(n) | n log(n) | n | Yes | |
-| **Quick sort** | n log(n) | n log(n) | n2 | log(n) | No | Quicksort is usually done in-place with O(log(n)) stack space |
-| **Shell sort** | n log(n) | depends on gap sequence | n (log(n))2 | 1 | No | |
-| **Counting sort** | n + r | n + r | n + r | n + r | Yes | r - biggest number in array |
-| **Radix sort** | n * k | n * k | n * k | n + k | Yes | k - length of longest key |
+| Name | Best | Average | Worst | Memory | Stable | Comments |
+| ------------------ | :-----------: | :---------------------: | :-------------------------: | :----: | :----: | :------------------------------------------------------------ |
+| **Bubble sort** | n | n2 | n2 | 1 | Yes | |
+| **Insertion sort** | n | n2 | n2 | 1 | Yes | |
+| **Selection sort** | n2 | n2 | n2 | 1 | No | |
+| **Heap sort** | n log(n) | n log(n) | n log(n) | 1 | No | |
+| **Merge sort** | n log(n) | n log(n) | n log(n) | n | Yes | |
+| **Quick sort** | n log(n) | n log(n) | n2 | log(n) | No | Quicksort is usually done in-place with O(log(n)) stack space |
+| **Shell sort** | n log(n) | depends on gap sequence | n (log(n))2 | 1 | No | |
+| **Counting sort** | n + r | n + r | n + r | n + r | Yes | r - biggest number in array |
+| **Radix sort** | n \* k | n \* k | n \* k | n + k | Yes | k - length of longest key |
## Project Backers
diff --git a/package-lock.json b/package-lock.json
index 93de7f66c9..9764a184d9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -26,7 +26,6 @@
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",
"integrity": "sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g==",
- "dev": true,
"requires": {
"@babel/highlight": "^7.12.13"
}
@@ -92,11 +91,35 @@
}
}
},
+ "@babel/eslint-parser": {
+ "version": "7.15.0",
+ "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.15.0.tgz",
+ "integrity": "sha512-+gSPtjSBxOZz4Uh8Ggqu7HbfpB8cT1LwW0DnVVLZEJvzXauiD0Di3zszcBkRmfGGrLdYeHUwcflG7i3tr9kQlw==",
+ "dev": true,
+ "requires": {
+ "eslint-scope": "^5.1.1",
+ "eslint-visitor-keys": "^2.1.0",
+ "semver": "^6.3.0"
+ },
+ "dependencies": {
+ "eslint-visitor-keys": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz",
+ "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==",
+ "dev": true
+ },
+ "semver": {
+ "version": "6.3.0",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+ "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+ "dev": true
+ }
+ }
+ },
"@babel/generator": {
"version": "7.13.9",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.13.9.tgz",
"integrity": "sha512-mHOOmY0Axl/JCTkxTU6Lf5sWOg/v8nUa+Xkt4zMTftX0wqmb6Sh7J8gvcehBw7q0AhrhAR+FDacKjCZ2X8K+Sw==",
- "dev": true,
"requires": {
"@babel/types": "^7.13.0",
"jsesc": "^2.5.1",
@@ -178,7 +201,6 @@
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.12.13.tgz",
"integrity": "sha512-TZvmPn0UOqmvi5G4vvw0qZTpVptGkB1GL61R6lKvrSdIxGm5Pky7Q3fpKiIkQCAtRCBUwB0PaThlx9vebCDSwA==",
- "dev": true,
"requires": {
"@babel/helper-get-function-arity": "^7.12.13",
"@babel/template": "^7.12.13",
@@ -189,7 +211,6 @@
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.12.13.tgz",
"integrity": "sha512-DjEVzQNz5LICkzN0REdpD5prGoidvbdYk1BVgRUOINaWJP2t6avB27X1guXK1kXNrX0WMfsrm1A/ZBthYuIMQg==",
- "dev": true,
"requires": {
"@babel/types": "^7.12.13"
}
@@ -298,7 +319,6 @@
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.12.13.tgz",
"integrity": "sha512-tCJDltF83htUtXx5NLcaDqRmknv652ZWCHyoTETf1CXYJdPC7nohZohjUgieXhv0hTJdRf2FjDueFehdNucpzg==",
- "dev": true,
"requires": {
"@babel/types": "^7.12.13"
}
@@ -306,8 +326,7 @@
"@babel/helper-validator-identifier": {
"version": "7.12.11",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz",
- "integrity": "sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw==",
- "dev": true
+ "integrity": "sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw=="
},
"@babel/helper-validator-option": {
"version": "7.12.17",
@@ -342,7 +361,6 @@
"version": "7.13.10",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.13.10.tgz",
"integrity": "sha512-5aPpe5XQPzflQrFwL1/QoeHkP2MsA4JCntcXHRhEsdsfPVkvPi2w7Qix4iV7t5S/oC9OodGrggd8aco1g3SZFg==",
- "dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.12.11",
"chalk": "^2.0.0",
@@ -352,8 +370,7 @@
"@babel/parser": {
"version": "7.13.15",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.13.15.tgz",
- "integrity": "sha512-b9COtcAlVEQljy/9fbcMHpG+UIW9ReF+gpaxDHTlZd0c6/UU9ng8zdySAW9sRTzpvcdCHn6bUcbuYUgGzLAWVQ==",
- "dev": true
+ "integrity": "sha512-b9COtcAlVEQljy/9fbcMHpG+UIW9ReF+gpaxDHTlZd0c6/UU9ng8zdySAW9sRTzpvcdCHn6bUcbuYUgGzLAWVQ=="
},
"@babel/plugin-proposal-async-generator-functions": {
"version": "7.13.15",
@@ -1038,7 +1055,6 @@
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.12.13.tgz",
"integrity": "sha512-/7xxiGA57xMo/P2GVvdEumr8ONhFOhfgq2ihK3h1e6THqzTAkHbkXgB0xI9yeTfIUoH3+oAeHhqm/I43OTbbjA==",
- "dev": true,
"requires": {
"@babel/code-frame": "^7.12.13",
"@babel/parser": "^7.12.13",
@@ -1049,7 +1065,6 @@
"version": "7.13.15",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.13.15.tgz",
"integrity": "sha512-/mpZMNvj6bce59Qzl09fHEs8Bt8NnpEDQYleHUPZQ3wXUMvXi+HJPLars68oAbmp839fGoOkv2pSL2z9ajCIaQ==",
- "dev": true,
"requires": {
"@babel/code-frame": "^7.12.13",
"@babel/generator": "^7.13.9",
@@ -1065,7 +1080,6 @@
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
- "dev": true,
"requires": {
"ms": "2.1.2"
}
@@ -1073,8 +1087,7 @@
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
- "dev": true
+ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
@@ -1082,7 +1095,6 @@
"version": "7.13.14",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.13.14.tgz",
"integrity": "sha512-A2aa3QTkWoyqsZZFl56MLUsfmh7O0gN41IPvXAE/++8ojpbz12SszD7JEGYVdn4f9Kt4amIei07swF1h4AqmmQ==",
- "dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.12.11",
"lodash": "^4.17.19",
@@ -1124,9 +1136,9 @@
},
"dependencies": {
"debug": {
- "version": "4.3.1",
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
- "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
+ "version": "4.3.2",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
+ "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"dev": true,
"requires": {
"ms": "2.1.2"
@@ -2135,9 +2147,9 @@
}
},
"acorn-jsx": {
- "version": "5.3.1",
- "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz",
- "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==",
+ "version": "5.3.2",
+ "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz",
+ "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
"dev": true
},
"acorn-walk": {
@@ -2191,7 +2203,6 @@
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
- "dev": true,
"requires": {
"color-convert": "^1.9.0"
}
@@ -2394,6 +2405,26 @@
"integrity": "sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA==",
"dev": true
},
+ "babel-eslint": {
+ "version": "10.1.0",
+ "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz",
+ "integrity": "sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==",
+ "requires": {
+ "@babel/code-frame": "^7.0.0",
+ "@babel/parser": "^7.7.0",
+ "@babel/traverse": "^7.7.0",
+ "@babel/types": "^7.7.0",
+ "eslint-visitor-keys": "^1.0.0",
+ "resolve": "^1.12.0"
+ },
+ "dependencies": {
+ "eslint-visitor-keys": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz",
+ "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ=="
+ }
+ }
+ },
"babel-jest": {
"version": "26.6.3",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-26.6.3.tgz",
@@ -2756,7 +2787,6 @@
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
- "dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
@@ -2985,7 +3015,6 @@
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
- "dev": true,
"requires": {
"color-name": "1.1.3"
}
@@ -2993,8 +3022,7 @@
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
- "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
- "dev": true
+ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"colorette": {
"version": "1.2.2",
@@ -3428,8 +3456,7 @@
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
- "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
- "dev": true
+ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"escodegen": {
"version": "2.0.0",
@@ -3553,9 +3580,9 @@
}
},
"chalk": {
- "version": "4.1.0",
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
- "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
+ "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
@@ -3578,9 +3605,9 @@
"dev": true
},
"debug": {
- "version": "4.3.1",
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
- "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
+ "version": "4.3.2",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
+ "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"dev": true,
"requires": {
"ms": "2.1.2"
@@ -4308,9 +4335,9 @@
}
},
"flatted": {
- "version": "3.1.1",
- "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.1.1.tgz",
- "integrity": "sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA==",
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.2.tgz",
+ "integrity": "sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==",
"dev": true
},
"for-in": {
@@ -4376,8 +4403,7 @@
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
- "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
- "dev": true
+ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"functional-red-black-tree": {
"version": "1.0.1",
@@ -4494,8 +4520,7 @@
"globals": {
"version": "11.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
- "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==",
- "dev": true
+ "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA=="
},
"globby": {
"version": "11.0.3",
@@ -4558,7 +4583,6 @@
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
- "dev": true,
"requires": {
"function-bind": "^1.1.1"
}
@@ -4572,8 +4596,7 @@
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
- "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
- "dev": true
+ "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"has-symbols": {
"version": "1.0.2",
@@ -4882,7 +4905,6 @@
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz",
"integrity": "sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==",
- "dev": true,
"requires": {
"has": "^1.0.3"
}
@@ -6729,8 +6751,7 @@
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
- "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
- "dev": true
+ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
},
"js-yaml": {
"version": "3.14.1",
@@ -6793,8 +6814,7 @@
"jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
- "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
- "dev": true
+ "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA=="
},
"json-parse-even-better-errors": {
"version": "2.3.1",
@@ -6939,8 +6959,7 @@
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
- "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
- "dev": true
+ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"lodash.clonedeep": {
"version": "4.5.0",
@@ -6948,12 +6967,6 @@
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=",
"dev": true
},
- "lodash.flatten": {
- "version": "4.4.0",
- "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz",
- "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=",
- "dev": true
- },
"lodash.truncate": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.truncate/-/lodash.truncate-4.4.2.tgz",
@@ -7642,8 +7655,7 @@
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
- "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
- "dev": true
+ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw=="
},
"path-type": {
"version": "2.0.0",
@@ -7940,9 +7952,9 @@
}
},
"regexpp": {
- "version": "3.1.0",
- "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz",
- "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==",
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz",
+ "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==",
"dev": true
},
"regexpu-core": {
@@ -8100,7 +8112,6 @@
"version": "1.20.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz",
"integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==",
- "dev": true,
"requires": {
"is-core-module": "^2.2.0",
"path-parse": "^1.0.6"
@@ -8480,8 +8491,7 @@
"source-map": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
- "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
- "dev": true
+ "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w="
},
"source-map-resolve": {
"version": "0.5.3",
@@ -8749,7 +8759,6 @@
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
- "dev": true,
"requires": {
"has-flag": "^3.0.0"
}
@@ -8788,26 +8797,23 @@
"dev": true
},
"table": {
- "version": "6.3.0",
- "resolved": "https://registry.npmjs.org/table/-/table-6.3.0.tgz",
- "integrity": "sha512-gM9kB7aNIuSagW89Fh+SdL49uhKnVSORxMcV72u/dfptFdqExInNn5M21wgq/Uf5UdJpsboFhNe/0SoNKjaxzg==",
+ "version": "6.7.1",
+ "resolved": "https://registry.npmjs.org/table/-/table-6.7.1.tgz",
+ "integrity": "sha512-ZGum47Yi6KOOFDE8m223td53ath2enHcYLgOCjGr5ngu8bdIARQk6mN/wRMv4yMRcHnCSnHbCEha4sobQx5yWg==",
"dev": true,
"requires": {
"ajv": "^8.0.1",
- "is-boolean-object": "^1.1.0",
- "is-number-object": "^1.0.4",
- "is-string": "^1.0.5",
"lodash.clonedeep": "^4.5.0",
- "lodash.flatten": "^4.4.0",
"lodash.truncate": "^4.4.2",
"slice-ansi": "^4.0.0",
- "string-width": "^4.2.0"
+ "string-width": "^4.2.0",
+ "strip-ansi": "^6.0.0"
},
"dependencies": {
"ajv": {
- "version": "8.1.0",
- "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.1.0.tgz",
- "integrity": "sha512-B/Sk2Ix7A36fs/ZkuGLIR86EdjbgR6fsAcbx9lOP/QBSXujDNbVmIS/U4Itz5k8fPFDeVZl/zQ/gJW4Jrq6XjQ==",
+ "version": "8.6.2",
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.6.2.tgz",
+ "integrity": "sha512-9807RlWAgT564wT+DjeyU5OFMPjmzxVobvDFmNAhY+5zD6A2ly3jDp6sgnfyDtlIQ+7H97oc/DGCzzfu9rjw9w==",
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
@@ -8907,8 +8913,7 @@
"to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
- "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=",
- "dev": true
+ "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4="
},
"to-object-path": {
"version": "0.3.0",
diff --git a/package.json b/package.json
index f77d87ff50..5f453fdfea 100644
--- a/package.json
+++ b/package.json
@@ -36,10 +36,11 @@
"homepage": "https://github.com/trekhleb/javascript-algorithms#readme",
"devDependencies": {
"@babel/cli": "7.12.10",
+ "@babel/eslint-parser": "^7.15.0",
"@babel/preset-env": "7.12.11",
"@types/jest": "26.0.19",
"canvas": "^2.7.0",
- "eslint": "7.16.0",
+ "eslint": "^7.16.0",
"eslint-config-airbnb": "18.2.1",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "24.1.3",
@@ -51,5 +52,8 @@
"engines": {
"node": ">=12.0.0",
"npm": ">=6.9.0"
+ },
+ "dependencies": {
+ "babel-eslint": "^10.1.0"
}
}
diff --git a/src/algorithms/sorting/pancake-sort/PancakeSort.js b/src/algorithms/sorting/pancake-sort/PancakeSort.js
new file mode 100644
index 0000000000..52e3237d3f
--- /dev/null
+++ b/src/algorithms/sorting/pancake-sort/PancakeSort.js
@@ -0,0 +1,51 @@
+import Sort from '../Sort';
+
+export default class PancakeSort extends Sort {
+ sort(originalArray) {
+ // Clone original array to prevent its modification.
+ const arr = [...originalArray];
+
+ let n = arr.length;
+
+ while (n > 1) {
+ let max = -Infinity;
+ let maxIndex = 0;
+ let k = n;
+
+ for (let i = 0; i < k; i += 1) {
+ if (this.comparator.greaterThanOrEqual(arr[i], max)) {
+ max = arr[i];
+ maxIndex = i;
+ }
+ }
+
+ this.callbacks.visitingCallback(arr[maxIndex]);
+
+ if (maxIndex !== n - 1) {
+ let i = 0;
+ k = maxIndex;
+ while (i < k) {
+ const temp = arr[k];
+ arr[k] = arr[i];
+ arr[i] = temp;
+ i += 1;
+ k -= 1;
+ }
+
+ i = 0;
+ k = n - 1;
+
+ while (i < k) {
+ const temp = arr[k];
+ arr[k] = arr[i];
+ arr[i] = temp;
+ i += 1;
+ k -= 1;
+ }
+ }
+ n -= 1;
+ }
+
+ return arr;
+ }
+}
diff --git a/src/algorithms/sorting/pancake-sort/README.md b/src/algorithms/sorting/pancake-sort/README.md
new file mode 100644
index 0000000000..5a572f803e
--- /dev/null
+++ b/src/algorithms/sorting/pancake-sort/README.md
@@ -0,0 +1,21 @@
+# Pancake Sort
+
+Pancake sorting is the mathematical problem of sorting a disordered stack of pancakes in order of size when a spatula can be inserted at any point in the stack and used to flip all pancakes above it. A pancake number is the minimum number of flips required for a given number of pancakes.
+
+Following are the detailed steps. Let given array be arr[] and size of array be n.
+
+- Start from current size equal to n and reduce current size by one while it’s greater than 1. Let the current size be curr_size. Do following for every curr_size
+ - Find index of the maximum element in arr [0..curr_szie-1]. Let the index be ‘mi’
+ - Call flip(arr, mi)
+ - Call flip(arr, curr_size-1)
+
+## Complexity
+
+| Name | Best | Average | Worst | Memory | Stable | Comments |
+| ---------------- | :-----------: | :-----------: | :-----------: | :----: | :----: | :------- |
+| **Pancake sort** | n2 | n2 | n2 | 1 | No | |
+
+## References
+
+[Wikipedia](https://en.wikipedia.org/wiki/Pancake_sorting)
+[GeeksforGeeks](https://www.geeksforgeeks.org/pancake-sorting)
diff --git a/src/algorithms/sorting/pancake-sort/__test__/PancakeSort.test.js b/src/algorithms/sorting/pancake-sort/__test__/PancakeSort.test.js
new file mode 100644
index 0000000000..e8145b9820
--- /dev/null
+++ b/src/algorithms/sorting/pancake-sort/__test__/PancakeSort.test.js
@@ -0,0 +1,60 @@
+import PancakeSort from '../PancakeSort';
+import {
+ equalArr,
+ notSortedArr,
+ reverseArr,
+ sortedArr,
+ SortTester,
+} from '../../SortTester';
+
+// Complexity constants.
+const SORTED_ARRAY_VISITING_COUNT = 19;
+const NOT_SORTED_ARRAY_VISITING_COUNT = 19;
+const REVERSE_SORTED_ARRAY_VISITING_COUNT = 19;
+const EQUAL_ARRAY_VISITING_COUNT = 19;
+
+describe('PancakeSort', () => {
+ it('should sort array', () => {
+ SortTester.testSort(PancakeSort);
+ });
+
+ it('should sort array with custom comparator', () => {
+ SortTester.testSortWithCustomComparator(PancakeSort);
+ });
+
+ it('should sort negative numbers', () => {
+ SortTester.testNegativeNumbersSort(PancakeSort);
+ });
+
+ it('should visit EQUAL array element specified number of times', () => {
+ SortTester.testAlgorithmTimeComplexity(
+ PancakeSort,
+ equalArr,
+ EQUAL_ARRAY_VISITING_COUNT,
+ );
+ });
+
+ it('should visit SORTED array element specified number of times', () => {
+ SortTester.testAlgorithmTimeComplexity(
+ PancakeSort,
+ sortedArr,
+ SORTED_ARRAY_VISITING_COUNT,
+ );
+ });
+
+ it('should visit NOT SORTED array element specified number of times', () => {
+ SortTester.testAlgorithmTimeComplexity(
+ PancakeSort,
+ notSortedArr,
+ NOT_SORTED_ARRAY_VISITING_COUNT,
+ );
+ });
+
+ it('should visit REVERSE SORTED array element specified number of times', () => {
+ SortTester.testAlgorithmTimeComplexity(
+ PancakeSort,
+ reverseArr,
+ REVERSE_SORTED_ARRAY_VISITING_COUNT,
+ );
+ });
+});