Vous êtes sur la page 1sur 5

Course No: ITGD2201 Course Title: Computer Science II Date: 07/ 11 / 2008 (10:00 12:30) No.

of Questions: Questions Time: 2 hours Using Calculator (No)

University of Palestine

Midterm Exam 1 semester 2008/2009 Total Grade: 100


st

Instructor Name: Mr.Ahmed Al Astal Student No.: _________________ Student Name: _______________ College Name: IT Dep. / Specialist: ______________ Using Dictionary (No)

First Question Q1 B1 Choose the best Answer:

No. of Branches (1)

(20/100) (20/20)

1) Suppose we start with an empty stack and then perform the following operations: Push (A); Push (B); Pop; Push (C); Top; Pop;
a) b) c) d) e) B,A,C B,C,A C,A,B A,B,C None of the above

2) Which choices of C and n0 would work in this definition to show that n2 + 3n is O(n2)?
a) n0 = 1, c = 4 b) n0 = 3, c = 2 c) A and B d) None of the above

3) Suppose that we are working with linked lists that are circular, singly-linked, and have no head node. Suppose that the link field is named next. Assume L is the first node in a nonempty list, and let x be any node in this list. Which of the statements below is true if and only if x is the last node in the list?
a) x = null b) x.next = null c) x.next = L d) x.next = L.next

4) Suppose we are implementing a single queue, which is to hold up to n elements. Which choice below is an advantage of the linked implementation of queues over the sequentialimplementation in arrays?
a) The linked implementation requires far less space b) The linked implementation permits insertions to the queue in only O(1) time. c) The linked implementation permits deletions from the queue in only O(1) time. d) None of the above

1/5

Course No: ITGD2201 Course Title: Computer Science II Date: 07/ 11 / 2008 (10:00 12:30) No. of Questions: Questions Time: 2 hours Using Calculator (No)

University of Palestine

Midterm Exam 1 semester 2008/2009 Total Grade: 100


st

Instructor Name: Mr.Ahmed Al Astal Student No.: _________________ Student Name: _______________ College Name: IT Dep. / Specialist: ______________ Using Dictionary (No)

5) Let x be a node in a linked list L which has a sentinel node, is doubly-linked, and is not circular; L points to the sentinel node. Let x be a node corresponding to some data element (so x is not a pointer to the sentinel). Under what conditions would the following statements fail to correctly delete node x from the list next=x.next; prev=x.prev; next.prev = x.prev prev.next = x.next;
a) x corresponds to the rst element of the list being represented b) x corresponds to the last element of the list being represented c) A and B d) None of the above{these statements would perform the deletion correctly in all cases.

6) You have implemented the queue with a linked list, keeping track of a front node and a rear node with two reference variables. Which of these reference variables will change during an insertion into an EMPTY queue
a) b) c) d) Neither changes Only front changes Only rear changes. Both change.

7)

Consider the following pseudocode:


declare a stack of characters while ( there are more characters in the word to read ) } read a character push the character on the stack { while ( the stack is not empty ) } pop a character off the stack write the character to the screen }

What is written to the screen for the input "carpets"? a) serc b) carpets c) steprac d) ccaarrppeettss.

2/5

Course No: ITGD2201 Course Title: Computer Science II Date: 07/ 11 / 2008 (10:00 12:30) No. of Questions: Questions Time: 2 hours Using Calculator (No)

University of Palestine

Midterm Exam 1 semester 2008/2009 Total Grade: 100


st

Instructor Name: Mr.Ahmed Al Astal Student No.: _________________ Student Name: _______________ College Name: IT Dep. / Specialist: ______________ Using Dictionary (No)

Second Question No. of Branches (3) Q2 B1 Explain Briefly each of the following terms:
1) 2) 3) 4) Robustness. Adaptability. Abstraction. Modularity.

(25/100) (8/25)

Q2 B2

(6/25)

Describe why it is a bad idea to implement a linked list version of a queue which uses the head of the list as the rear of the queue?

Q2 B3

(11/25)

In the following diagram a reference is indicated by an arrow, the list nodes have an info variable containing an integer and a next variable containing a reference, and list, ref1, and ref2 are references to a list node.

a) Give the values of the following expressions:


ref1.info ref2.next.info list.next.next.info

b) Are the following expressions true or false?


list.next == ref1 ref1.next.info == 60 ref2.next == null list.info == 25

c) Write one statement to do each of the following:


Make list point to the node containing 45. Make ref2 point to the last node in the list. Make list point to an empty list. Set the info variable of the node containing 45 to 60

3/5

Course No: ITGD2201 Course Title: Computer Science II Date: 07/ 11 / 2008 (10:00 12:30) No. of Questions: Questions Time: 2 hours Using Calculator (No)

University of Palestine

Midterm Exam 1 semester 2008/2009 Total Grade: 100


st

Instructor Name: Mr.Ahmed Al Astal Student No.: _________________ Student Name: _______________ College Name: IT Dep. / Specialist: ______________ Using Dictionary (No)

Third Question Q3 B1

No. of Branches (1)

(15/100) (15/20 )

In the class ArrayIndexList, a linear list is represented using a one-dimensional array element. The data member size is such that the list elements are in positions 0 through size-1 of the array. The method removeNull (which is a method of ArrayIndexList) removes every null element of the list. For example, suppose that the list x is: [1, null, 3, null, null, 6] (list size is 6). Then following the invocation x.removeNull(), the list will be [1, 3, 6] (the size is now 3).

Write JAVA code for the member method removeNull. (Do not assume the existence of any
methods for ArrayIndexList).

Fourth Question Q4 B1

No. of Branches (1)

(20/100) (20/20 )

Two stacks of positive integers are needed, both containing integers with values less than or equal to 1000. One stack contains even integers; the other contains odd integers. The total number of elements in the combined stacks is never more than 200 at any time, but we cannot predict how many are in each stack. (All the elements could be in one stack, they could be evenly divided, both stacks could be empty, and so on.) Can you think of a way to implement both stacks in one array

a) Draw a diagram of how the stacks might look. b) Write a pseudo code for the push operation; it should store the new item into the correct stack according to its value (even or odd).

4/5

Course No: ITGD2201 Course Title: Computer Science II Date: 07/ 11 / 2008 (10:00 12:30) No. of Questions: Questions Time: 2 hours Using Calculator (No)

University of Palestine

Midterm Exam 1 semester 2008/2009 Total Grade: 100


st

Instructor Name: Mr.Ahmed Al Astal Student No.: _________________ Student Name: _______________ College Name: IT Dep. / Specialist: ______________ Using Dictionary (No)

Fifth Question Q4 B1

No. of Branches (1)

(20/100) (20/20 )

Suppose we are dealing with linked lists that are doubly-linked, have no list header, and are not circular; let L be the first node in the list. The Node class has three fields: data, next, and prev, with the usual meanings. Below is an example of this representation for the list A,B,C,D,E.

Write a JAVA function deleteSecond(L) that deletes the second node in the list that L represents.
(For example, starting with the list A,B,C,D,E shown below and calling deleteSecond(L) would yield the representation with the same conventions, of the list A,C,D,E.)

You may assume that the list has at least two elements, so there is a second element but make sure your code works correctly even when there are only two elements.

End of Questions Good Luck

5/5

Vous aimerez peut-être aussi