5 kyu
Find whether there is a route between two nodes in a graph
306 of 333ykagan
Loading description...
Recursion
Algorithms
Graph Theory
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
how is suppossed to have access to the matrix of connections? with just 'a' and 'b' should we get the result?
That matrix is part of the test suit. Not relevant for the solution. a and b are nodes, so yes, that's all you need to find the path (or not).
Java:
Java translation
Approved.
see issue above, please.
Raising about the elephant in the room, since FArekkusu seems to be missing the almost obvious...
nodes
is reassigned along the way, and used as a global var. That's bad too. Moreover when one considers that the user has absolutely no use for it. The tests should be rewritten without that or at least without it being "visible" to the user.suggestion:
Tests with big cyclic graphs should be added, to check that the user is actually keeping track of what he does (ie. implement an algo that can terminate...). That would be a bit more appropriate considering the rank.
cheers
all done except big cyclic graphs
No random tests.
No sample tests.
This comment has been hidden.
the graphs are directed. going from
A
toB
is not the same as going fromB
toA
This comment has been hidden.
This comment has been hidden.
visited
should not be stored as a global variable, this will cause previous calls to thegetRoute
function's nodes to be stored within, causing sub-sequent calls with an entirely new arguments passed to the function to have unvisited nodes invisited
Some possible tests, if anyone is lost (as I was):
Would be nice to state what you expect from the function, if boolean value or path. I know its not a big deal but a simple test case with expected value, makes the nice graph kata easier to understood.
It might make sense to explain that node values could be used to uniquely identify node, since we have to use strings as keys into a set/hash of visited nodes.
No tests
This was fun. Yet, there is room for improvement.
There should be at least one sample use of the function in the problem description.
I thought the labels would be used as parameters to the function.
Thanks again!
rewrote the description
I'm passing the first nine test cases. However, I'm having trouble debugging the 10th. I get a TypeError if I try to use console.log on anything beyond the 6th test case.
You might want to mention the console.log(a,b) hangups in the description an potentially provide alternative debugging methods.
I see you managed to solve it - any idea what was causing the console.log issues? I imagine it had something to do we resetting the nodes[] object during testing?
I think it could have been because of a cycle in the graph. I'll take a look at it again and update this post.
Edit: yep, that's it:
So does this need to be logged as an issue?
console.log(some_var) where some_var has a cycle causes console.log to break.
The simplest construction I can think of for a cycle:
var x = {}; x['self'] = x; console.log(x);
I just tried this in the kata editor and that code would now output:
{ self: [Circular] }
. If that's consistent with kata submissions, the issue is resolved now.added messages
Wow, not used to this graph representation.
It's a nice kata, but please fix the starting code to be valid javascript.
Fix initial solution code please. It's
var getRoute(a,b){
, but it should have at least correct syntax.Fixed, I wish validation also did a syntax check on the initial setup.
That would break kata where the point is to fix an invalid setup, unfortunately.
Yes, but this kata is not to fix bug, it's to write algorithm.