Files
StanimalTheMan 781c217001 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
2019-04-02 22:45:01 +05:30

2.6 KiB

title
title
Adjacency List

Adjacency List

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: 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.

:speech_balloon: Hint: 1

Create keys with the names James, Jill, Jenny and Jeff.

try to solve the problem now

:speech_balloon: 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!

warning sign

Solution ahead!

:beginner: 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.

:clipboard: NOTES FOR CONTRIBUTIONS:

  • :warning: 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. :traffic_light: