• edited by
2,169 views
16 16 votes

Consider the following functions $f$ and $g$.
 

f(){
x = x-50; 
y = y+50;
}
g( ) {
a = a+x;   
a = a+y;
}

Suppose we start with initial values of $100$ for $x, 200$ for $y$, and $0$ for $a$, and then execute $f$ and $g$ in parallel - that is, at each step we either execute one statement from $f$ or one statement from $g$. Which of the following is not a possible final value of $a$?

  1. $300$
  2. $250$
  3. $350$
  4. $200$

2 Answers

Best answer
11 11 votes

Answer is (D) $200$

If we execute first $f()$ and then $g()$ then we get $300$

If we execute $1^{st}$ line of $g()$ , then $f()$ all the lines and then last line of $g()$ ,will get $350$

If we execute $1^{st}$ line of $f()$, then $1^{st}$ line of $g()$, then 2nd line of $g()$ and then $2^{nd}$ line of $f()$, we get $250$

• edited by
0 0 votes
as we are adding y to a's value and minimum value of 'a' at point a=a+x; can be 50....so the final value of 'a'  (at a=a+y;) has to be greater than 200 (max. value of 'a' can be 350)
Answer:
Position:
Show:

Related questions

14 14 votes
2 answers 2 answers
4.9k
4.9k views
go_editor asked May 22, 2016
4,871 views
Consider the following programming errors:Type mismatch in an expression.Array index out of bounds.Use of an uninitialized variable in an expression.Which of these errors...
4 4 votes
1 1 answer
2.4k
2.4k views
go_editor asked May 22, 2016
2,407 views
You are given two sorting algorithms A and B that work in time $O(n \log n)$ and $O(n^2)$, respectively. Consider the following statements:Algorithm $A$ will sort any arr...
8 8 votes
5 answers 5 answers
3.8k
3.8k views
go_editor asked May 22, 2016
3,809 views
A man has three cats. At least one is male. What is the probability that all three are male?$\frac{1}{2}$$\frac{1}{7}$$\frac{1}{8}$$\frac{3}{8}$
9 9 votes
2 answers 2 answers
2.8k
2.8k views
go_editor asked May 22, 2016
2,774 views
A basket of fruit is being arranged out of apples, bananas, and oranges. What is the smallest number of pieces of fruit that should be put in the basket in order to guara...