Data Structures
Stacks, queues, trees, heaps & hash tables — how they store and retrieve
Choosing the right data structure is often what separates a slow program from a fast one. Each structure trades off how quickly you can insert, remove, search or order data.
Linear structures
Stacks (last-in, first-out) and queues (first-in, first-out) impose an access order — stacks power undo and recursion, queues power scheduling and BFS. Linked lists chain nodes with pointers, giving cheap insertion and deletion anywhere without shifting elements, at the cost of no random access.
Hierarchical & keyed structures
Binary search trees keep keys ordered so lookups, insertions and range queries run in O(log n) on a balanced tree. Heaps are partially-ordered trees that surface the minimum or maximum in O(log n) — the engine behind priority queues and heap sort. Hash tables map keys to buckets through a hash function for average O(1) lookup, at the cost of unordered storage and occasional collisions.
The visualizers below let you push, pop, insert and delete to see exactly how each structure rearranges itself.
Try it interactively
スタック可視化ツール
インタラクティブなLIFOスタック — pushとpopをアニメーション付きのtopポインタとステップ操作で確認できます。ブラウザ上ですぐ動作します。
ツールを開くキュー可視化ツール
インタラクティブなFIFOキュー — front/rearポインタのアニメーション付きで要素の追加(enqueue)と取り出し(dequeue)を実行し、ステップ操作ボタンで動きを確認できます。ブラウザ上ですぐに動作します。
ツールを開く連結リスト・ビジュアライザー
単方向連結リストをインタラクティブに操作 — 先頭/末尾への挿入、検索、削除をポインタが動くアニメーションとステップ実行ボタンで確認できます。ブラウザ上でそのまま動作します。
ツールを開く二分探索木ビジュアライザー
挿入・検索・削除をアニメーションで確認できるインタラクティブな二分探索木ツール。ステップ操作と疑似コード表示付きで、ブラウザ上ですぐに動かせます。
ツールを開くバイナリヒープ可視化ツール
インタラクティブなバイナリ最大ヒープ — 要素を挿入(insert)し、最大値を取り出す(extract-max)操作を、sift-up / sift-downのアニメーションとステップ実行、疑似コード付きで確認できます。すべてブラウザ内で完結します。
ツールを開くハッシュテーブル可視化ツール
separate chaining方式のインタラクティブなハッシュテーブル。insert・search・deleteの動きを、値のハッシュ化と衝突処理のアニメーションで確認できます。ブラウザ上ですぐに動作します。
ツールを開くPrefer a focused tool?
- Data Structures → See data structures build and rearrange, step by step
よくある質問
ハッシュテーブルとは何ですか?
ハッシュテーブルは、複数のバケットを持つ配列にkey/valueのペアを格納するデータ構造です。ハッシュ関数を使って各keyに対応するバケットのインデックスを計算するため、insert・search・deleteの各操作をほぼ一定時間で行えます。
ハッシュ衝突(hash collision)とは何ですか?
異なる2つのkeyが同じバケットにハッシュ化されてしまう現象です。このツールではseparate chainingという方式で衝突を処理しており、各バケットはエントリの連結リスト(linked list)を保持します。
ハッシュテーブル操作の時間計算量はどのくらいですか?
insert・search・deleteはいずれも平均O(1)です。最悪の場合は、多くのkeyが1つのバケットに集中して衝突するため、O(n)になります。
このツールではどのハッシュ関数を使っていますか?
index = value % 7というシンプルな剰余(モジュロ)演算のハッシュ関数を使っており、バケットの動きを追いやすくしています。実際のハッシュテーブルでは、より強力なハッシュ関数を使い、チェーンが長くなりすぎないよう自動的にリサイズを行います。