|
| 1 | +# JavaScriptアルゴリズムとデータ構造 |
| 2 | + |
| 3 | +[](https://travis-ci.org/trekhleb/javascript-algorithms) |
| 4 | +[](https://codecov.io/gh/trekhleb/javascript-algorithms) |
| 5 | + |
| 6 | + |
| 7 | +このリポジトリには、JavaScriptベースの多数のサンプル |
| 8 | +一般的なアルゴリズムとデータ構造。 |
| 9 | + |
| 10 | +各アルゴリズムとデータ構造には独自のREADMEがあります |
| 11 | +関連する説明と、さらに読むためのリンク (関連YouTubeのビデオも含まれてい). |
| 12 | + |
| 13 | +_Read this in other languages:_ |
| 14 | +[_English_](https://github.com/trekhleb/javascript-algorithms/), |
| 15 | +[_简体中文_](README.zh-CN.md), |
| 16 | +[_繁體中文_](README.zh-TW.md), |
| 17 | +[_한국어_](README.ko-KR.md), |
| 18 | +[_Polski_](README.pl-PL.md), |
| 19 | +[_Français_](README.fr-FR.md), |
| 20 | +[_Español_](README.es-ES.md), |
| 21 | +[_Português_](README.pt-BR.md) |
| 22 | + |
| 23 | +## データ構造 |
| 24 | + |
| 25 | +データ構造は、データ値、データ値との間の関係、 |
| 26 | +そして、データを扱うことができる関数と演算の集合で、 |
| 27 | +データを特定の方法で構成して保存することで、より効率的に |
| 28 | +アクセスして変更することができます。 |
| 29 | + |
| 30 | +`B` - 初心者, `A` - 上級 |
| 31 | + |
| 32 | +* `B` [リンクされたリスト](src/data-structures/linked-list) |
| 33 | +* `B` [二重リンクリスト](src/data-structures/doubly-linked-list) |
| 34 | +* `B` [キュー](src/data-structures/queue) |
| 35 | +* `B` [スタック](src/data-structures/stack) |
| 36 | +* `B` [ハッシュ表](src/data-structures/hash-table) |
| 37 | +* `B` [ヒープ](src/data-structures/heap) - max and min heap versions |
| 38 | +* `B` [優先度キュー](src/data-structures/priority-queue) |
| 39 | +* `A` [トライ](src/data-structures/trie) |
| 40 | +* `A` [リー](src/data-structures/tree) |
| 41 | + * `A` [バイナリ検索ツリー](src/data-structures/tree/binary-search-tree) |
| 42 | + * `A` [AVLツリー](src/data-structures/tree/avl-tree) |
| 43 | + * `A` [赤黒のリー](src/data-structures/tree/red-black-tree) |
| 44 | + * `A` [セグメントツリー](src/data-structures/tree/segment-tree) - with min/max/sum range queries examples |
| 45 | + * `A` [フェンウィック・ツリー](src/data-structures/tree/fenwick-tree) (Binary Indexed Tree) |
| 46 | +* `A` [グラフ](src/data-structures/graph) (both directed and undirected) |
| 47 | +* `A` [分離集合](src/data-structures/disjoint-set) |
| 48 | +* `A` [ブルームフィルタ](src/data-structures/bloom-filter) |
| 49 | + |
| 50 | +## アルゴリズム |
| 51 | + |
| 52 | +アルゴリズムとは、問題のクラスをどのように解決するかの明確な仕様です。 |
| 53 | +一連の操作を正確に定義する一連のルールです。 |
| 54 | + |
| 55 | +`B` - 初心者, `A` - 上級 |
| 56 | + |
| 57 | +### トピック別アルゴリズム |
| 58 | + |
| 59 | +* **数学** |
| 60 | + * `B` [ビット操作](src/algorithms/math/bits) - set/get/update/clear bits, 2つの乗算/除算, 否定的にする. 等 |
| 61 | + * `B` [因果関係](src/algorithms/math/factorial) |
| 62 | + * `B` [フィボナッチ数](src/algorithms/math/fibonacci) - クラシックとクローズドフォームのバージョン |
| 63 | + * `B` [素数性テスト](src/algorithms/math/primality-test) (trial division 方法) |
| 64 | + * `B` [ユークリッドアルゴリズム](src/algorithms/math/euclidean-algorithm) - 最大公約数を計算する (GCD) |
| 65 | + * `B` [最小公倍数](src/algorithms/math/least-common-multiple) (LCM) |
| 66 | + * `B` [エラトステネスのふるい](src/algorithms/math/sieve-of-eratosthenes) - 与えられた限度まですべての素数を見つける |
| 67 | + * `B` [Is Power of Two](src/algorithms/math/is-power-of-two) - 数値が2の累乗であるかどうかを調べる(単純なアルゴリズムとビットごとのアルゴリズム) |
| 68 | + * `B` [パスカルの三角形](src/algorithms/math/pascal-triangle) |
| 69 | + * `B` [複素数](src/algorithms/math/complex-number) - 複素数とその基本演算 |
| 70 | + * `B` [ラジアン&度](src/algorithms/math/radian) - 度数と逆方向の変換に対するラジアン |
| 71 | + * `B` [高速電力供給](src/algorithms/math/fast-powering) |
| 72 | + * `A` [整数パーティション](src/algorithms/math/integer-partition) |
| 73 | + * `A` [Liu Hui π アルゴリズム](src/algorithms/math/liu-hui) - N-gonsに基づく近似π計算 |
| 74 | + * `A` [離散フーリエ変換](src/algorithms/math/fourier-transform) - 時間(信号)の関数をそれを構成する周波数に分解する |
| 75 | + * **セット** |
| 76 | + * `B` [デカルト積 ](src/algorithms/sets/cartesian-product) - 複数の積の積 |
| 77 | + * `B` [Fisher–Yates Shuffle](src/algorithms/sets/fisher-yates) - 有限シーケンスのランダム置換 |
| 78 | + * `A` [パワーセット](src/algorithms/sets/power-set) - セットのすべてのサブセット(ビットごとのソリューションとバックトラッキングソリューション) |
| 79 | + * `A` [順列](src/algorithms/sets/permutations) (繰り返しの有無にかかわらず) |
| 80 | + * `A` [組み合わせ](src/algorithms/sets/combinations) (繰返しあり、繰返しなし) |
| 81 | + * `A` [最長共通部分列](src/algorithms/sets/longest-common-subsequence) (LCS) |
| 82 | + * `A` [最長増加サブシーケンス](src/algorithms/sets/longest-increasing-subsequence) |
| 83 | + * `A` [最短共通スーパーシーケンス](src/algorithms/sets/shortest-common-supersequence) (SCS) |
| 84 | + * `A` [ナップザック問題 ](src/algorithms/sets/knapsack-problem) - 「0/1」と「非結合」問題 |
| 85 | + * `A` [最大サブアレイ](src/algorithms/sets/maximum-subarray) - 「ブルートフォース」と「ダイナミックプログラミング」(Kadane's版) |
| 86 | + * `A` [組み合わせ合計](src/algorithms/sets/combination-sum) - 特定の合計を構成するすべての組み合わせを見つける |
| 87 | + * **文字列** |
| 88 | + * `B` [ハミング距離](src/algorithms/string/hamming-distance) - シンボルが異なる位置の数 |
| 89 | + * `A` [レーベンシュタイン距離](src/algorithms/string/levenshtein-distance) - 2つのシーケンス間の最小編集距離 |
| 90 | + * `A` [Knuth-Morris-Prattアルゴリズム](src/algorithms/string/knuth-morris-pratt) (KMP Algorithm) - 部分文字列検索 (pattern matching) |
| 91 | + * `A` [Z アルゴリズム](src/algorithms/string/z-algorithm) - 部分文字列検索 (pattern matching) |
| 92 | + * `A` [Rabin Karpアルゴリズム](src/algorithms/string/rabin-karp) - 部分文字列検索 |
| 93 | + * `A` [最長共通部分文字列](src/algorithms/string/longest-common-substring) |
| 94 | + * `A` [正規表現マッチング](src/algorithms/string/regular-expression-matching) |
| 95 | + * **検索** |
| 96 | + * `B` [リニアサーチ](src/algorithms/search/linear-search) |
| 97 | + * `B` [ジャンプ検索](src/algorithms/search/jump-search) (or Block Search) - ソートされた配列で検索 |
| 98 | + * `B` [バイナリ検索](src/algorithms/search/binary-search) - ソートされた配列で検索 |
| 99 | + * `B` [補間探索](src/algorithms/search/interpolation-search) - 一様分布のソート配列で検索する |
| 100 | + * **並べ替え** |
| 101 | + * `B` [バブルソート](src/algorithms/sorting/bubble-sort) |
| 102 | + * `B` [選択ソート](src/algorithms/sorting/selection-sort) |
| 103 | + * `B` [挿入ソート](src/algorithms/sorting/insertion-sort) |
| 104 | + * `B` [ヒープソート](src/algorithms/sorting/heap-sort) |
| 105 | + * `B` [マージソート](src/algorithms/sorting/merge-sort) |
| 106 | + * `B` [クイックソート](src/algorithms/sorting/quick-sort) -インプレースおよび非インプレース・インプリメンテーション |
| 107 | + * `B` [シェルソート](src/algorithms/sorting/shell-sort) |
| 108 | + * `B` [並べ替えを数える](src/algorithms/sorting/counting-sort) |
| 109 | + * `B` [基数ソート](src/algorithms/sorting/radix-sort) |
| 110 | + * **リンクされたリスト** |
| 111 | + * `B` [ストレートトラバーサル](src/algorithms/linked-list/traversal) |
| 112 | + * `B` [逆方向のトラバーサル](src/algorithms/linked-list/reverse-traversal) |
| 113 | + * **ツリー** |
| 114 | + * `B` [深度優先検索](src/algorithms/tree/depth-first-search) (DFS) |
| 115 | + * `B` [幅優先検索](src/algorithms/tree/breadth-first-search) (BFS) |
| 116 | + * **グラフ** |
| 117 | + * `B` [深度優先検索](src/algorithms/graph/depth-first-search) (DFS) |
| 118 | + * `B` [幅優先検索](src/algorithms/graph/breadth-first-search) (BFS) |
| 119 | + * `B` [Kruskalのアルゴリズム](src/algorithms/graph/kruskal) - 重み付き無向グラフの最小スパニングツリー(MST)の発見 |
| 120 | + * `A` [Dijkstraアルゴリズム](src/algorithms/graph/dijkstra) - 単一の頂点からすべてのグラフ頂点への最短経路を見つける |
| 121 | + * `A` [Bellman-Fordアルゴリズム](src/algorithms/graph/bellman-ford) - 単一の頂点からすべてのグラフ頂点への最短経路を見つける |
| 122 | + * `A` [Floyd-Warshallアルゴリズム](src/algorithms/graph/floyd-warshall) - すべての頂点ペア間の最短経路を見つける |
| 123 | + * `A` [Detect Cycle](src/algorithms/graph/detect-cycle) - 有向グラフと無向グラフの両方(DFSおよびディスジョイントセットベースのバージョン) |
| 124 | + * `A` [プリムのアルゴリズム](src/algorithms/graph/prim) - 重み付き無向グラフの最小スパニングツリー(MST)の発見 |
| 125 | + * `A` [トポロジカルソート](src/algorithms/graph/topological-sorting) - DFSメソッド |
| 126 | + * `A` [アーティキュレーションポイント](src/algorithms/graph/articulation-points) - Tarjanのアルゴリズム(DFSベース) |
| 127 | + * `A` [ブリッジ ](src/algorithms/graph/bridges) - DFSベースのアルゴリズム |
| 128 | + * `A` [オイラーパスとオイラー回路](src/algorithms/graph/eulerian-path) - フルリーアルゴリズム - すべてのエッジを正確に1回訪問する |
| 129 | + * `A` [ハミルトニアンサイクル](src/algorithms/graph/hamiltonian-cycle) - すべての頂点を正確に1回訪問する |
| 130 | + * `A` [強連結成分](src/algorithms/graph/strongly-connected-components) - コサラジュのアルゴリズム |
| 131 | + * `A` [トラベリングセールスマン問題](src/algorithms/graph/travelling-salesman) - 各都市を訪問し、起点都市に戻る最短経路 |
| 132 | + * **暗号** |
| 133 | + * `B` [多項式ハッシュ](src/algorithms/cryptography/polynomial-hash) - 関数多項式に基づくハッシュ関数 |
| 134 | + * **未分類** |
| 135 | + * `B` [ハノイの塔](src/algorithms/uncategorized/hanoi-tower) |
| 136 | + * `B` [正方行列回転](src/algorithms/uncategorized/square-matrix-rotation) - インプレイスアルゴリズム |
| 137 | + * `B` [ジャンプゲーム](src/algorithms/uncategorized/jump-game) - バックトラック、ダイナミックプログラミング(トップダウン+ボトムアップ)、欲張りの例 |
| 138 | + * `B` [ユニークなパス](src/algorithms/uncategorized/unique-paths) - バックトラック、動的プログラミング、PascalのTriangleベースの例 |
| 139 | + * `B` [レインテラス](src/algorithms/uncategorized/rain-terraces) - トラップ雨水問題(ダイナミックプログラミングとブルートフォースバージョン) |
| 140 | + * `B` [再帰的階段](src/algorithms/uncategorized/recursive-staircase) - 上に到達する方法の数を数える(4つのソリューション) |
| 141 | + * `A` [N-クイーンズ問題](src/algorithms/uncategorized/n-queens) |
| 142 | + * `A` [ナイトツアー](src/algorithms/uncategorized/knight-tour) |
| 143 | + |
| 144 | +### Paradigmによるアルゴリズム |
| 145 | + |
| 146 | +アルゴリズムパラダイムは、あるクラスのアルゴリズムの設計の基礎をなす一般的な方法またはアプローチである。それは、アルゴリズムがコンピュータプログラムよりも高い抽象であるのと同様に、アルゴリズムの概念よりも高い抽象である。 |
| 147 | +* **ブルートフォース** - べての可能性を見て最適なソリューションを選択する |
| 148 | + * `B` [線形探索](src/algorithms/search/linear-search) |
| 149 | + * `B` [レインテラス](src/algorithms/uncategorized/rain-terraces) - 雨水問題 |
| 150 | + * `B` [Recursive Staircase](src/algorithms/uncategorized/recursive-staircase) - 先頭に到達する方法の数を数えます |
| 151 | + * `A` [最大サブアレイ](src/algorithms/sets/maximum-subarray) |
| 152 | + * `A` [旅行セールスマン問題](src/algorithms/graph/travelling-salesman) - 各都市を訪れ、起点都市に戻る最短ルート |
| 153 | + * `A` [離散フーリエ変換](src/algorithms/math/fourier-transform) - 時間(信号)の関数をそれを構成する周波数に分解する |
| 154 | +* **欲張り** - 未来を考慮することなく、現時点で最適なオプションを選択する |
| 155 | + * `B` [ジャンプゲーム](src/algorithms/uncategorized/jump-game) |
| 156 | + * `A` [結合されていないナップザック問題](src/algorithms/sets/knapsack-problem) |
| 157 | + * `A` [Dijkstra Algorithm](src/algorithms/graph/dijkstra) - すべてのグラフ頂点への最短経路を見つける |
| 158 | + * `A` [Prim’s Algorithm](src/algorithms/graph/prim) - 重み付き無向グラフの最小スパニングツリー(MST)を見つける |
| 159 | + * `A` [Kruskalのアルゴリズム](src/algorithms/graph/kruskal) - 重み付き無向グラフの最小スパニングツリー(MST)を見つける |
| 160 | +* **分割と征服** - 問題をより小さな部分に分割し、それらの部分を解決する |
| 161 | + * `B` [バイナリ検索](src/algorithms/search/binary-search) |
| 162 | + * `B` [ハノイの塔](src/algorithms/uncategorized/hanoi-tower) |
| 163 | + * `B` [パスカルの三角形](src/algorithms/math/pascal-triangle) |
| 164 | + * `B` [ユークリッドアルゴリズム](src/algorithms/math/euclidean-algorithm) - GCD(Greatest Common Divisor)を計算する |
| 165 | + * `B` [マージソート](src/algorithms/sorting/merge-sort) |
| 166 | + * `B` [クイックソート](src/algorithms/sorting/quick-sort) |
| 167 | + * `B` [ツリーの深さ優先検索](src/algorithms/tree/depth-first-search) (DFS) |
| 168 | + * `B` [グラフの深さ優先検索](src/algorithms/graph/depth-first-search) (DFS) |
| 169 | + * `B` [ジャンプゲーム](src/algorithms/uncategorized/jump-game) |
| 170 | + * `B` [高速電力供給](src/algorithms/math/fast-powering) |
| 171 | + * `A` [順列](src/algorithms/sets/permutations) (繰り返しの有無にかかわらず) |
| 172 | + * `A` [組み合わせ](src/algorithms/sets/combinations)(繰返しあり、繰返しなし) |
| 173 | +* **動的プログラミング** - 以前に発見されたサブソリューションを使用してソリューションを構築する |
| 174 | + * `B` [フィボナッチ数](src/algorithms/math/fibonacci) |
| 175 | + * `B` [ジャンプゲーム](src/algorithms/uncategorized/jump-game) |
| 176 | + * `B` [ユニークなパス](src/algorithms/uncategorized/unique-paths) |
| 177 | + * `B` [雨テラス](src/algorithms/uncategorized/rain-terraces) - トラップ雨水問題 |
| 178 | + * `B` [再帰的階段](src/algorithms/uncategorized/recursive-staircase) - 上に到達する方法の数を数える |
| 179 | + * `A` [Levenshtein Distance](src/algorithms/string/levenshtein-distance) - 2つのシーケンス間の最小編集距離 |
| 180 | + * `A` [最長共通部分列](src/algorithms/sets/longest-common-subsequence) (LCS) |
| 181 | + * `A` [最長共通部分文字列](src/algorithms/string/longest-common-substring) |
| 182 | + * `A` [最長増加サブシーケンス](src/algorithms/sets/longest-increasing-subsequence) |
| 183 | + * `A` [最短共通共通配列](src/algorithms/sets/shortest-common-supersequence) |
| 184 | + * `A` [0/1ナップザック問題](src/algorithms/sets/knapsack-problem) |
| 185 | + * `A` [整数パーティション](src/algorithms/math/integer-partition) |
| 186 | + * `A` [最大サブアレイ](src/algorithms/sets/maximum-subarray) |
| 187 | + * `A` [Bellman-Fordアルゴリズム](src/algorithms/graph/bellman-ford) - すべてのグラフ頂点への最短経路を見つける |
| 188 | + * `A` [Floyd-Warshallアルゴリズム](src/algorithms/graph/floyd-warshall) - すべての頂点ペア間の最短経路を見つける |
| 189 | + * `A` [正規表現マッチング](src/algorithms/string/regular-expression-matching) |
| 190 | + * **バックトラッキング** - ブルートフォースと同様に、可能なすべてのソリューションを生成しようとしますが、 |
| 191 | + 次のソリューションを生成するたびにすべての条件を満たすかどうかをテストし、それ以降は引き続きソリューションを生成します。 |
| 192 | + それ以外の場合は、バックトラックして、解決策を見つける別の経路に進みます。 |
| 193 | + 通常、状態空間のDFSトラバーサルが使用されています。 |
| 194 | + * `B` [ジャンプゲーム](src/algorithms/uncategorized/jump-game) |
| 195 | + * `B` [ユニークなパス](src/algorithms/uncategorized/unique-paths) |
| 196 | + * `B` [パワーセット](src/algorithms/sets/power-set) - セットのすべてのサブセット |
| 197 | + * `A` [ハミルトニアンサイクル](src/algorithms/graph/hamiltonian-cycle) - すべての頂点を正確に1回訪問する |
| 198 | + * `A` [N-クイーンズ問題](src/algorithms/uncategorized/n-queens) |
| 199 | + * `A` [ナイトツアー](src/algorithms/uncategorized/knight-tour) |
| 200 | + * `A` [組み合わせ合計](src/algorithms/sets/combination-sum) - 特定の合計を構成するすべての組み合わせを見つける |
| 201 | +* **ブランチ&バウンド** - バックトラック検索の各段階で見つかった最もコストの低いソリューションを覚えておいて、最もコストの低いソリューションのコストを使用します。これまでに発見された最もコストの低いソリューションよりも大きなコストで部分ソリューションを破棄するように指示します。通常、状態空間ツリーのDFSトラバーサルと組み合わせたBFSトラバーサルが使用されています。 |
| 202 | + |
| 203 | +## このリポジトリの使い方 |
| 204 | + |
| 205 | +**すべての依存関係をインストールする** |
| 206 | +``` |
| 207 | +npm install |
| 208 | +``` |
| 209 | + |
| 210 | +**ESLintを実行する** |
| 211 | + |
| 212 | +これを実行してコードの品質をチェックすることができます。 |
| 213 | + |
| 214 | +``` |
| 215 | +npm run lint |
| 216 | +``` |
| 217 | + |
| 218 | +**すべてのテストを実行する** |
| 219 | +``` |
| 220 | +npm test |
| 221 | +``` |
| 222 | + |
| 223 | +**名前でテストを実行する** |
| 224 | +``` |
| 225 | +npm test -- 'LinkedList' |
| 226 | +``` |
| 227 | + |
| 228 | +**playground** |
| 229 | + |
| 230 | +データ構造とアルゴリズムを `./src/playground/playground.js` ファイルで再生し、 |
| 231 | +それに対するテストを書くことができ `./src/playground/__test__/playground.test.js`. |
| 232 | + |
| 233 | +次に、次のコマンドを実行して、遊び場コードが正常に動作するかどうかをテストします。 |
| 234 | + |
| 235 | +``` |
| 236 | +npm test -- 'playground' |
| 237 | +``` |
| 238 | + |
| 239 | +## 有用な情報 |
| 240 | + |
| 241 | +### 参考文献 |
| 242 | + |
| 243 | +[▶ データ構造とアルゴリズム on YouTube](https://www.youtube.com/playlist?list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8) |
| 244 | + |
| 245 | +### ビッグO表記 |
| 246 | + |
| 247 | +*Big O表記法は* 入力サイズが大きくなるにつれて実行時間やスペース要件がどのように増加するかに応じてアルゴリズムを分類するために使用されます。下のチャートでは、Big O表記で指定されたアルゴリズムの成長の最も一般的な順序を見つけることができます。 |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | +出典: [Big Oチートシート](http://bigocheatsheet.com/). |
| 252 | + |
| 253 | +以下は、最も使用されているBig O表記のリストと、入力データのさまざまなサイズに対するパフォーマンス比較です。 |
| 254 | + |
| 255 | +| Big O Notation | Computations for 10 elements | Computations for 100 elements | Computations for 1000 elements | |
| 256 | +| -------------- | ---------------------------- | ----------------------------- | ------------------------------- | |
| 257 | +| **O(1)** | 1 | 1 | 1 | |
| 258 | +| **O(log N)** | 3 | 6 | 9 | |
| 259 | +| **O(N)** | 10 | 100 | 1000 | |
| 260 | +| **O(N log N)** | 30 | 600 | 9000 | |
| 261 | +| **O(N^2)** | 100 | 10000 | 1000000 | |
| 262 | +| **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 | |
| 263 | +| **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 | |
| 264 | + |
| 265 | +### データ構造操作の複雑さ |
| 266 | + |
| 267 | +| Data Structure | Access | Search | Insertion | Deletion | Comments | |
| 268 | +| ----------------------- | :-------: | :-------: | :-------: | :-------: | :-------- | |
| 269 | +| **Array** | 1 | n | n | n | | |
| 270 | +| **Stack** | n | n | 1 | 1 | | |
| 271 | +| **Queue** | n | n | 1 | 1 | | |
| 272 | +| **Linked List** | n | n | 1 | 1 | | |
| 273 | +| **Hash Table** | - | n | n | n | In case of perfect hash function costs would be O(1) | |
| 274 | +| **Binary Search Tree** | n | n | n | n | In case of balanced tree costs would be O(log(n)) | |
| 275 | +| **B-Tree** | log(n) | log(n) | log(n) | log(n) | | |
| 276 | +| **Red-Black Tree** | log(n) | log(n) | log(n) | log(n) | | |
| 277 | +| **AVL Tree** | log(n) | log(n) | log(n) | log(n) | | |
| 278 | +| **Bloom Filter** | - | 1 | 1 | - | False positives are possible while searching | |
| 279 | + |
| 280 | +### 配列の並べ替えアルゴリズムの複雑さ |
| 281 | + |
| 282 | +| Name | Best | Average | Worst | Memory | Stable | Comments | |
| 283 | +| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- | |
| 284 | +| **Bubble sort** | n | n<sup>2</sup> | n<sup>2</sup> | 1 | Yes | | |
| 285 | +| **Insertion sort** | n | n<sup>2</sup> | n<sup>2</sup> | 1 | Yes | | |
| 286 | +| **Selection sort** | n<sup>2</sup> | n<sup>2</sup> | n<sup>2</sup> | 1 | No | | |
| 287 | +| **Heap sort** | n log(n) | n log(n) | n log(n) | 1 | No | | |
| 288 | +| **Merge sort** | n log(n) | n log(n) | n log(n) | n | Yes | | |
| 289 | +| **Quick sort** | n log(n) | n log(n) | n<sup>2</sup> | log(n) | No | Quicksort is usually done in-place with O(log(n)) stack space | |
| 290 | +| **Shell sort** | n log(n) | depends on gap sequence | n (log(n))<sup>2</sup> | 1 | No | | |
| 291 | +| **Counting sort** | n + r | n + r | n + r | n + r | Yes | r - biggest number in array | |
| 292 | +| **Radix sort** | n * k | n * k | n * k | n + k | Yes | k - length of longest key | |
0 commit comments