5
Instructor Name: Mr.Ahmed Al Astal Student No.: _________________ Student Name: _______________ College Name: IT Dep. / Specialist: ______________ Using Dictionary (No) University of Palestine Midterm Exam 1 st semester 2008/2009 Total Grade: 100 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) 1/5 (20/100) No. of Branches (1) First Question ) 20 / 20 ( Q1 B1 Choose the best Answer: Suppose we start with an empty stack and then perform the following operations: Push (A); Push (B); Pop; Push (C); Top; Pop; 1) a) B,A,C b) B,C,A c) C,A,B d) A,B,C e) None of the above Which choices of C and n 0 would work in this definition to show that n 2 + 3n is O(n 2 )? 2) a) n 0 = 1, c = 4 b) n 0 = 3, c = 2 c) A and B d) None of the above 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? 3) a) x = null b) x.next = null c) x.next = L d) x.next = L.next 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? 4) 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

Csii Mid Exam 12008

Embed Size (px)

Citation preview

Page 1: Csii Mid Exam 12008

Instructor Name: Mr.Ahmed Al Astal

Student No.: _________________

Student Name: _______________

College Name: IT

Dep. / Specialist: ______________

Using Dictionary (No)

University of Palestine

Midterm Exam

1st semester 2008/2009

Total Grade: 100

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)

1/5

(20/100) No. of Branches (1) First Question

)20/20( Q1 B1

Choose the best Answer:

Suppose we start with an empty stack and then perform the following operations:

Push (A); Push (B); Pop; Push (C); Top; Pop; 1)

a) B,A,C b) B,C,A c) C,A,B d) A,B,C e) None of the above

Which choices of C and n0 would work in this definition to show that n2 + 3n is O(n

2)? 2)

a) n0 = 1, c = 4 b) n0 = 3, c = 2

c) A and B d) None of the above

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?

3)

a) x = null b) x.next = null c) x.next = L

d) x.next = L.next

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?

4)

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

Page 2: Csii Mid Exam 12008

Instructor Name: Mr.Ahmed Al Astal

Student No.: _________________

Student Name: _______________

College Name: IT

Dep. / Specialist: ______________

Using Dictionary (No)

University of Palestine

Midterm Exam

1st semester 2008/2009

Total Grade: 100

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)

2/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;

5)

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.

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؟

6)

a) Neither changes b) Only front changes c) Only rear changes. d) Both change.

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"?

7)

a) serc b) carpets c) steprac d) ccaarrppeettss.

Page 3: Csii Mid Exam 12008

Instructor Name: Mr.Ahmed Al Astal

Student No.: _________________

Student Name: _______________

College Name: IT

Dep. / Specialist: ______________

Using Dictionary (No)

University of Palestine

Midterm Exam

1st semester 2008/2009

Total Grade: 100

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)

3/5

(25/100) No. of Branches (3) Second Question

)25/8( Q2 B1

Explain Briefly each of the following terms: 1) Robustness. 2) Adaptability. 3) Abstraction. 4) Modularity.

)25/6( Q2 B2 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?

)25/11( Q2 B3 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

Page 4: Csii Mid Exam 12008

Instructor Name: Mr.Ahmed Al Astal

Student No.: _________________

Student Name: _______________

College Name: IT

Dep. / Specialist: ______________

Using Dictionary (No)

University of Palestine

Midterm Exam

1st semester 2008/2009

Total Grade: 100

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)

4/5

(15/100) No. of Branches (1) Third Question

) 20/15( Q3 B1

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).

(20/100) No. of Branches (1) Fourth Question

) 20/20( B1 Q4

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).

Page 5: Csii Mid Exam 12008

Instructor Name: Mr.Ahmed Al Astal

Student No.: _________________

Student Name: _______________

College Name: IT

Dep. / Specialist: ______________

Using Dictionary (No)

University of Palestine

Midterm Exam

1st semester 2008/2009

Total Grade: 100

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)

5/5

(20/100) No. of Branches (1) Fifth Question

) 20/20( B1 Q4 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