Data Structures and AlgorithmsGraphs

Graphs consist of nodes (vertices) connected by edges. They can be directed or undirected, weighted or unweighted. Used in social networks, navigation systems, and network routing.

// Representing a graph using adjacency list
const graph = {
  A: ['B', 'C'],
  B: ['A', 'D'],
  C: ['A', 'D'],
  D: ['B', 'C']
};
console.log(graph.A); // Output: [ 'B', 'C' ]