* Propose a Basic Solution to Adjaceny List Problem * Update guide/english/certifications/coding-interview-prep/data-structures/adjacency-list/index.md Co-Authored-By: StanimalTheMan <43020892+StanimalTheMan@users.noreply.github.com> * Remove template
2.6 KiB
2.6 KiB
title
title |
---|
Adjacency List |
Adjacency List
Remember to use
Read-Search-Ask
if you get stuck. Try to pair program and write your own code
Problem Explanation:
To solve this problem, you have to create a Javascript Object to emulate an undirected graph in the form of an adjacency list.
Hint: 1
Create keys with the names James, Jill, Jenny and Jeff.
try to solve the problem now
Hint: 2
Read the presentation and try to understand what it means to be an undirected graph.
try to solve the problem now
Spoiler Alert!
Solution ahead!
Basic Code Solution:
var undirectedAdjList = {
James: ["Jeff"],
Jill: ["Jenny"],
Jenny: ["Jill", "Jeff"],
Jeff: ["Jenny", "James"]
};
Code Explanation:
- The undirected graph is created using a Javascript Object. Each unique name is a key and the each person who has a relationship with the name is in the unique name's array value. e.g. if James and Jeff have a relationship, Jeff will be in James's array value and James will be in Jeff's array value.