Introduction To Computer Science-103 Final Exam
Introduction To Computer Science-103 Final Exam
Final exam
1. Three processes (A, B, and C) are running concurrently. Process A has acquired
File1, but needs File 2. Process B has acquired File3, but needs File 1. Process C
has acquired File2, but needs File3. Draw a diagram for these processes. Is this a
deadlock situation? (6%) (P7-9)
This is a deadlock situation (see Figure P7-9) because all four conditions of
deadlock (mutual exclusion, resource holding, no preemption, and circular waiting)
are all present.
2. Draw a diagram to show a linked list in which the data part is a student record
with three fields: id, name, and grade. (6%) (P11-13)
Figure .1
5. Please follow the program to show the results. (4%)
int x = 0;
if (x = 0 || x == 0)
printf("%d\n", x);
printf("%d\n", x);
1
1
6. Write an algorithm in pseudocode to apply binary search on an array of elements.
(6%) (P11-5)
The algorithm shows the binary search routine in pseudocode (see Chapter 8).
Note that we perform the binary search on sorted array. If flag is true, it means x is
found and i is its location. If flag is false, it means x is not found; i is the location
where the target supposed to be.
7. If the subprogram calculate (A, B, P, S) accepts the value of A and B and
calculates their sum S and product P, which variable do you pass by value and
which one by reference? (6%) (P9-23)
8. Write an algorithm to delete an element in a sorted array. The algorithm must call
a search algorithm to find the location of insertion. (6%) (P11-7)
The algorithm that insert an element in a sorted array has two parts. Part a shows
the main algorithm. Part b shows the algorithm named shiftup called by the insert
algorithm.
10. Using the selection sort algorithm, manually sort the following list and show your
work in each pass using a table: (6%) (P8-5)
14 7 23 31 40 56 78 9 2
The status of the list and the location of the wall after each pass of the selection
sort algorithm is shown below:
11. Using the UML diagram for the product algorithm, draw a diagram to calculation
the value of xn, when x and n are two given integers. (6%) (P8-38)
Figure 8-38 shows the UML for finding the power of an integer with an integral
exponent.
12. Please follow the program to show the results. (6%)
#include <stdio.h>
void delete_element (int value, int&array_size, int array[]){
int i,;
int location = array_size + 1;
array_size--;
}
int main(){
int i;
int arraysize = 10;
int a[10] = {0,1,2,3,4,5,6,7,8,9};
for (i=0;i<arraysize;i++)
printf("%d ",a[i]);
delete_element(5,arraysize,a);
printf("\n") ;
for (i=0;i<arraysize;i++)
printf("%d ",a[i]);
return 0;
}
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 6 7 8 9
13. Please show how to build a linked list from scratch using the insertion algorithm
(by following algorithm 11.3) (6%) (P11-16)
Algorithm P11-16 shows the routine in pseudocode for building a linked. The
routing uses the InsertLinkedList algorithm.
14. Show the contents of stack S1 and the value of variable x and y after the following
algorithm segment is executed. (6%) (P12-5)
stack (S1)
Push (S1,5)
Push (S1,3)
Push (S1,2)
if (not empty (S1))
{
pop(S1, x)
}
if (not empty (S1))
{
pop(S1, y)
}
push (S1, 6)
15. Write an algorithm to find the average of the numbers in a linked list of numbers.
(6%) (P11-17)
16. Write an algorithm that reverses the elements of an array so that the last element
becomes the first, the second to the last becomes the second, and so forth. (6%)
(P11-2)
註解 [m1]: 新增此題
17. Change the following code segments to use an if-else statement: (6%)