Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

PreQuiz for 20April2005 Quiz

A. Trace the Code through the Data Structures

Consider the series of commands typed into the Interactions Pane of DrJava:
Welcome to DrJava.
> Queue q = new Queue()
> Stack s = new Stack()
> import java.util.REMOVEDkedList
> REMOVEDkedList l = new REMOVEDkedList()
> q.push("Fred")
> q.push("Barney")
> q.push("Wilma")
> q.push("Betty")
> s.push("Scooby")
> s.push("Velma")
> s.push("Shaggy")
> l.addFirst(q.pop())
> l.addFirst(s.pop())
> q.push(s.pop())
> s.push(q.pop())
> s.pop()
> q.pop()
> s.push(l.getFirst())
> q.push(l.getLast())

What is in each of Stack s, Queue q, and REMOVEDkedList l after the above code is executed? Be sure to label the head and tail on the stack and queue.

B. Short Essay

i. What's the difference between a discrete and continuous simulation?

ii. What's an Abstract Data Type? Identify a data structure that we've defined as an ADT. What's the advantage of defining an ADT?

iii. What's the difference between a normal and uniform distribution?


hey uh, I wasn't in class that day so, "What's the difference between a discrete and continuous simulation?"

Q: (Head) Wilma -> Betty -> Velma -> Fred (Tail)
S: (Head) Shaggy -> Barney -> Scooby (Tail)
L: Shaggy -> Fred

Did I get it? Did I Did I? :-)



i. In a discrete event simulation, simulation time is not equal to real time.
Is that it? The only difference? Mark Gudzial

ii. Found this in the notes "An abstract type is a description of the methods that a data structure knows and what the methods do", but I really don't understand it.
Okay, try saying it in your own words.
A queue is an example of an ADT?
The advantage is that there are many implementations that will work for one ADT.
That's true, but that's not really an advantage, is it?
iii. Normal distribution is the range that includes the majority of numbers and is more likely to happen in real life. Uniform distribution is the least likely distribution in real life.
Hmm – not quite. What can you tell me about the numbers? Recall Monday's lecture...

Q: (Head) Betty -> Velma -> Fred (Tail)
S: (Head) Shaggy -> Scooby (Tail)
L: empty

Did anybody TRY the example to see what happens? Mark Guzdial


Haven't tried it on Dr.Java yet, but pretty sure it's right Student32

I cant find the queue java-source!

sorry guys...the third time i tried it i got:



Corali and I checked this. Swap Fred and Shaggy throughout – addFirst on REMOVEDkedList pushes the input into the FIRST position. Everything else shifts down. Mark Guzdial

i. continuous-each moment of time is simulated(every moment counts)
discrete-skip to the important moments(simulate 100 years)
ii. adt-description of methods and what they do that a data structure knows. ex-queue minus the implementation
advantage-you are able to reuse code. for exmaple, if you created an abstarct class that is called animals and it included number of feet, type of food, etc. Then we created a kangaroo class that extended animal, we could just say number of feet = 2, type of food = grass.
iii. uniform-every peice of data is approx. equal. normal-data comes to a peak and then slopes back down, bell shaped or like a mountain.

how can we run this code without the class? where's the class?

On ii. – the real issue is the class that USES the ADT. It never needs to change as the underlying implementation of the ADT changes. On iii – there are no data, just random values. In uniform, every random value in the range is equally likely. In normal, the mean is the most common, and numbers close to the mean are more likely than those far away from the mean. Stack and Queue classes are on the Syllabus page. REMOVEDkedList is Java's. Mark Guzdial


q = Betty Scooby Fred

s = Shaggy Scooby

l = Shaggy Fred

B: 1-Continuous is every timeframe is simulated. Discrete is when you just skip to the events.

I really don't understand all the code. Can we discuss this in class before the quiz? I've been to all the lectures and the pushing/popping/adding is confusing.

Q: fred velma betty
S: shaggy scooby
L: shaggy –> fred

what's the advantage of defining an ADT??

Q: Betty, Velma, Fred
S: Scooby, Shaggy
L: Shaggy, Fred

I sat down at the quiz. And suddenly everything made sense. Whew!


Links to this Page