0
0
DSA Typescriptprogramming~30 mins

Adjacency List Representation in DSA Typescript - Build from Scratch

Choose your learning style9 modes available
Adjacency List Representation
📖 Scenario: Imagine you are organizing a small social network where each person can be friends with others. You want to store who is friends with whom in a way that is easy to look up and update.
🎯 Goal: You will build an adjacency list representation of a graph using a TypeScript object. Each key will be a person's name, and the value will be a list of their friends' names.
📋 What You'll Learn
Create an adjacency list object with exact keys and values
Add a new person with an empty friends list
Add friends to a person's list
Print the adjacency list to show the connections
💡 Why This Matters
🌍 Real World
Adjacency lists are used to represent networks like social connections, road maps, or computer networks efficiently.
💼 Career
Understanding adjacency lists is important for roles in software development, data analysis, and network engineering where graph data structures are common.
Progress0 / 4 steps
1
Create the initial adjacency list
Create a variable called adjacencyList as an object with these exact entries: 'Alice': ['Bob', 'Charlie'], 'Bob': ['Alice'], 'Charlie': ['Alice']
DSA Typescript
Hint

Use a TypeScript object with string keys and array of strings as values.

2
Add a new person with no friends
Add a new key 'David' to adjacencyList with an empty array as value
DSA Typescript
Hint

Use bracket notation to add a new key with an empty array.

3
Add friends to David's list
Add 'Alice' and 'Bob' to adjacencyList['David'] array using push method
DSA Typescript
Hint

Use push method twice to add two friends.

4
Print the adjacency list
Print the adjacencyList variable using console.log
DSA Typescript
Hint

Use console.log(adjacencyList) to print the whole object.