Problem 95 - To Tree, or not to Tree -

239 views
Skip to first unread message

Peter

unread,
Jan 5, 2012, 7:28:18 AM1/5/12
to 4Clojure
Hello

I would expect that

[1 [2 [3 [4 false nil] nil] nil] nil]

would validate as a binary tree, but the problem seems to indicate it
differently

(= (__ [1 [2 [3 [4 false nil] nil] nil] nil])
false)

Why is this not a valid binary tree?

Tx

Peter

Peter

unread,
Jan 5, 2012, 7:29:53 AM1/5/12
to 4Clojure
Ah...never mind. I was misinterpreting the meaning of nil in the value

Apologies for the noise

Peter

chepprey

unread,
Jan 6, 2012, 3:57:50 PM1/6/12
to 4Clojure
No worries. I hope the "noise" actually starts picking up around here
again now that the holidays are over.

David

unread,
Mar 3, 2012, 5:28:59 PM3/3/12
to 4Clojure
I'm also confused why that wouldn't be a binary tree, anyone mind
clarifying?

Thanks,
David

Damien Lepage

unread,
Mar 3, 2012, 5:52:29 PM3/3/12
to 4clo...@googlegroups.com
The problem states that "Each node in the tree must have a value, a left child, and a right child."
So my understanding is that "false" is not a valid node because it is just a value, the 2 children are missing.
On the other side, "nil" doesn't represent an empty value, but means "no node", so it's fine as a left or right child.


2012/3/3 David <pick...@gmail.com>

David

unread,
Mar 3, 2012, 5:58:58 PM3/3/12
to 4Clojure
Ah ok that makes more sense and my solution passes all the tests now.
Thanks.

On Mar 3, 4:52 pm, Damien Lepage <damienlep...@gmail.com> wrote:
> The problem states that "Each node in the tree must have a value, a left
> child, and a right child."
> So my understanding is that "false" is not a valid node because it is just
> a value, the 2 children are missing.
> On the other side, "nil" doesn't represent an empty value, but means "no
> node", so it's fine as a left or right child.
>
> 2012/3/3 David <pickda...@gmail.com>
> @damienlepage <https://twitter.com/#!/damienlepage>
> linkedin.com/in/damienlepage <http://www.linkedin.com/in/damienlepage>

JorgeD

unread,
Sep 20, 2017, 5:19:15 PM9/20/17
to 4Clojure
Sorry for disturbing 5 years later, but... false is "just a value" but 1, 2, 3 and 4 are only just values and yet they are nodes (i.e., kind of roots of a subtree).

Why is false not a node?

Thanks in advance!

Leif

unread,
Sep 21, 2017, 6:18:06 PM9/21/17
to 4Clojure
Hi, Jorge.

To expand upon Damien's answer:

The difference is that 1, 2, 3, and 4 are at the "value" position.  The structure of these trees is either:
[value left-node right-node] (node with value)
nil (empty node)

These are the only structures that are valid nodes.

So, in [4 false nil], 4 is correct because it is in the value position, and doesn't have to be a tree, nil is correct because it is in the right-node position, and it represents an empty node.  "false," however, is incorrect because it is in the left-node position, but it is a value, not a node.  To make it a node, you would need to write [false nil nil].

HTH,
Leif

JorgeD

unread,
Sep 25, 2017, 4:08:47 AM9/25/17
to 4Clojure
Hi Leif,

thanks a lot - and please excuse me for the delay.

Now I see the problem: it was not about "false" being a value or not but it was all about the *position*!

Best regards,

Jorge
Reply all
Reply to author
Forward
0 new messages