DSA Lesson 18 of 33

Graphs

Understand vertices, edges and graph representations.

Course Progress55%

Theory

A graph is a non-linear data structure consisting of vertices and edges. Graphs can represent relationships between objects such as cities and roads, users and friendships or web pages and links.

Example

const graph = { A: ["B", "C"], B: ["A", "D"], C: ["A"], D: ["B"] }; console.log(graph.A);

Expected Output

The neighbors of A are B and C.

Practice

Create a graph representing four cities and their connections.

Interview Questions

  1. What is a graph?
  2. What are vertices and edges?
  3. What is a directed graph?
  4. What is an undirected graph?