Propose a Basic Solution to Adjacency List Problem (#35511)
* 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
This commit is contained in:
committed by
The Coding Aviator
parent
bf3e001b78
commit
781c217001
@ -2,9 +2,49 @@
|
||||
title: Adjacency List
|
||||
---
|
||||
## Adjacency List
|
||||
 Remember to use <a>**`Read-Search-Ask`**</a> if you get stuck. Try to pair program  and write your own code 
|
||||
|
||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/coding-interview-prep/data-structures/adjacency-list/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
||||
###  Problem Explanation:
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
||||
To solve this problem, you have to create a Javascript Object to emulate an undirected graph in the form of an adjacency list.
|
||||
|
||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||
|
||||
##  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.
|
||||
|
||||
##  NOTES FOR CONTRIBUTIONS:
|
||||
|
||||
*  **DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution.
|
||||
* Add an explanation of your solution.
|
||||
* Categorize the solution in one of the following categories — **Basic**, **Intermediate** and **Advanced**. 
|
||||
|
Reference in New Issue
Block a user