View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Questions on Tree Milestone

See Spring 2000 Project Milestones
Ask questions here or on the newsgroup,

note to class:
i'd like to propose a swiki policy.
if your question is specifically about the requirements of a project, post it here.
if your question is really about sqeak or smalltalk or implementation issues, please post it on the newsgroup.

does that sounds like a good idea? (if you really think it sucks, btw, feel free to edit this page and delete this request)


Put Squeak questions in the Squeak FAQ. Mark Guzdial

how do I fix a bad image file? I somehow managed to make squeak die on
me, and when I loaded up my image, it said it can't locate the changes
file, even though it is present.

I tried to re-accept my code, but it took out all the commented parts
and smushed everything together.

Any help?

If your image is totally hosed, you can't repair it. But you can get all of your code out of your changes file into a new image – see p. 50. Mark Guzdial

We discussed in class how to create a LL, as it pertained to our project. Are we not permitted to use the built-in LL in Collections-Sequenceable??

Thanks in advance

Stephen Belknap
You can use anything in Squeak you want. I was merely offering an example. Mark Guzdial

Can you give us any hints on the best way to draw a Tree like shown on the other page.

Hint (not a commandment, merely a suggestion): Do it on paper. Figure out where you'd want to put things for a binary tree, then a 3-ary tree, and decide how flexible you want to be. Mark Guzdial

Also why does the class Tree do display instead of the root node myTree. Does it matter which way we do it. Being able to print from the instance seems better because then we can chose to print the whole tree or just subtree's of the whole.

Tuesday 11th 6:23 pm

By the end of Chapter 3, you'll know everything you need to know to display things as you see them on Spring 2000 Project Milestones. And the Tree thing was a bug – thanks for catching it! Mark Guzdial

Ok I have read the section on pen and now know how to draw. But the only thing I could find to draw on was a form. What should I use to make the form constant ie. movable. Also from the object oriented view should this require more than one object. If not how would you suggest doing the search? I am assuming I should use a depth first search.

Another question is is this just a binary tree or an n-nary tree. If it is an n-nary tree then isn't dynamically allocating an infinite number of node over a finite space such that the spacing is even, an unsolvable problem within a resonable time?

Chris Spears

Wednesday 12th 2:30

Yes, you draw on a Form. The Display is a Form. You don't have to make anything movable for the first assignment. You'll certainly need more than one object. You decide if you need more than one class. It's an n-ary tree. Yes, it's NP-complete. (NB: Consider how this assignment is relevant to the newspaper problem.) You might want to ask about this in class – it's a good point. Mark Guzdial

So how would you suggest doing a TreeWidth procedure. Those aren't so easy to write and that is where the exponential growth comes in. Can we assume a max number of nodes. Or do you just want use to write it all out.

Chris Spears

Monday 17th 6:00pm
There are no procedures in Squeak, and message names always begin with lowercase characters, so no "TreeWidth procedure." Mark Guzdial

Are there constructors in squeak? I've looked, but I am having a hard time differentiating between class instance vars and instance vars. Basically, I was trying to overload the new message so I can instantiate an OrderedCollection when my Tree class gets the new message. This way I don't have to always check to see if myOrderedCollection = nil. Any ideas?

Gary Herndon

You do not need any class variables in this assignment! Not at all! Suggestion: do not use them! Mark Guzdial

I refer myself and others to SmallTalk-80 pp79-80 to figure out object constructors.
Gary Herndon

Is there any ideal range of how many nodes we should set as the max to be able to display, or is it up to us? Also, can we design the graphic representation to not display all nodes at once, and allow the user to click on the children to expand to a finite amount of subtrees?

Kyle Randolph
I wouldn't make this round interactive. I'd just display as much as you find reasonable, but at least display all of a binary tree to a reasonable depth. Mark Guzdial

I would just like to know why it is that squeak won't always fileOut ?
Instead it is just throwing an error and frequently then crashes all of the Squeak programming environment so that I lose all my code. I'd like to not have to either cut and paste saved copies of my code in from else where all the time and not lose my code so if anyone knows what I'm doing to make it so that squeak won't file out I'd REALLY like to know. Thanks.

Jacqueline Walker

You never lose all your code! (I think I said that a few times in class.) Try editing your changes file, or read page 50 for how to recover your code without using an editor. If you could tell me the error, I might be able to help figure out what's going on. I've never had an error on fileOut. Mark Guzdial

I don't know if this helps, but I just have several workspaces open in Squeak and I just save the image as cs2340.image, and never close those workspaces.

Susi Rathmann

Do we need to handle errors? Such as if the user types myTree at:5 and there are only 3 sub-nodes, are we going to have to deal with the user sending in bad information?

Jason Dalton

followup question: i'm assuming the answer to the above is yes (mark or a TA can verify that). but a second error can occur:
(myTree at: 10) content: 'i'm child number 10'.
let's say myTree only has 5 child nodes. my code detects the error in the at: message, notifies the user, and returns nil. this, of course, causes an error because nil doesn't understand the content: message. does our code need to handle this second error?

