6 kyu
Binary Tree Compare
902 of 1,929bovard
Loading description...
Binary Trees
Algorithms
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.
maybe a link to some reading? this is potentially one of the first BT kata people will do. would be good to use it as a deliberate teaching moment
Interesting kata.
Scala translation
Approved by someone
Thanks bovard!!
My first true binary tree kata! Feeling good!!
In Python 3.10, I'm failing a
depth 2
test:Should return false for non-equal trees
.I've verified that my code returns false, but the test fails with 'True should equal False'
The tree structure is
Am I missing something?
Update: I've hard-wired the code to check for this tree, verified the branch with prints statements in the log, but the test fails regardless of whether I return
True
orFalse
Hi; I just solved this and I must agree that it was quite frustrating to debug as the output/display of wrong results is not very clear.
Also, you are clearly on the right track - your recursive logic is correct but your base case is where things are going wrong I think.
Using your code, you are failing 3 of the fixed tests - however, none of these correspond to the trees that you have drawn above though (so I'm not sure how you managed to obtain that drawing).
For example, of the 3 test cases where your code is failing, the first one actually is testing the following pair of trees a,b:
and the expected answer is
False
for this input pair.Hopefully that helps you debug a bit better (I can't share with you more of the test cases because otherwise people could just hardcode the correct answer, as there are no random tests).
This comment has been hidden.
Haskell translation
Lua transaltion, with random tests as well.
approved
COBOL translation, including random tests (author is inactive).
approved
C translation (author inactive)
Approved :)
I passed 17 and failed 1, the second test at depth 2. But I passed the first test at depth 2 and it looks identical to the second test I failed. Can someone double check this for me because maybe I'm not looking hard enough at the two tests. They look the same to me.
()depth 2 Log { val: 3, left: { val: 1, left: null, right: null }, right: { val: 1, left: null, right: null } } { val: 3, left: { val: 1, left: null, right: null }, right: { val: 1, left: null, right: null } } Should return true for equal trees
Log { val: 3, left: { val: 1, left: null, right: null }, right: { val: 1, left: null, right: null } } { val: 3, left: { val: 1, left: null, right: null }, right: { val: 1, left: null, right: null } } Should return true for equal trees should return true - Expected: true, instead got: false
Issue with your code, do read this before raising issues next time and use question label pls ~~
This comment has been hidden.
C translation: https://www.codewars.com/kumite/5c3a99ddf42ec8000b083aac?sel=5c3a99ddf42ec8000b083aac
Can someone explain to me how this tree is equal? { val: 3, left: { val: 1, left: null, right: null }, right: { val: 1, left: null, right: null } } { val: 3, left: { val: 1, left: null, right: null }, right: { val: 2, left: null, right: null } }
That is the 3rd test case within the depth 2 tests. It is expecting true, but shouldn't it be false? The instructions say that they have to be equal in structure and value, but from what i see, they aren't equal in value.
This comment has been hidden.
This seems to be from a different problem.
This comment has been hidden.
Nobody's taken your suggestion for five years. Closing.
Hey there! So I pass the tests that are provided and the tests that I made. Whoot. The problem is that "val" is being caught for some reason. Does anyone have any insight on that? Here's what the actual text says: "AttributeError: 'NoneType' object has no attribute 'val'"... I only use 'val' when I'm writing a.val and b.val; again, it works fine in the testing phase, but not in the attempt phase. Thanks! :D
Same issue here.
a
andb
can be null (None
). Null values don't, and can't, have attributes. The error messages says this loud and clear. Try troubleshooting your solution. There is documentation for this.This comment has been hidden.
This comment has been hidden.
Maybe, maybe not.
I'm having a problem, my code works in the IDE but not here. language: python
def compare(a, b):
This comment has been hidden.
This comment has been hidden.
Some spelling errors are present in the problem description and comments.
Fixed, thanks!
Fixed! Thanks