6 kyu
The Binary Tree, or There and Back Again
166 of 351dmitvitalii
Loading description...
Algorithms
Data Structures
Trees
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.
[Python]
Tests should fail without raising exceptions if the result is not valid.
I initially forgot the return statement and got
AttributeError: 'NoneType' object has no attribute 'equal'
I made a quick fix that will behave gracefully, except when the user actually returns None. Do you think it's acceptable?
oh, forget that... (was missing your last line... Back to it...)
.
Python Translation
.
JS:
Is the problem here the
[Object]
s? Or should I be reading something else into it?The problem is the log shows no difference between actual and expected.
Javascript should use a node/tree class like the other (and original) languages. Currently it just doesn't respect the kata specifications.
The only real difference between JS and Java versions is the added purity requirement which genuinely shouldn't be there. Objects lacking a pointless
Node
wrapper is definitely not an issue, though.It would be pointless if the kata was not rotate a binary tree.
I don't understand the problem. The encoding is specified, appropriate, and a binary tree. Whether the specific class is
Object
or something custom does not really matter.The purity requirement is mostly because modifying your arguments makes test failure messages weird, and deep-freezing inputs is not a real solution either ( as well as bug-prone ). But this was not raised as the issue anyway - if you want that changed, please raise that as a separate issue. ( I'm willing to discuss the merits, but I will not be doing it. I just don't think it's a good idea. )
For me an array or such is not a proper way to encode a tree, but I'm just ignorant.
About the purity question: can't you just use different deep copies of the object? It was the cause of my failure and it is absent from the original language. Should I raise an issue about that? It's the point of tree rotations to change the tree in place.
This comment has been hidden.
JavaScript translation
Approved
Please consider the issue I've raised above. I think it's still the time to rectificate.
Haskell translation
OP has left the building. PUs welcome to approve this.
OP, your profile says you have been here this month. Kindly approve the translation.
Approved
The description says that "The rotation is changing a root of the tree to be next or previous leaf of the current root", but shouldn't it say child? In the first example the previous leaf of 9 is 8, but after rotation the new root is 7, which was originally 9's previous child.
OK, changed for better understanding.
In this case, leaf == child, meaning a root has children, they are leafs.
The definition of a leaf is 'a node with no children', so not all children are leaves.
Fixed.
Bilbo?
The Hobbit?
;o
What happens if the tree cannot be inverted?
Thanks for the pointer. If the tree cannot be inverted, one should return the original one. Added this information and tests for such cases.
Currently, Kata has unresolved issue with tests.
Solved issues with random tests.
This comment has been hidden.
This comment has been hidden.
I've finally got the point about mutability and safety of a random function. Thanks, fixed.