We will not purposefully do bad things to your code, but mistakes can happen. Your code should not break. Mark Guzdial

Do we have to write code that will never display outside the 300@300 box? I mean, obviously we should try to stay within the box, but will we be counted off if it ever displays outside the box?

Jared Ivey
Try to stay inside of 300@300. Drawing outside will not be points off, but display outside of 300@300 may not be considered when deciding if you have a "good" display. Mark Guzdial

When printing a literal array, how inmprtant is it that the pound sign is printed at the beginning?

Chad VanWie

Which is more important: staying in bounds or displaying non-overlapping content? Thanks.


Do we need to dynamically figure out the spacing between nodes, or
may we do it statically. Thus, draw as much of the n-ary tree as
the restrictions on screen size allows, and then print a meesage
that simply says parts of the tree are undispalayed.

Mike Yunis

Your call. Mark Guzdial

I'm having trouble figuring out where to create an instance of a collection on this homework. Is there a way to create one when we say "Tree new"? Otherwise I don't see where in the first few lines of the example usage the instance of the collection is being created.

More importantly, how do you create an instance of a collection?
The book and notes aren't helpng me too much.

Max Speyer

OrderedCollection new. Mark Guzdial

This may be a stupid question but by an n-ary tree you are saying the root can have any number of sub nodes in the first "row" underneath it? So instead of having
"|" left right "|" we would instead have something like "|" one two three . . . whereWeWantToStop "|" or a better way or implementing that.?

Richard McPhaul

Yes, that's what an n-ary tree is. Yes, that's one way of handling it. Mark Guzdial

If the at: method is used to access a nonexistant code, how are we to handle it? Should we create an error message to pop up? Or do nothing at all? Thanks,

Shaun Morber

You decide. We won't do this on purpose, but if we do it on accident, the behavior should be reasonable – understandable error, or return something reasonable. Mark Guzdial

Ok, if I've got a tree class, how can I declare one of my instance variables inside it to be an array at the very beginning? I want to use an array to hold some objects (hmm.....) and I need to know how to have this array in there from the get go.
David Jaggie

Well, since no one seems to be paying attention here, I'll sort of answer myself. You have to do this in the 'new' method, either by finding a class where this is already done, or by overriding.

David Jaggie

For your learning, it's ALWAYS better to answer your own questions! Remember that the point of the project is for you to learn something along the way. I'd rather that the TA's and I were all silent if it leads to you discovering things for yourself more! Mark Guzdial

I've been hunting through both books to the answer to this question but can't seem to find it. Does squeak allow for a Linked Lists of Linked lists? If so is there anything special I have to do for this?

Adam Gershowitz

It probably does. But you're better off building your own data structure. Seriously – it's less than a dozen lines of code Mark Guzdial

Re: instance variables and how to create/initialize

This is how I do it:

give your Tree an instance variable like 'list'

make a CLASS method:


newTree "temp var, vert bars == box on coweb"

newTree_super new.
newTree initialize.
then, make an instance method:



list_SomeCollection new.
I'm not a T.A. but that seems to work, anyone feel free to correct
me if it isn't.

Lelyn Tyson

(Yes, but this method suffers from the problems Mark illustrated in class... it is tempting to write code that calls initialize twice when subclassing tree. I prefer the approach on p. 85 of the ST-80 book. The basic idea: Introduce private intialize methods that are only responsible for initializing the non-inherited fields. Override new to use this private initializer appropriately. Finally, never subclass the initializer [in Java, you would mark it "final"]. Stephen Bennett)

That technique that Stephen describes is called "lazy initialization" and we'll talk more about it in Chapter 4. Doing new as ^super new initialize works, too. Mark Guzdial

How about this way which I believe is similar to the one Stephen suggested:

You have an object Item with two class methods:


newItem_super new.
(newItem class) initialize:newItem.

initialize: newItem

newItem name:'Item'.
newItem otherVar: value.

then in item's sub-class Chair you overide only initialize

Class method:
initialize: newItem

super initialize:newItem.
newItem name:'Chair'.

Using this manner you can chose whether the initialize
for the super-class (Item) is called in addition to Chair's, instead of Chair's, or not called at all.

Is this at least better than the first(my) way?

Lelyn Tyson

I'd like to take a moment to point out that very few questions either here or the on the newsgroup, got answered by a person of responsibility if they were posted from yesterday afternoon on. I'm not whining like a 131x'er that "You didn't answer my post fast enough," but that virtually no one in authority checked these places at all after a certain time. I'm not expecting light from the heavens, but even a little hint or 2 for some people would have helped. Oh well. Back to coding the display.

David Jaggie

That's what happens when you wait until the last 24 hours to meet a deadline. In industry, do you think that the customer answers all the questions in the last 24 hours before delivery? Mark Guzdial

Not at all. However, considering this is the first assignment and we're all still getting our feet wet, it'd be nice to have some support. Thanks for checking this morning, BTW.

David Jaggie

Links to this Page