Friday, 24 April 2015

new interesting question

This question talks about what I previously talked about... That the Tree class we constructed does not necessarily lead to a tree. cycles are permitted in the implementation and the objective is to find out whether this is in fact a tree.

First, we need to realize that the node may still be part of a something Not a tree (ex. two things are pointing at it). But there is no way to know this from the node.

If you think about the tree rules - they can only be reached in one way. so you can never see the same node twice if you "traverse all the nodes once".

I think this is interesting because you can't use sets for nodes (mutable. hashing is not possible for mutable instances). Of course the easy way is to just use lists. But is there something that is immutable and representative of what I'm thinking of that I can substitute here? memory location. id values. Having two different nodes (ie. "A is B" is not true) is okay even if they have the same value (the value need not be unique). It's the object itself that must be different and I believe id captures this idea.

Anyhow, my soln:

No comments:

Post a Comment