本文へスキップ
製品デスクトップツール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製品情報は検証済みの開発ソースに基づいています。リリース・改善中

最短経路と最小全域木 ドキュメント
最短経路と最小全域木
ConceptsHow it worksImplementationComplexityPractice problemsReal-world use
ディスカッション

最短経路と最小全域木 ガイド · 1/6

Concepts

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

This guide covers two classic families of weighted-graph problems. Shortest paths ask for the cheapest way to travel from one vertex to another. Minimum spanning trees (MSTs) ask for the cheapest set of edges that keeps every vertex connected. Both appear constantly in coding interviews and in real systems such as map routing, network protocols and cable layout.

Weighted graphs

A graph has vertices V and edges E. In a weighted graph every edge carries a number: distance, time, cost or latency. Edges may be directed (one-way streets) or undirected (two-way roads). The weight of a path is the sum of its edge weights, and a shortest path is a path of minimum total weight.

Most algorithms here work on an adjacency list: for each vertex, a list of (neighbor, weight) pairs. It uses O(V + E) memory and lets you scan the neighbors of a vertex quickly. Kruskal's algorithm instead works on a plain edge list.

n = 4
edges = [(0, 1, 4), (0, 2, 1), (2, 1, 2), (1, 3, 1)]  # (u, v, weight)

adj = [[] for _ in range(n)]
for u, v, w in edges:
    adj[u].append((v, w))
    # for an undirected graph also add: adj[v].append((u, w))

print(adj)  # [[(1, 4), (2, 1)], [(3, 1)], [(1, 2)], []]

Problem variants

  • Single-source shortest paths (SSSP): distances from one source to every vertex. Dijkstra and Bellman-Ford solve this.
  • Single-pair: from s to t only. In practice you run an SSSP algorithm and stop early once t is settled.
  • All-pairs shortest paths (APSP): a distance for every pair. Floyd-Warshall solves this, or you run Dijkstra from every vertex.
  • Minimum spanning tree: for a connected undirected graph, choose V - 1 edges that connect all vertices with the smallest total weight. Kruskal and Prim solve this.

Relaxation

Every shortest-path algorithm in this guide is built on one operation called relaxation. You keep a tentative distance dist[v] for each vertex, starting at infinity (0 for the source). Relaxing edge (u, v, w) asks: is going through u better than what we know?

from math import inf

dist = [0, inf, inf, inf]
parent = [-1, -1, -1, -1]

def relax(u, v, w):
    if dist[u] + w < dist[v]:
        dist[v] = dist[u] + w
        parent[v] = u          # remember how we reached v
        return True
    return False

relax(0, 1, 4)
relax(0, 2, 1)
relax(2, 1, 2)                 # 1 + 2 = 3 beats 4
print(dist, parent)            # [0, 3, 1, inf] [-1, 2, 0, -1]

The algorithms differ only in the order in which they relax edges. Dijkstra relaxes outgoing edges of the closest unfinished vertex first, Bellman-Ford relaxes all edges in repeated rounds, and Floyd-Warshall relaxes through each possible intermediate vertex in turn. The array forms a , and following it backwards from a target rebuilds the actual path.

この章について質問がありますか?
次の章How it works
parent
shortest-path tree

Negative edges and negative cycles

Negative weights are legal in Bellman-Ford and Floyd-Warshall but break Dijkstra's greedy assumption. A negative cycle is a cycle whose total weight is below zero. If one is reachable from the source, you can loop around it forever, so the shortest distance is undefined. Detecting such a cycle is a useful result in its own right, for example for spotting currency arbitrage.

Choosing an algorithm

SituationAlgorithmTime
Unweighted edgesBFSO(V + E)
Weights are only 0 or 10-1 BFSO(V + E)
Non-negative weightsDijkstra with a binary heapO((V + E) log V)
Negative weights, or cycle detectionBellman-FordO(V E)
All pairs, small V (a few hundred)Floyd-WarshallO(V^3)
Directed acyclic graphRelax in topological orderO(V + E)

Minimum spanning trees

A spanning tree of a connected undirected graph touches every vertex using exactly V - 1 edges and has no cycle. The MST is the spanning tree of least total weight. Two facts make greedy algorithms correct here. The cut property says that the lightest edge crossing any split of the vertices into two groups belongs to some MST. The cycle property says that the heaviest edge on any cycle can be left out. Kruskal adds edges from lightest to heaviest and skips any edge that would close a cycle, using union-find. Prim grows one tree from a start vertex, always adding the cheapest edge that leaves the tree.

An MST is not the same thing as a shortest-path tree. The MST minimizes the total length of cable; the shortest-path tree minimizes each vertex's distance to the source.

    A ---1--- B
     \       /
      3     1
       \   /
         C

MST (total 2):            A-B, B-C   -> A to C costs 2 via B
Shortest-path tree from A: A-B, B-C  (here they agree)
Change A-C to 1.5: the MST is still A-B, B-C,
but the shortest path A to C becomes the direct edge.

Summary

  • Shortest paths minimize the weight from a source; MSTs minimize the total weight that keeps an undirected graph connected.
  • Relaxation is the shared building block; algorithms differ in the order they relax edges.
  • Pick the algorithm by edge weights (none, 0/1, non-negative, negative) and by whether you need one source or all pairs.
  • Kruskal and Prim are correct because of the cut and cycle properties.

コメント 0件

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

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