This document elaborates on Graphs, focusing on traversal algorithms (Depth-First Search (DFS) and Breadth-First Search (BFS)), and properties like connected components and cyclic vs. non-cyclic graphs. Each section includes explanations, algorithms visualized with Mermaid diagrams (using correct syntax), and JavaScript implementations with examples.
A Graph is a data structure consisting of nodes (vertices) connected by edges. Graphs can be:
- Directed (edges have direction) or Undirected (edges are bidirectional).
- Weighted (edges have weights) or Unweighted (edges have no weights).
- Cyclic (contains cycles) or Acyclic (no cycles).