Notice: Included file qa-util-string.php is deprecated in /var/www/html/qadb/qa-include/qa-util-string.php on line 12

Deprecated: Implicit conversion from float-string "1568463366.921" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1568463366.921" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1568463366.921" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1568463366.921" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1568463366.921" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1578275893.168" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1578275893.168" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1578275893.168" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1578275893.168" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1578275893.168" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1541846074.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1541846074.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1541846074.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1541846074.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1541846074.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594
Operating System: CMI2012-A-10
edited by
1,322 views
16 votes
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$
edited by

2 Answers

Best answer
11 votes
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 votes
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:

Related questions

3.0k
views
2 answers
14 votes
go_editor asked May 22, 2016
2,972 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...
1.4k
views
1 answers
3 votes
go_editor asked May 22, 2016
1,369 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...
2.0k
views
5 answers
8 votes
go_editor asked May 22, 2016
2,033 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}$
2.1k
views
2 answers
7 votes
go_editor asked May 22, 2016
2,134 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...
Total PHP MySQL Other RAM
Time (ms) % Time (ms) % File count Time (ms) % Query count Time (ms) % Amount %
Setup 8.3 8% 6.8 7% 211 1.7 1% 2 0.0 0% 1035k 24%
Control 15.7 16% 2.4 2% 5 13.7 14% 12 0.0 0% 280k 6%
View 2.2 2% 2.2 2% 18 0.0 0% 0 0.0 0% 49k 1%
Theme 61.4 66% 18.6 20% 27 43.6 46% 21 0.0 0% 2818k 67%
Stats 5.3 5% 0.1 0% 0 5.3 5% 1 0.0 0% 0k 0%
Total 92.9 100% 30.2 32% 261 64.2 69% 36 0.0 0% 4185k 100%