You are on page 1of 8

CSE 110 Midterm Exam 2 Practice B KEY

Fall 2013

NAME (please print in LEGIBLE block letters!):


Your University ID Number:
The name of the student to your LEFT:
The name of the student to your RIGHT:

Please use a pen for all answers.


No books, notes, or electronic devices may be used during the exam.
The last page of the exam contains a summary of helpful information, like Pep/8 opcodes.
Any CHEATING will result in an F as well as being written-up on academic dishonesty. Dont
place anything in a location where it might indicate that you are copying.
The score for a perfect exam (without extra credit) is 100 points.
NO-BS Bonus: If you do not know the answer to a problem and you leave it COMPLETELY
BLANK, you will receive 1 point for that problem (or part of a problem). If you write anything
in that space and it is wrong, you will receive a 0.

QUESTION VALUE
1
2
3
4
5
6
7
8
9
10
11
12
13

6
6
10
10
5
5
10
5
9
8
9
6
6

TOTAL

95

SCORE

1. (6 points)
Briefly describe how the SSTF disk scheduling algorithm works. What problem does it cause?
Shortest-seek-time-first compares the current disk head position to the cylinders that are still
remaining to be accessed. It always chooses to move to the closest remaining disk request; after
servicing that request, it again looks for the closest remaining request. Since new requests are
always coming in, SSTF may end up always dealing with newer, closer requests rather than dealing
with older but more distant requests. Those more distant requests may be significantly delayed in
getting taken care of.

2. (6 points)
Which of the three abstract data types (ADTs) that we discussed in class exhibits last-in-first-out
(LIFO) behavior?.
Stacks are a LIFO data structure.

3. (10 points)
Draw the binary search tree whose elements have been inserted into an initially empty tree in the
following order:
11, 26, 50, 2, 72, 96, 25, 107, 9, 12
2

4. (10 points)
The following code fragment compiles and runs without error. What output does it produce?

int num = 20;


while (num !=
{
if (num %
num =
else
num =

1)
2 == 0)
num / 2;
3 * num + 1;

System.out.println(num);
}

Output: 10, 5, 16, 8, 4, 2, 1

5. (5 points)
The last position number in a Java string is always:
(a) the number of characters
(b) 0
(c) 1 more than the number of characters
(d) 1 less than the number of characters

ANSWER:
4

6. (5 points)
What is the output of the following code?
int[] a = new int[20];
a[0]=12;
System.out.println(a.length):
(a) 1
(b) 12
(c) 19
(d) 20

ANSWER:

7. (10 points)
A sequence of instructions is given below. Write/draw the stack and the queue that would result
from following this sequence of instructions.

1. Add 2
2. Add 3
3. Add 4
4. Remove an item
5. Add 5
6. Add 6
7. Add 7
8. Remove an item
9. Remove an item

Stack: 2 3 5
Queue: 5 6 7

8. (5 points)
Which of the following statements is FALSE?
(a) Round-Robin guarantees that each process will receive a fair share of CPU time
(b) First-Come, First-Served can be proven to be the optimal process-scheduling algorithm
(c) Long-running processes may take longer to run to completion under Shortest-Job First
(d) A hard disk can be considered part of the memory hierarchy

ANSWER:

9. (9 points)
Assume that you have a computer system that has 2160K available for user processes. This memory
is initially empty. Draw a diagram to indicate what system memory will look like after the following
sequence of events:

1. Process 1 arrives and requests 600K of memory


2. Process 2 arrives and requests 1000K of memory
3. Process 3 arrives and requests 300K of memory
4. Process 1 terminates

600K free

1000K (P2)
300K (P3)
260K free

10. (8 points)
Write a Java loop that calculates the sum of all even integers between 2 and the value stored in
the variable n. You may assume that n has been assigned a value, and is greater than 2. You may
also assume that an int variable sum has been declared and initialized to 0.
for (int i = 2; i <= n; i = i + 2)
{
sum = sum + i;
}
11. (9 points)
What value will the function below return for each of the following input values? (3 points each)
boolean mystery (String input)
{
int left = 0;
int right = input.length() - 1;
while (left < right)
{
if (input.charAt(left) != input.charAt(right))
{
return false;
}
left = left + 1;
right = right - 1;
}
return true;
}
(a) alcoa

ANSWER:

false

(b) dgsgd

ANSWER:

true

(c) madam

ANSWER:

true

12. (6 points)
Consider the following list of values:
100, 22, 13, 81, 75, 3, 9, 56
Which of the following is a possible intermediate stage if we apply selection sort to this list?
(a) 13 22 81 100 75 3 9 56
(b) 56 22 13 9 75 3 81 100
(c) 13 22 75 3 9 56 81 100
(d) None of the above

ANSWER:

13. (6 points)
Which of the following is not a factor in the time required to service a disk I/O request?
(a) Seek time
(b) Rotational delay (latency)
(c) Data encryption
(d) Transfer time

ANSWER:
8

You might also like