Discover how graphs turn messy connections into clear maps you can explore and understand!
Why Graph Terminology Vertices Edges Directed Undirected Weighted in DSA Typescript?
Imagine you want to map all your friends and how they are connected to each other. You try to write down every friendship and direction manually on paper.
Writing and updating connections by hand is slow and confusing. You might forget who is connected to whom or miss if the connection has a direction or weight, like how close the friendship is.
Graphs let you organize all these connections clearly. You can represent friends as points (vertices) and friendships as lines (edges). You can also show if friendships go one way (directed) or both ways (undirected), and add importance (weights) easily.
const friends = ['Alice', 'Bob', 'Carol']; // Manually track connections with notes // Alice -> Bob (close), Bob <-> Carol (friends)
class Graph { vertices: string[] = []; edges: Map<string, Map<string, number>> = new Map(); // Add vertices and edges with direction and weight }
Graphs let you quickly find relationships, paths, and strengths between points in complex networks.
Social media platforms use graphs to show who follows whom, suggest friends, and rank connections by interaction strength.
Vertices are points or nodes representing entities.
Edges connect vertices and can have direction and weight.
Graphs help model complex relationships clearly and efficiently.