本文へスキップ

リソース · ガイド・記事

Topological Sorting

有向グラフのトポロジカル順序を定義し、それが存在する条件、つまりグラフに有向閉路がないことを説明しています。履修スケジュールやビルド順序のような問題の入門になります。

確認日

元のサイトを開く: Topological Sorting (元のサイトを新しいタブで開きます)

このトピックを練習グラフ の問題で練習用面接官を開きます。

ロードマップに追加

取り組んでいるロードマップにこのリソースを追加できます。自分用の追加リソースとして表示され、ロードマップの手順は変わらず、記録した手順数にも数えられません。

出典コンテンツの言語:英語

In the field of computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering. For instance, the vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one task must be performed before another; in this application, a topological ordering is just a valid sequence for the tasks. A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG). Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time.

PrepKit の概要

この概要は PrepKit 編集部がソースリポジトリをもとに執筆・確認したもので、リソース本文の引用ではありません。

対象
ソースにレベルの記載はありません
形式
リファレンス

扱っている内容

  • 非巡回であるという条件と、線形時間で構築するアルゴリズムが存在するという記述
  • 一つのDAGの例に対する6通りの正しい順序。それぞれ、どの規則で得られたかのラベル付き
  • 応用としてのジョブスケジューリングとパッケージの依存関係の解決

使い方

PrepKit の学習アドバイスであり、ソースの主張ではありません。

例のグラフでKahnの方法とDFSの帰りがけ順を実装し、どちらの出力も正しい順序か確認してください。両方とも閉路を報告できるようにします。

範囲と制約

具体的なアルゴリズム名は挙げておらず、線形時間の方法があると述べるだけで疑似コードも計算量もありません。閉路の報告は扱っていません。

利用方法と形式

MITライセンスのtrekhleb/javascript-algorithmsリポジトリ内のGitHub上のREADMEで、英語で無料で読めます。

PrepKit が 2026/10/02 に確認しました。 リソースの出典のコミット: 85293e3e2b88

この概要の根拠
  • src/algorithms/graph/topological-sorting/README.md

この項目を掲載しているページ

PrepKit ニュースレターを受け取る

任意です。PrepKit の利用には必要ありません。

メールアドレスの取り扱いについて