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

Sum00 Final Exam Review: Choosing your collection objects

a. Arrays - bubble sort, as you will need to iterate through the entire array several times.

Bags - a shopbot where you choose items to purchase over the web. This is since the order doesn't matter, you just add an item to a cart and when you are done, you want all the items and how many of each.

Dictionaries - airplane seating chart. You can easily look up the seat you are sitting in just by using your name and not have to iterate through the whole list.

b. For an array, you must iterate across it and check each element to see if it is correct to find an element. In a set, the implementation is a Dictionary, and it has a hash table to instantly determine if the element is there or not.

c. OrderedCollections are slow when they have to grow to hold the infomration given to them. They are about the same speed when the OrderCollection is already at the right size. They are slow to grow because they double in size for each time that they need one more space for an element. Also, when they are already at the same size, they are a little slower than arrays because an OrderedCollection checks bounds before performing an at:put:.

Adam Blaiss

Nice, but "bubble sort" is not a USE for arrays. Like, how often do people say, "Gee, I'd love a bubble sort about now..." :-) Mark Guzdial

Yeah, I know, but I was actually having difficulty coming up with a concrete use that definitely uses iteration repeatedly to justify using an array. How about a bank ledger where all of the fields need to be added or subtracted to get a final balance? I'd really like to get some ideas from people since an array just doesn't seem to be as useful in real life scenarios as a dictionary based object.

Adam Blaiss

How about using an array when you know it's going to be small like (bad example) but an array of User ID's where you only can see ten users at one time...

A real place where you use Arrays is when you have to pass a CHUNK of CONTIGUOUS memory, like to a device or to a primitive. Mark Guzdial

CONTIGUOUS \Contig"uous\, a. [L. contiguus; akin to contigere to touch on all sides. See Contingent.] In actual contact; touching; also, adjacent; near; neighboring; adjoining.

Link to this Page