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

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

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

サーバー

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

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

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

ニュース

今日の開発ニュース言語・フレームワーク・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ツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
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製品情報は検証済みの開発ソースに基づいています。リリース・改善中

探索 ドキュメント
探索
Searching ConceptsHow It WorksImplementationComplexityPractice ProblemsSearching in the Real World
ディスカッション

探索 ガイド · 1/6

Searching Concepts

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

Searching means locating a value, or a position that satisfies some condition, inside a collection of data. "Is this value present?", "Where is it?", and "What is the first element greater than or equal to this value?" are all search questions. This chapter introduces linear search and binary search, then the wider family built on binary search: searching on the answer (parametric search), ternary search, and hash-based lookup. Along the way it fixes the vocabulary used in the rest of the guide.

Linear search

Linear (sequential) search compares elements one by one from the front. It needs no ordering and works on anything you can only read front to back, such as linked lists or streams. The price is that in the worst case it inspects every element, so the time grows in proportion to the number of elements n.

def linear_search(items, target):
    for i, value in enumerate(items):
        if value == target:
            return i
    return -1


print(linear_search([7, 3, 9, 3], 3))   # 1 (first occurrence)
print(linear_search([7, 3, 9, 3], 4))   # -1

Python's x in list and list.index(x) are linear searches under the hood. For a few dozen elements that is perfectly fine; sorting or building an index would cost more than it saves.

Binary search

Binary search works on sorted arrays. It compares the target with the middle element and throws away the half that cannot contain it, over and over. Each comparison halves the candidate range, so even a million elements take only about 20 steps. The essential precondition is order, or more generally monotonicity: a condition whose truth value flips exactly once along the range.

def binary_search(a, target):
    lo, hi = 0, len(a) - 1          # closed interval [lo, hi]
    while lo <= hi:
        mid = (lo + hi) // 2
        if a[mid] == target:
            return mid
        if a[mid] < target:
            lo = mid + 1
        else:
            hi = mid - 1
    return -1


print(binary_search([2, 5, 8, 12, 16, 23], 16))   # 4

This version only tells you whether a value exists. When the value occurs several times, which index you get back is unspecified. In practice the boundary-finding forms in the next section, lower_bound and upper_bound, are used far more often.

Finding boundaries: lower_bound and upper_bound

  • lower_bound(x): the first index i with a[i] >= x, or len(a) if there is none.
  • upper_bound(x): the first index i with a[i] > x, or len(a) if there is none.
  • The difference upper_bound(x) - lower_bound(x) is the number of occurrences of .
この章について質問がありますか?
次の章How It Works
x
  • lower_bound(x) is also the leftmost slot where x can be inserted without breaking the order.
  • Python's standard bisect module provides exactly these two functions: bisect_left is lower_bound and bisect_right is upper_bound.

    from bisect import bisect_left, bisect_right
    
    scores = [10, 20, 20, 20, 35, 50]
    print(bisect_left(scores, 20))    # 1
    print(bisect_right(scores, 20))   # 4
    print(bisect_right(scores, 20) - bisect_left(scores, 20))   # 3 occurrences
    print(bisect_left(scores, 99))    # 6 (the end)

    Monotone predicates and searching on the answer

    Binary search is not limited to arrays. If a condition P(k) over an integer range is false up to some boundary and true from then on (False, False, ..., True, True), binary search finds the first k where it becomes true. This is called parametric search, or "binary searching the answer". The trick is to turn an optimization question such as "what is the smallest daily throughput that meets the deadline?" into a yes/no question: "is this value enough?"

    Ternary search finds the position of the maximum or minimum of a unimodal function, one that rises and then falls (or the reverse). It splits the range into thirds, compares the function at two inner points, and discards the third that cannot contain the extremum.

    Hash lookup

    A hash table (Python's set and dict) turns a key into a hash and jumps straight to its slot, answering "is it present?" in O(1) on average. It keeps no ordering, though, so it cannot answer "the first value at least x" or "all values in [a, b]". Use hashing for exact-match lookups and sorting plus binary search when order or ranges matter.

    Vocabulary

    TermMeaning
    KeyThe value that comparisons are based on
    InvariantA property that holds on every iteration, e.g. the answer always lies in [lo, hi)
    Half-open interval[lo, hi): lo included, hi excluded
    Monotone predicateA condition whose truth value changes only once
    Unimodal functionA function that increases then decreases (or vice versa)

    Summary

    • Linear search is the simplest choice for small or unsorted data.
    • Binary search runs in O(log n) on sorted data, and its boundary forms, lower_bound and upper_bound, are the most useful.
    • With a monotone predicate you can binary search the answer itself, no array required.
    • Use hashing for exact matches; use sorting plus binary search for ordered and range queries.

    コメント 0件

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

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