GATE 2009
66 questions
MCQ 661-mark 24 · 2-mark 42
Questions 46–50 of 66
I There exist parsing algorithms for some programming languages whose complexities are less than .
II A programming language which allows recursion can be implemented with static storage allocation.
III No L-attributed definition can be evaluated in the framework of bottom-up parsing.
IV Code improving transformations can be performed at both source language and intermediate code level.
Answer: (B)
II is false. Static allocation fixes one memory location for each variable at compile time, so there is no place for a new copy of the local variables at every recursive call. Recursion needs stack (dynamic) allocation.
III is false. Every S-attributed definition is also L-attributed, and S-attributed definitions are evaluated easily during bottom-up parsing. So some L-attributed definitions can be evaluated bottom-up.
IV is true. Code-improving transformations can be done on the source (for example, constant folding or loop changes on the syntax tree) and on the intermediate code (for example, common subexpression removal).
So I and IV are true.
Answer: (B)
Answer: (B)
Correct Option: B
Lexical analysis uses regular expressions.
Pushdown automata go with context free grammar. This belongs to syntax analysis.
Code optimization is where dataflow analysis is done.
Code generation is where register allocation is done.
Now consider the following statements:
I. If a process makes a transition D, it would result in another process making transition A immediately.
II. A process P2 in blocked state can make transition E while another process P1 is in running state.
III. The OS uses preemptive scheduling.
IV. The OS uses non-preemptive scheduling.
Which of the above statements are TRUE?
Answer: (C)
- I is false. When a process makes D, it leaves the CPU. A ready process (there is always one) then makes transition B, not A. A is the arrival of a new process, which does not depend on D.
- II is true. A blocked process moves to Ready by E when its event completes. This can happen while another process is running.
- III is true. Transition C takes a running process back to Ready without it finishing or blocking, so the OS can preempt a process. That is preemptive scheduling.
- IV is false, since III is true.
So II and III are true.
Answer: (C)
void enter_CS(x)
{
while test-and-set(x) ;
}
void leave_CS(x)
{
x=0;
}
In the above solution, x is a memory location associated with the CS and is nitialized to 0.Now consider the following statements:
I. The above solution to CS problem is deadlock-free
II. The solution is starvation free.
III. The processes enter CS in FIFO order.
IV More than one process can enter CS at the same time.
Which of the above statements is TRUE?
Answer: (A)
- I is true. If no process is in the CS, x is 0, so some waiting process gets 0 and enters. A process inside leaves and sets x = 0. So the processes cannot all be stuck waiting: the solution is deadlock-free.
- II is false. Nothing decides which spinning process wins when x becomes 0, so one unlucky process may lose again and again (starvation).
- III is false. There is no queue, so the processes do not enter in the order they came.
- IV is false. Test-and-set is atomic, so only one process can see 0, and mutual exclusion holds.
So only I is true.
Answer: (A)
Which one of the following statements is TRUE if all three processes run concurrently starting at time t=0?
Answer: (A)
Resources: R1 = 3, R2 = 2, R3 = 3, R4 = 2. The table shows the free units after the events at each time.
At , process has to wait, because only is free but needs . So is blocked.
P1 was blocked from to , so all its later steps move 2 time units later. Its release of R2 and R1 (listed at ) happens at , its release of R3 (listed at ) at , and its request for (listed at ) at . P1 then finishes at instead of . P2 finishes at and P3 at .
Every request is met in the end, so all three processes finish and no process is in deadlock.
Answer: (A)