View this PageEdit this PageUploads to this PageVersions of this PageHomeRecent ChangesSearchHelp Guide

MP6 Discussion

Q. Sagar Shah - June-20-2007 - For part 3, my partner and I have come up with different implementations of the do: aBlock method. The way I have it now is to perform aBlock on the root node's value, and then recursively call do: for the left and right sub-trees (in that exact order: root, left, right). I'm wondering if the ordering of these three tasks matters - my partner does this in the order right, root, left. My initial answer is that it doesn't matter - do: might affect the result of a statement like collect:, but collect: wouldn't work for a binary tree structure anyway. Any thoughts?

A:Nicholas Chen - June 20, 2007 - In this assignment it does not matter what order you do the traversal. However, since you already have a tree structure that imposes some ordering why not just make use of that order and have do: output things in order?

Notice if your do: does thing in order (ascending or descending), then when you do collect: you may have a unbalanced tree.


Q. Richard Young - June-19-2007 - In part 2, it says that class Set implements methods like union and intersect. However, I'm unable to find the method intersect, and when I send an intersect message to a Set, I get a doesNotUnderstand exception. What's going on?

Shayne Czyzewski - June-19-2007 - You need to actually use intersection:, which is defined in Collection.


Q. Matt Stockton - June-15-2007 - For the Binary Tree message -

"elementsInOrder - return a collection of the elements of the tree in ascending order."

Should we return a Collection of only the values of the nodes in order? Also, does it matter what subclass of Collection we return as long as its use is appropriate? (Collection is abstract so we should return an object whose type is one of its subclasses?)

A: Nicholas Chen - June 15, 2007

1) Should we return a Collection of only the values of the nodes in order?

I am not sure what you mean with this question. What other values would the collection include otherwise?

2) Also, does it matter what subclass of Collection we return as long as its use is appropriate?

It does not matter. You have more freedom on the implementation of this assignment since you are writing the test cases.



Q. Jeffrey Votteler - June-14-2007 - Part 1: For richer set, do you mean don't use do: but collect:, select: , etc. etc.

A: Nicholas Chen - June 14, 2007 - Yup. That is right.


Q. Sagar Shah - June-19-2006 - Part 2: Are we allowed to override the union: and intersection: methods for the DeMorgan's test?


A: Paul Adamczyk - June-19-2006 - You should be able to use the implementation of these methods in Set class.


Q. Elaine Savino - June 19-2006 - Part 3: When I try to inspect my tree for debug purposes, and try to look at certain instance variables, I get a message saying that printString or printOn is not implemented. Do we need to do this too? Why am I getting this message?

A: Paul Adamczyk - June-19-2006 - The debugger calls printString method on every object that it needs to display. So, if you're trying to inspect your BinaryTree class, you need to override printOn (not printString) method in that class. You can look at example implementations in other classes. You don't need to implement this method for this assignment, but if it helps you in debugging, then feel free to add it.


Q: Elaine Savino - June-19-2006 - Part 3: In a usual binary tree aren't the lesser values to the left and the greater values to the right? I believe this is saying the opposite.

A: Paul Adamczyk - June-19-2006 - That's why it's the "mirror" image, I guess. I haven't noticed this, but you're right. You can implement it either way as long as your test cases work.


Q: Nevedita Mallick - June-18-2006 - Part 3.2: Do we have to add/override extra methods to make collect: and select: work, or just a reasonable explanation of why it might not work be ok?


A: Paul Adamczyk - June-18-2006 - Just an explanation is sufficient. Put it after all the code in your MP submission.


Q: Nevedita Mallick - June-17-2006 - Part3: I assume that there will be duplicates in the resulting tree. The question says "value stored in a node is greater than or "equal to" the values of its right-most child or any of its children. Likewise, the value stored in a node is less than or "equal to" the values of its left-most child or any of its children", shouldn't the "equal to" be only on one side?

A: Paul Adamczyk - June-17-2006 - You're right. It's up to you which "equal to" you'd like to remove, as long as you're consistent in your implementation.


Q: Nevedita Mallick - June-17-2006 - Part3: The question asks us to make BinaryTree a subclass of Collection. In that case we will have to implement the ordering. Are we supposed to do it that way? Won't it be better to make it a subclass of Sequenceable collection?

A: Paul Adamczyk - June-17-2006 - If you mean that BinaryTree should be a subclass of SequenceableCollection, because you will implement ordering in the collection, then you may have a valid point. But since you won't be using any methods implemented specifically in that class, then subclassing from SequenceableCollection won't give you any additional benefit.

On the other hand, if you means that you could reuse some of the methods from SequenceableCollection to implement ordering of BinaryTree, then you are incorrect. Ordering of the BinaryTree should be implemented by recursively asking the children to order themselves. If a node is a leaf node (no children), then it just returns itself and its parent is responsible for concatenating the partial result and returning it to its parent.



Link to this Page