3 kyu

Minimal Cost Binary Search Trees

Description
Loading description...
Algorithms
Binary Search Trees
Fundamentals
  • Please sign in or sign up to leave a comment.
  • vall-ball Avatar

    I get this answer: Test Results: Random Tests cost -- random Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed make_min_tree -- random Test Passed Test Passed STDERR Execution Timed Out (12000 ms)

    How can I understans what is going on?

  • fcr-- Avatar

    This comment has been hidden.

  • lechevalier Avatar

    This comment has been hidden.

  • dacostag Avatar

    What is being evaluated in the random test cases? I keep getting Test passed but a message immediately below of the form:

    "24704190 should equal 22467540"

    I am pretty sure this is not the cost of the tree, but I can't find where the number comes from.

  • bellaire Avatar

    This comment has been hidden.

    • ecolban Avatar

      It looks like you you have a Tree that is None. A Tree cannot be None.

    • bellaire Avatar

      Are you sure? I don't think there is any way for my code to return a None instead of a Tree. The code in the traceback is not my code, it is code from your random test generator. I do not how me creating a None tree (even if I were) would cause that error.

    • Greatlemer Avatar

      I've just completed this and didn't have any problems with the final tests. You may want to check your code again.

    • user9644768 Avatar

      Your code is wrong.

      Issue marked resolved by user9644768 5 years ago
  • ALowVerus Avatar

    Good kata, good fun! High five @ecolban!

  • _greyhound Avatar

    Some questions regarding the testcases of 2nd part of the problem:

    tree2 = make_min_tree([a, b]) Test.assert_equals(str(tree2), '[_ A:10 [B:2]]')

    Shouldn't we be checking whether the cost of the tree is minimum or not instead of equating the actual node placement? For example, The above answer could also be '[[B:2] A:10 ]' and still the minimum weight would be the same. There could be multiple trees with minimum weight.

    tree3 = make_min_tree([a, b, c]) Test.assert_equals(str(tree3), '[_ A:10 [[B:2] C:4 ]]')

    Isn't this wrong? The answer assumes the tree being: A
    C / B Here cost of tree = (10X1)+(4X2)+(2X3) = 24 However, this is not minimum. For example, A /
    C B Here cost of the tree = (10X1)+(4X2)+(2X2) = 22

    The test cases doesn't match what I understood from the question. Let me know if I am missing something.

    • Blind4Basics Avatar

      You're dealing with BST here, and a "special kind" (as in, not usual): what defines the relation between nodes isn't the weight of the nodes, but their value, which is here the symbol/string representing the node.
      So, because of this, '[[B:2] A:10 ]' is breaking the BST contract (B to the left of A) and isn't a possible answer.

    • JohanWiltink Avatar
      Question marked resolved by JohanWiltink 3 years ago