DATA STRUCTURES, ANALYSIS OF ALGORITHMS AND COMPUTATIONAL COMPLEXITY
COMPUTER ARCHITECTURE AND OPERATING SYSTEMS
a) Briefly explain the First-Fit algorithm.
b) Briefly explain the Best-Fit algorithm.
Given a variable partition memory management scheme with the following free list:
| Free element | Size in KB
| 1 | 100
| 2 | 500
| 3 | 200
| 4 | 300
| 5 | 600
| |
c) Show how memory is allocated using the First-Fit algorithm by filling in this table:
| Request # | Size in KB | Request Satisfied (Y/N)? | Updated Free List
| 1 | 212 | Y/N | ( )
| 2 | 417 | Y/N | ( )
| 3 | 112 | Y/N | ( )
| 4 | 426 | Y/N | ( )
| |
PROGRAMMING LANGUAGES AND COMPILER DESIGN
a) dynamic scope and call by value-result
b) static scope and call by reference
c) static scope and call by value
Show your work in terms of activation records.
int a, b, c;
int g(int x, int y) {
c = 2;
x++;
y--;
a = x + c;
return (x-y);
}
void f(int x) {
int a = x+3;
b = g(a,c);
x = x + b;
}
void main() {
a = 3;
b = 5;
c = 7;
f(b);
print(a,b,c);
}
int i = 2;
int j = 3;
int a[4] = {3, 7, 2, 2};
int f(int &x, int &y) {
int *p;
int *q;
p = &j;
q = p;
a[i] = a[j--];
return (i + j + a[i] + a[j] + *p + *q + x + y);
}
int main() {
cout << f(i,i) << endl;
}
a) Describe the static storage-allocation strategy.
b) Describe the stack storage-allocation strategy.
c) Describe the heap storage-allocation strategy.
Be sure to compare the strategies and describe differences between the strategies (including lifetimes, visibility, efficiency, etc.).
struct y { struct id {
float x; or float id;
int i; int id;
}; };
a) Show the set of terminals belonging to FIRST(S), FIRST(L), FIRST(F), FIRST(T).
b) Compute FOLLOW of these non-terminals.
c) Using your results from a) and b), construct an LL(1) parsing table.
d) Using your result from c), begin the parse of the example above assuming that y, x, i are all replaced with the terminal id. Show the contents of the stack and how the input is consumed (show at least the first five steps).