Cycle Detection for Directed and Undirected Graphs in Java | Check if a Graph has a Cycle | Geekific

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • Support us on Patreon: / geekific
    Discord Community: / discord
    GitHub Repository: github.com/geekific-official/
    In our previous videos, we covered what graphs are, how many types of graphs we have, and we’ve learned a few graph traversal algorithms and techniques. In this video we focus on cyclic graphs, both directed and undirected. More specifically, we’ll see how to detect, in code, if any of these graph types contains a cycle.
    Timestamps:
    00:00 Introduction
    00:28 What are Cycles?
    01:13 Detecting a Cycle in a Directed Graph
    03:33 Cycle Detection for Directed Graphs Implementation
    07:12 Detecting a Cycle in a Undirected Graph
    09:26 Thanks for Watching!
    If you found this video helpful, check other Geekific uploads:
    - Object-Oriented Programming Fundamentals: • What is Object-Oriente...
    - SOLID Principles and Best Practices: • SOLID Design Principle...
    - Recursion Made Simple, Recursive Methods: • What is Recursion? | R...
    - Use-Case and Sequence Diagrams: • UML Use-Case and Seque...
    - Graphs, The Fundamentals: • Introduction to Graphs...
    - Trees Compared and Visualized, BST vs AVL vs Red-Black vs Splay vs Heaps: • Trees Compared and Vis...
    - Dijkstra's Algorithm Explained and Implemented in Java: • Shortest Path | Dijkst...
    - Ford-Fulkerson Algorithm Explained and Implemented in Java: • Max Flow | Ford-Fulker...
    - Generics and Wildcards in Java, Invariance vs Covariance vs Contravariance: • Generics and Wildcards...
    #Geekific #CycleDetection #GraphTheory #DFS #BFS

Komentáře • 4

  • @tomasalves5182
    @tomasalves5182 Před 8 měsíci

    Thanks, i've been searching for hours but only this did the trick, thank you so much

  • @tedelamater
    @tedelamater Před rokem

    I feel like BFS is easier to find cycles.

  • @manOfPlanetEarth
    @manOfPlanetEarth Před rokem

    Niiiice!!!
    One small remark. Boolean "onCurrentPath" instead of "beingVisited" would be more reflecting what's going on:)
    We have multiple being visited vertices in the path under exploring while function "hasCycle" at every moment works with only one vertex. It confuses. Even boolean "green" would be more self-telling:)
    2. As I get your "stream branded" approach is not applicable here because of need to return value (boolean), is it?
    Thank you for the material🥳

    • @geekific
      @geekific  Před rokem +1

      Glad I could help :) and 2-Yup.