DATA STRUCTURES, ANALYSIS OF ALGORITHMS AND COMPUTATIONAL COMPLEXITY
A | v B---->C---->D | | v v E->F G
typedef struct tree_node *tree_ptr;
struct tree_node {
char element;
tree_ptr first_child;
tree_ptr next_sibling;
}
a) Write the code, in the language of your choice, for either selection sort or insertion sort to put a[0]...a[n-1] into ascending order.
Assume that the array is declared by element a[n], where "element" has already been declared.
Variables of type element may be compared and assigned using the usual relational and assignment operators.
b) Give a big-theta description, along with a brief explanation, of the worst case number of
For each of the classes below, can the above algorithm be used
to prove the problem PRIME lies in the class? Explain each answer.
COMPUTER ARCHITECTURE AND OPERATING SYSTEMS For each reader process:
a) Is the solution correct? YES/NO
In each of the following, your answer should be either
i) HAS NO EFFECT
ii) IS NEEDED FOR A CORRECT SOLUTION
iii) MAKES FOR AN INCORRECT SOLUTION
Include a brief explanation. Note that each question is independent, that is, it assumes the original code above.
b) What is the effect of swapping lines 1 and 2?
c) What is the effect of swapping lines 3 and 4?
d) What is the effect of swapping lines 7 and 8?
PROGRAMMING LANGUAGES AND COMPILER DESIGN
TEXT -> ch TEXT | empty
a) List all tokens used in this language (ch is one; what are the others?)
b) Give a simple BNF grammar that generates syntactically correct PAGEs
b) Suppose that an Object Oriented language has a class STUDENT with
subclasses GRADSTUDENT and POSTBACSTUDENT. Also, suppose that each of the three
classes above has its own "print()" method.
Give simple examples of instances in which the correct "print()" method
to call
(i) can
(ii) can not
be determined at the time of compilation of the program. Explain.
a) Propose an efficient storage scheme for a compiler for this language to store the n(n+1)/2 nonzero entries.
b) For your scheme, show the computation necessary (access function) to access element a[i,j].
a) Which segment is valid? What are the values of x and y after the valid code segment executes? Explain.
b) Which segment is not valid? Explain. (If your answer is language or compiler dependent, explain also.)
(ii) element assignments
prime = true;
for (i=2; i <= sqrt(n); i++)
if ( n%i == 0) {
prime = false;
break;
}
if (prime) print(n, " is prime");
while (1) {
1. wait(sem_readcount);
2. readcount++;
3. signal(sem_readcount);
4. if (readcount==1) wait(sem_wrt);
/* reader reads from the file */
5. wait(sem_readcount);
6. readcount--;
7. signal(sem_readcount);
8. if (readcount==0) signal(sem_wrt);
}
while (1) {
9. wait(sem_wrt);
/* writer writes to file */
10. signal(sem_wrt);
}
<HTML> <TITLE>
Some text goes here.
</TITLE> <BODY>
<P>
This is a possibly multi-line "Paragraph"
Below is an "Unordered List".
</P>
<UL>
<LI> Text for first List Item.
<LI> Text for second List Item, etc.
</UL>
</BODY> </HTML>
...
TEXT -> ch TEXT | empty
real UpperTriangular a[n]; // a is an n by n matrix of real numbers
// all entries below main diagonal are zero
// diagonal has n entries a[0,0], a[1,1], ..., a[n-1,n-1]
real UpperTriangular b[3];
(i) (ii)
int x, y; int x, y;
y = 8; y = 8;
x = - --y; x = -- -y;