Professional Documents
Culture Documents
Midterm 2 Practice A
Midterm 2 Practice A
Fall 2013
QUESTION VALUE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
10
10
10
6
6
6
6
6
15
5
5
6
4
10
6
TOTAL
111
1
SCORE
1. (10 points)
Draw the binary search tree whose elements have been inserted into an initially empty tree in the
following order:
50, 72, 96, 107, 26, 12, 11, 9, 2, 25
2. (10 points)
The following code fragment compiles and runs without error. What output does it produce?
int num = 1;
int max = 20;
while (num < max)
{
if (num % 2 == 0)
System.out.println(num);
num = num + 1;
}
3. (10 points)
Assume that you have a computer system that has 3500K available for user processes. This memory is initially empty, and is assigned to programs in contiguous blocks using first-fit allocation.
Consider the following sequence of events:
After this sequence of events, how much free memory is available for use? Can the computer
accommodate another process that requires 1000K of memory? Why or why not?
4. (6 points)
Which of the following hexadecimal sequences correctly represents the following Pep/8 instruction?
Load the value 31 into Register 0
(a) E10011
(b) C1001F
(c) E1001F
(d) C0001F
ANSWER:
5. (6 points)
Consider the following list of processes, with their total CPU times:
Process
------P1
P2
P3
P4
P5
CPU Time
-------3
8
4
5
2
Assume that the processes have arrived in the order shown above, but none of them has started to
execute yet. Draw a diagram to show how these processes will be executed under a shortest-job-first
(SJF) strategy and under a round-robin (RR) strategy with a time slice of 2.
SJF:
Round-Robin:
6. (6 points)
Briefly describe the difference between the SCAN and LOOK disk scheduling algorithms.
7. (6 points)
Briefly explain how stacks and queues work.
8. (6 points)
List one advantage and one disadvantage of virtual memory.
Advantage:
Disadvantage:
9. (15 points)
Write some Java code to do the following:
1. Read in two words representing passwords and store them in the String variables below.
2. Print out the number of characters in the shorter of the two words.
For example, if the user enters open and sesame, your code should print out 4 (the number of
characters in open).
10. (5 points)
What is the result of performing a 2-bit right circular shift on 10011001?
(a) 11001100
(b) 11100110
(c) 00100110
(d) 01100110
ANSWER:
11. (5 points)
Which of the following is NOT a part of the memory hierarchy?
(a) RAM
(b) The hard disk
(c) The control unit
(d) None of the above
ANSWER:
12. (6 points)
The SBU 2010 CPU contains a pipeline that uses six stages: Fetch, Decode, Load Arguments,
Execute, Writeback, and Update. This pipeline processes instructions at a rate of one stage per
clock cycle. Assume that you have 10 instructions to process, and that the pipeline is empty to
begin with. Calculate the number of clock cycles that you will save by using pipelining
instead of using a non-pipelined approach. You must show your calculations (including any
formulas you use) in order to receive any credit.
13. (4 points)
Consider the following Java String:
String s = "abcdefghijklmno"
Write a Java expression that will return the substring "fghijk" from this list.
15. (6 points)
Given an array of integers named x and an integer variable named total that has already been
declared and initialized to 0, write some code that places the sum of all the elements of the array
x into total. Declare any additional variables that you need.
10