リソース · ガイド・記事
Counting Sort
小さな整数のキー向けの計数ソートを扱います。比較ソートの下限を回避できる理由や、基数ソートやバケットソートとの関係も説明しています。
確認日
元のサイトを開く: Counting Sort (元のサイトを新しいタブで開きます)ロードマップに追加
取り組んでいるロードマップにこのリソースを追加できます。自分用の追加リソースとして表示され、ロードマップの手順は変わらず、記録した手順数にも数えられません。
出典コンテンツの言語:英語
In computer science, counting sort is an algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm. It operates by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each key value in the output sequence. Its running time is linear in the number of items and the difference between the maximum and minimum key values, so it is only suitable for direct use in situations where the variation in keys is not significantly greater than the number of items. However, it is often used as a subroutine in another sorting algorithm, radix sort, that can handle larger keys more efficiently. Because counting sort uses key values as indexes into an array, it is not a comparison sort, and the Ω(n log n) lower bound for comparison sorting does not apply to it. Bucket sort may be used for many of the same tasks as counting sort, with a similar time analysis; however, compared to counting sort, bucket sort requires linked lists, dynamic arrays or a large amount of preallocated memory to hold the sets of items within each bucket, whereas counting…
PrepKit の概要
この概要は PrepKit 編集部がソースリポジトリをもとに執筆・確認したもので、リソース本文の引用ではありません。
- 対象
- ソースにレベルの記載はありません
- 形式
- リファレンス
扱っている内容
- 比較ソートではない理由と、キーの範囲によって適する場面。
- 3つの手順:出現回数を数え、累積の数を作り、出力配列に要素を配置します。
- 計算量の表:時間とメモリが n + r、安定。r は最大の数です。
使い方
PrepKit の学習アドバイスであり、ソースの主張ではありません。
[4, 2, 2, 8, 3, 3, 1] を3つの手順すべてを通して手で並べ替え、次に安定性を保ったままコードにしてください。
範囲と制約
手順の図は外部ブログに置かれた画像です。負の数の扱いや演習はありません。ポルトガル語版へのリンクがあります。
利用方法と形式
GitHub の trekhleb/javascript-algorithms(MIT ライセンス)にある、英語の無料 README です。
PrepKit が 2026/10/02 に確認しました。 リソースの出典のコミット: 85293e3e2b88
この概要の根拠
- src/algorithms/sorting/counting-sort/README.md
この項目を掲載しているページ
PrepKit ニュースレターを受け取る
任意です。PrepKit の利用には必要ありません。