Faculté de génie École d’ingénierie et de technologie de l’information
University of Ottawa
Faculty of Engineering
School of Information Technology and Engineering
Introduction to Computer Science II (ITI 1121) Final Examination: Solutions
Instructor: Marcel Turcotte April 2008, duration: 3 hours
Identification
Student name: Student number: Signature:
Instructions
1. 2. 3. 4. 5. 6. This is a closed book examination; No calculators or other aids are permitted; Write comments and assumptions to get partial points; Beware, poor hand writing can affect grades; Do not remove the staple holding the examination pages together; Write your answers in the space provided. Use the backs of pages if necessary. There are two blank pages at the end. You may not hand in additional pages.
Marking scheme
Question 1 2 3 4 5 6 7 8 Total Points 10 15 15 10 5 10 15 10 90 Score
April 2008
ITI 1121
Page 2 of 25
Question 1
(10 points)
For this question, the classes Queue and Stack both implement the interface LinearCollection.
«interface» LinearCollection +add(E item):void +remove():E +isEmpty():boolean
Queue
Stack
Queue, as all the other implementations of a queue, is such that the method add enqueues the item at the rear of the queue, the method remove dequeues the front element, and the method isEmpty returns true if this queue contains no elements. Stack, as all the other implementations of a stack, is such that the method add pushes the item onto the top of the stack, the method remove pops (removes and returns) the top element, and the method isEmpty returns true if this stack contains no elements. A BinarySearchTree was created by adding elements in the order that follows; the resulting tree is shown to the right. BinarySearchTree t; t = new BinarySearchTree(); t.add( t.add( t.add( t.add( t.add( t.add( t.add( t.add( t.add( 3 1 7 9 5 4 6 2 8 ); ); ); ); ); ); ); ); );
3 1 7
2
5
9
4
6
8
A.