本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペースはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらく

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシープライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
012345678901234567890123456789012345678901234567890123456789
昨日
012345678901234567890123456789012345678901234567890123456789
累計閲覧
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

基本データ構造 ドキュメント
基本データ構造
Core ConceptsHow It WorksImplementationComplexity AnalysisPractice ProblemsReal-World Use
ディスカッション

基本データ構造 ガイド · 4/6

Complexity Analysis

この章は現在、英語でのみ提供しています。

Big-O tells you how cost grows with n, the number of stored items. For basic data structures the interesting part is that the same operation can be O(1) on one structure and O(n) on another, and that some O(1) figures are averages or amortized rather than guaranteed.

Operation costs side by side

OperationDynamic arrayLinked list (doubly)Deque (ring buffer)Hash table
Access k-th itemO(1)O(n)O(1)not supported
Search by valueO(n)O(n)O(n)O(1) average by key
Insert / delete at endO(1) amortizedO(1)O(1) amortizedn/a
Insert / delete at frontO(n)O(1)O(1) amortizedn/a
Insert / delete in the middleO(n)O(1) once the node is foundO(n)n/a
Insert / delete by keyn/an/an/aO(1) average, O(n) worst
Extra memory per itemsmall (spare capacity)two pointers per nodesmallbucket array plus chain nodes

Stacks and queues are restrictions of these structures, so a stack on a dynamic array has O(1) amortized push and pop, and a queue on a ring buffer or linked list has O(1) enqueue and dequeue.

Amortized O(1) append

A single append to a full dynamic array copies all n items, which is O(n). Over a sequence of n appends with doubling, the copies are 1 + 2 + 4 + ... + n/2 + n, which is less than 2n. Total work is O(n), so the cost per append is O(1) amortized.

The growth factor matters. Growing by a constant amount (say 10 slots each time) makes the copies 10 + 20 + 30 + ..., which is O(n squared) in total. Any constant multiplier greater than 1 keeps appends O(1) amortized; libraries trade memory for speed by choosing 1.5, 2 or a small over-allocation as CPython does.

def total_copies(n, grow):
    size, cap, copies = 0, 1, 0
    for _ in range(n):
        if size == cap:
            copies += size
            cap = grow(cap)
        size += 1
    return copies

n = 100_000
print("x2   :", total_copies(n, lambda c: c * 2))       # about 1.3 * n
print("x1.5 :", total_copies(n, lambda c: c + c // 2 + 1))
print("+10  :", total_copies(n, lambda c: c + 10))      # about n * n / 20
この章について質問がありますか?
前の章Implementation次の章Practice Problems

Hash tables: average vs worst case

With m buckets and n keys, the load factor is alpha = n / m. If the hash function spreads keys evenly, the expected chain length is alpha, so a lookup costs O(1 + alpha). Keeping alpha below a constant (0.75 in Java's HashMap, 1.0 by default in C++'s std::unordered_map) makes it O(1) on average. Resizing costs O(n) when it happens, but like array growth it is O(1) amortized per insert.

The worst case is O(n): if every key lands in one bucket, the table degenerates into a list. This happens with a poor hash function or with adversarial input crafted to collide (hash flooding). Python randomizes string hashes per process for this reason, and Java's HashMap turns very long chains into balanced trees so the worst case becomes O(log n).

Measuring it yourself

Complexity tables are easy to verify with a timer. Removing from the front is the classic trap:

from collections import deque
from timeit import timeit

def drain_list(n):
    items = list(range(n))
    while items:
        items.pop(0)          # shifts every remaining item

def drain_deque(n):
    items = deque(range(n))
    while items:
        items.popleft()       # moves one index

n = 100_000
print("list.pop(0)    ", timeit(lambda: drain_list(n), number=1))
print("deque.popleft()", timeit(lambda: drain_deque(n), number=1))

The list version is quadratic in total and at this size is often a hundred times slower or more. Membership tests show the hash table advantage:

from timeit import timeit

items = list(range(10_000))
as_set = set(items)
probes = range(0, 20_000, 7)
print("list:", timeit(lambda: sum(p in items for p in probes), number=1))
print("set :", timeit(lambda: sum(p in as_set for p in probes), number=1))

Python's built-in types

TypeOperationAverage cost
listx[i], append, pop()O(1) (append amortized)
listinsert(0, x), pop(0), x in listO(n)
dequeappend, appendleft, pop, popleftO(1)
dequed[i] in the middleO(n)
dict / setget, set, delete, inO(1) average, O(n) worst

Space

All five structures use O(n) space, but the constants differ. A dynamic array may hold up to about twice the slots it needs right after growing. A doubly linked list stores two pointers per item, which on a 64-bit machine is 16 bytes of overhead before counting the value. Hash tables cap the load factor at a limit such as 0.75 or 1, so many buckets stay empty, and chaining adds a node per entry.

Summary

Arrays give O(1) indexing and amortized O(1) appends, linked structures give O(1) splicing at known positions, and hash tables give O(1) average key operations with an O(n) worst case. Amortized and average figures are reliable in practice as long as growth is geometric and the hash function spreads keys well; measure when in doubt.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。