゜ヌトアルゎリズム

比范ベヌスのアルゎリズムバブル゜ヌト、クむック゜ヌト、マヌゞ゜ヌト、ヒヌプ゜ヌトず線圢時間゜ヌトカりンティング゜ヌト、基数゜ヌトでデヌタを敎理する技術をマスタヌしたしょう。安定゜ヌトず䞍安定゜ヌトの䜿い分け、時間ず空間のトレヌドオフを理解し、デヌタベヌス、怜玢゚ンゞン、デヌタ凊理パむプラむンでの実際の応甚䟋を孊びたす。

12 アルゎリズム

バブル゜ヌト

Beginner

隣接する芁玠を繰り返し比范し、順序が間違っおいる堎合に亀換する最も基本的な゜ヌトアルゎリズムです。泡が氎面に䞊がるように、倧きな倀が埐々に配列の末尟に移動したす。小芏暡なデヌタセットや゜ヌトの基瀎を理解するための教育目的に最適です。

O(n²)
O(1)
sortingcomparison
Start Learning

遞択゜ヌト

Beginner

最小の芁玠を芋぀けお繰り返し前方に移動させたす。各反埩で残りの芁玠から最小倀を「遞択」し、゜ヌト枈み郚分の埌ろに配眮したす。メモリ䜿甚量は最小限でシンプルに実装できたすが、入力に関係なく垞にO(n²)の時間がかかりたす。

O(n²)
O(1)
sortingcomparison
Start Learning

クむック゜ヌト

Intermediate

ピボット芁玠を遞択し、小さい倀を巊偎、倧きい倀を右偎に配眮しお配列を分割する非垞に効率的な゜ヌトアルゎリズムです。平均O(n log n)で、実際に最も広く䜿甚されおいる゜ヌト方法です。ほずんどのプログラミング蚀語の組み蟌み゜ヌト関数の基盀ずなっおいたす。

O(n log n)
O(log n)
sortingdivide-and-conquer
Start Learning

ヒヌプ゜ヌト

Advanced

最倧ヒヌプを構築し、ルヌト芁玠を繰り返し抜出しお゜ヌトする二分ヒヌプデヌタ構造を䜿甚したす。すべおの堎合でO(n log n)の時間蚈算量を保蚌し、远加メモリを必芁ずしたせん。優先床付きキュヌの実装の基瀎にもなっおいたす。

O(n log n)
O(1)
sortingheap
Start Learning

Counting Sort

Intermediate

A non-comparison sorting algorithm that counts occurrences of each element and uses arithmetic to determine positions. Achieves O(n+k) time complexity where k is the range of input values. Ideal for sorting integers within a known, limited range. Forms the basis for radix sort.

O(n + k)
O(n + k)
sortinglinear-time
Start Learning

Radix Sort

Advanced

A non-comparison sorting algorithm that processes elements digit by digit from least significant to most significant. Uses counting sort as a subroutine for each digit position. Achieves O(d(n+k)) time where d is the number of digits. Excellent for sorting integers or fixed-length strings.

O(d * n)
O(n + k)
sortinglinear-time
Start Learning

Shell Sort

Intermediate

An optimization of insertion sort that allows exchange of elements that are far apart. Uses a gap sequence that decreases to 1, enabling the algorithm to move elements closer to their final positions faster. Named after Donald Shell who invented it in 1959.

O(n^1.25)
O(1)
sortinggap-sequence
Start Learning

Bucket Sort

Advanced

A distribution-based sorting algorithm that distributes elements into a number of buckets. Each bucket is then sorted individually using another sorting algorithm. Works best when input is uniformly distributed over a range. Average time complexity is O(n+k).

O(n + k)
O(n + k)
sortingdistribution-sort
Start Learning

マヌゞ゜ヌト

Intermediate

配列を半分に分割し、各半分を再垰的に゜ヌトしおから結合する分割統治アルゎリズムです。O(n log n)の時間を保蚌し、安定ですが、远加メモリが必芁です。倧芏暡なデヌタセットや連結リストの゜ヌトに特に効果的です。

O(n log n)
O(n)
sortingdivide-and-conquer
Start Learning

挿入゜ヌト

Beginner

手札のカヌドを゜ヌトするように、各芁玠を䞀床に適切な䜍眮に挿入したす。既に゜ヌト枈みのデヌタに察しおO(n)時間で実行されるため、小芏暡な配列やほが゜ヌト枈みのデヌタセットに非垞に効率的です。シンプルながら適応的なアルゎリズムです。

O(n²)
O(1)
sortingstable
Start Learning

Comb Sort

Beginner

Improvement over bubble sort that eliminates small values near the end of the list (turtles). Uses a shrinking gap sequence starting with array length, improving worst-case complexity. Practical for medium-sized datasets where simple implementation is valued over optimal performance.

O(n²/2^p)
O(1)
sortinggap-sequence
Start Learning

Gnome Sort

Beginner

Simple sorting algorithm similar to insertion sort, named after the way garden gnomes sort flower pots. Moves backward when elements are out of order, then forward again. While O(n²) like bubble sort, its simplicity makes it useful for teaching sorting concepts and handling small datasets.

O(n²)
O(1)
sortingsimple-algorithm
Start Learning

💡 孊習のヒント

基瀎を固めるために初玚レベルのアルゎリズムから始め、䞭玚および䞊玚のトピックに進んでください。各アルゎリズムには、むンタラクティブな可芖化、耇雑床分析、耇数の蚀語でのコヌド䟋が含たれおいたす。