0
0
DSA Typescriptprogramming~3 mins

Why Graph Terminology Vertices Edges Directed Undirected Weighted in DSA Typescript?

Choose your learning style9 modes available
The Big Idea

Discover how graphs turn messy connections into clear maps you can explore and understand!

The Scenario

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.

The Problem

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.

The Solution

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.

Before vs After
Before
const friends = ['Alice', 'Bob', 'Carol'];
// Manually track connections with notes
// Alice -> Bob (close), Bob <-> Carol (friends)
After
class Graph {
  vertices: string[] = [];
  edges: Map<string, Map<string, number>> = new Map();
  // Add vertices and edges with direction and weight
}
What It Enables

Graphs let you quickly find relationships, paths, and strengths between points in complex networks.

Real Life Example

Social media platforms use graphs to show who follows whom, suggest friends, and rank connections by interaction strength.

Key Takeaways

Vertices are points or nodes representing entities.

Edges connect vertices and can have direction and weight.

Graphs help model complex relationships clearly and efficiently.