Professional Documents
Culture Documents
Midterm 2 Practice B
Midterm 2 Practice B
Fall 2013
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?
2. (6 points)
Which of the three abstract data types (ADTs) that we discussed in class exhibits last-in-first-out
(LIFO) behavior?.
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
4. (10 points)
The following code fragment compiles and runs without error. What output does it produce?
1)
2 == 0)
num / 2;
3 * num + 1;
System.out.println(num);
}
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:
3
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:
Queue:
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:
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.
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:
(b) dgsgd
ANSWER:
(c) madam
ANSWER:
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:
7