5 kyu

Find whether there is a route between two nodes in a graph

306 of 333ykagan
Description
Loading description...
Recursion
Algorithms
Graph Theory
  • Please sign in or sign up to leave a comment.
  • luis-orantes Avatar

    how is suppossed to have access to the matrix of connections? with just 'a' and 'b' should we get the result?

  • Blind4Basics Avatar

    Java:

    • why E->E should be considered false? nothing is said about that.
    • the interface of the Node class is rather poor. Looking at the JS version it seems to be the intent (meaning: no equals/hashCode implementation). But in that case the description has to be clear about the values of the nodes: can to different nodes have the same value or not?
  • LosBlobbos Avatar
  • Blind4Basics Avatar

    Raising about the elephant in the room, since FArekkusu seems to be missing the almost obvious...

    • edges can be undefined. That's bad, and that's not said. Edges should be an empty array by default
    • 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.
    • the node class should be in preloaded or even in the tests themselves
    • inputs aren't properly described in... the description. Just be explicit, you're sort of at two words of the appropriate sentence...

    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

  • FArekkusu Avatar

    No random tests.

  • FArekkusu Avatar

    No sample tests.

  • gslav27 Avatar

    This comment has been hidden.

  • wasifzaman Avatar

    This comment has been hidden.

  • johnnash03 Avatar

    This comment has been hidden.

  • nwr Avatar

    Some possible tests, if anyone is lost (as I was):

    var 
    f = Node("f", []),
    g = Node("g", []),
    h = Node("h", []),
    e = Node("e", [g]),
    d = Node("d", [f, g, h]),
    a = Node("a", [d]),
    b = Node("b", [d, e]),
    c = Node("c", [e, h]);
    
    Test.expect(getRoute(d,f), 'getRoute(d,f) should have been true');
    Test.expect(getRoute(a,f), 'getRoute(a,f) should have been true');
    Test.expect(getRoute(b,f), 'getRoute(b,f) should have been true');
    Test.expect(getRoute(c,g), 'getRoute(c,g) should have been true');
    Test.expect(getRoute(b,d), 'getRoute(b,d) should have been true');
    Test.expect(getRoute(c,h), 'getRoute(c,h) should have been true');
    Test.expect(getRoute(e,g), 'getRoute(e,g) should have been true');
    Test.expect(getRoute(b,d), 'getRoute(b,d) should have been true');
    Test.expect(!getRoute(d,a), 'getRoute(d,a) should have been false');
    Test.expect(!getRoute(c,f), 'getRoute(c,f) should have been false');
    Test.expect(!getRoute(a,e), 'getRoute(a,e) should have been false');
    
  • marian.ivanco Avatar

    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.

  • eachofwhich Avatar

    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.

  • topkara Avatar

    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!

  • jacobb Avatar

    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.

  • jacobb Avatar

    Wow, not used to this graph representation.

  • Abbe Avatar

    It's a nice kata, but please fix the starting code to be valid javascript.

  • SagePtr Avatar

    Fix initial solution code please. It's var getRoute(a,b){, but it should have at least correct syntax.