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

Sum01 Final Exam Review: Collection Differences


1. Identify a use where Arrays are the best choice?
When program wants quick access to data. Can retrieve data using the array indexes.
2. Identify a use where Bags are the best choice?
When a program doesn't really care about order just want to know of presence of an object and its occurences.
3. Identify a use where Dictionaries are the best choice?
Tieing 2 things together. aDict at: 'dog' put: 'rufus' (from slides)

qwerty



You've described what the different collections mean, which is extremely important. Let's talk about performance, though. Try to describe a case would each collection be a big performance win over the others. It's good to pick the most convenient collection to start with, but it's not too much work to switch later if you find a performance problem. How do you know what to switch to? -Lex Spoon


Arrays are fast because its implemented using primitives.
Collection are good for things that need sorting.
Bags is good for counting occurences and keeping multiple of same object.
Dictionary for definitions, association and stuff
1) Arrays are best when your algorithm will require iterating through your collection frequently, since they are fastest for indexed access.

2) Bags are best where you're not going to iterate a lot, but simply know how many of one object exists in your collection.

3) Dictionaries are best when you want to quickly access certain items by name without iterating to find them.
b. Sets are much faster than Arrays for figuring out if an element is in the collection because it uses a hash table.

c. OrderedCollections are much slower than Arrays when adding to it; it's almost the same speed as Arrays for at:put:; it's slower because it doubles in size on each add(grow). -doria

It wasn't shown in class, but #do: (iteration) is actually pretty fast for all collections in Squeak. It's a little faster for Array's, but then again most operations are a little faster for Arrays.... except the ones that are much slower!

It's not true that all additions are slow for OrderedCollections. Only the ones that trigger grow's are slow. Over time, the average access time is a constant factor slower than Arrays, which probably isn't a big deal. In some applications, though, it is possible that the grow pauses will be a problem, however.








Link to this Page