Beta

Are these nodes connected?

Description:

Your goal is to create a data structure that can quickly determine whether nodes are connected.

Nodes are represented as positive integers 0-N.

You can connect them by saying connect(a,b).

You should be able to ask if they are connected by saying isConnected(a,b).

Connections are bidirectional, so if a is connected to b, b is also connected to a.

This connection determination is a classic computer science problem, but is also totally deducible from first princicples. You'll get the most learning value out of this if you to try to solve it yourself first before going to look up solutions.

The API should work like this:

var nodes = Nodes(6); // size 6
nodes.connect(0,1); // node at index 0 is connected with node at index 1
nodes.connect(1,2);
nodes.isConnected(0,2); // true, since 0 -> 1 -> 2
Data Structures
Algorithms
Graph Theory

More By Author:

Check out these other kata created by SimplGy

Stats:

CreatedOct 5, 2016
PublishedOct 5, 2016
Warriors Trained108
Total Skips7
Total Code Submissions234
Total Times Completed31
JavaScript Completions31
Total Stars4
% of votes with a positive feedback rating75% of 16
Total "Very Satisfied" Votes10
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes2
Total Rank Assessments16
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • SimplGy Avatar
  • trashy_incel Avatar
Ad