Why Graphs Exist and What Trees Cannot Model
📖 Scenario: Imagine you are organizing a group of friends who want to share rides to different places. Some friends can drive others, and some can be passengers. You want to represent these relationships to understand who can reach whom. Trees are like family trees with one clear path, but sometimes friends have multiple connections that trees cannot show well. Graphs help us model these complex connections.
🎯 Goal: You will build a simple graph using an adjacency list in TypeScript to represent friends and their ride-sharing connections. This will show why trees are not enough when multiple connections exist.
📋 What You'll Learn
Create a graph using an adjacency list with exact friend names and connections
Add a variable to count the total number of friends
Write a function to add a new friend connection
Print the adjacency list to show all connections
💡 Why This Matters
🌍 Real World
Graphs help model complex relationships like social networks, road maps, and ride-sharing connections where multiple links exist between entities.
💼 Career
Understanding graphs is essential for software roles involving network analysis, recommendation systems, and any scenario with interconnected data.
Progress0 / 4 steps