本文へスキップ

リソース · ガイド・記事

Detect Cycle in Graphs

閉路検出の背景にある用語、つまり閉じた歩道、単純閉路、回路を整理し、有向グラフと無向グラフで定義がどう違うかを説明しています。閉路検出の問題に取り組む前に、用語を正確に押さえるために読むとよいでしょう。

確認日

元のサイトを開く: Detect Cycle in Graphs (元のサイトを新しいタブで開きます)

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

ロードマップに追加

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

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

In graph theory, a cycle is a path of edges and vertices wherein a vertex is reachable from itself. There are several different types of cycles, principally a closed walk and a simple cycle. A closed walk consists of a sequence of vertices starting and ending at the same vertex, with each two consecutive vertices in the sequence adjacent to each other in the graph. In a directed graph, each edge must be traversed by the walk consistently with its direction: the edge must be oriented from the earlier of two consecutive vertices to the later of the two vertices in the sequence. The choice of starting vertex is not important: traversing the same cyclic sequence of edges from different starting vertices produces the same closed walk. A simple cycle may be defined either as a closed walk with no repetitions of vertices and edges allowed, other than the repetition of the starting and ending vertex, or as the set of edges in such a walk. The two definitions are equivalent in directed graphs, where simple cycles are also called directed cycles: the cyclic sequence of vertices and edges in a walk is completely determined by the set of edges that it uses. In undirected graphs the set of…

PrepKit の概要

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

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

扱っている内容

  • 閉じた歩道の定義。有向グラフの歩道は辺の向きに従わなければならないという規則を含む
  • 単純閉路と回路の違いと、無向グラフの閉路一つが有向グラフの閉路二つに対応する理由
  • 色分けされた例のグラフで、パスH-A-B、頂点が重複する歩道、単純閉路H-D-G-Hを区別
  • 無向グラフと有向グラフそれぞれの閉路検出についての、別々の参考資料一覧

使い方

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

両方の版を解いてください。無向グラフには親を記録するDFSまたはunion-find、有向グラフには3色DFSを使います。無向グラフ用の方法が有向グラフでうまくいかない理由を説明しましょう。

範囲と制約

定義のみです。検出アルゴリズム、計算量、コードはREADMEでは説明されておらず、GeeksForGeeksとYouTubeへのリンクの先にしかありません。

利用方法と形式

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

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

この概要の根拠
  • src/algorithms/graph/detect-cycle/README.md

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

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

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

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