2018-10-12 15:37:13 -04:00
---
title: Adjacency List
---
2019-07-24 00:59:27 -07:00
# Adjacency List
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
2019-04-02 13:15:01 -04:00
To solve this problem, you have to create a Javascript Object to emulate an undirected graph in the form of an adjacency list.
2018-10-12 15:37:13 -04:00
2019-04-02 13:15:01 -04:00
2019-07-24 00:59:27 -07:00
---
## Hints
### Hint 1
2019-04-02 13:15:01 -04:00
Create keys with the names James, Jill, Jenny and Jeff.
2019-07-24 00:59:27 -07:00
### Hint 2
2019-04-02 13:15:01 -04:00
Read the presentation and try to understand what it means to be an undirected graph.
2019-07-24 00:59:27 -07:00
---
## Solutions
2019-04-02 13:15:01 -04:00
2019-07-24 00:59:27 -07:00
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2019-04-02 13:15:01 -04:00
2019-07-24 00:59:27 -07:00
```js
var undirectedAdjList = {
James: ["Jeff"],
Jill: ["Jenny"],
Jenny: ["Jill", "Jeff"],
Jeff: ["Jenny", "James"]
};
```
2019-04-02 13:15:01 -04:00
2019-07-24 00:59:27 -07:00
#### Code Explanation
2019-04-02 13:15:01 -04:00
* 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.
2019-07-24 00:59:27 -07:00
< / details >