Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  The following two functions P1 and P2 that sh... Start Learning for Free
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.
P1()
{
     C = B – 1;
     B = 2*C;
}
P2()
{
    D = 2 * B;
    B = D - 1;
}
The number of distinct values that B can possibly take after the execution is
  • a)
    3
  • b)
    2
  • c)
    5
  • d)
    4
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
The following two functions P1 and P2 that share a variable B with an ...
There are following ways that concurrent processes can follow.
There are 3 different possible values of B: 2, 3 and 4.
View all questions of this test
Most Upvoted Answer
The following two functions P1 and P2 that share a variable B with an ...
Explanation:

To determine the number of distinct values that B can take after the execution of the given functions, we need to analyze how the value of B changes in each function and how the two functions interact with each other.

P1 Function:
- C is assigned the value of B - 1 (i.e., C = B -1)
- B is assigned the value of 2 * C (i.e., B = 2*C)

P2 Function:
- D is assigned the value of 2 * B (i.e., D = 2 * B)
- B is assigned the value of D - 1 (i.e., B = D - 1)

Now let's consider the possible values of B after the execution of each function.

Possible values of B after P1:
- If B = 2, then C = 1 and B = 2 * 1 = 2
- If B > 2, then C = B - 1 > 1 and B = 2 * C > 4
- If B < 2,="" then="" c="B" -="" 1="" />< 1="" and="" b="2" *="" c="" />< />

Therefore, after the execution of P1, B can have two possible values: 2 or any value greater than 4.

Possible values of B after P2 (assuming B is initially 2):
- D = 2 * B = 4
- B = D - 1 = 3

Therefore, after the execution of P2, B can have only one possible value: 3.

Possible values of B after both P1 and P2:
- If B = 2, then after P1, B = 2 and after P2, B = 3
- If B > 2, then after P1, B can have any value greater than 4 and after P2, B can have only one possible value, i.e., 3

Therefore, the total number of distinct values that B can possibly take after the execution of both P1 and P2 is 3: 2, 3, and any value greater than 4. Hence, option A is the correct answer.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer?
Question Description
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer?.
Solutions for The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer?, a detailed solution for The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.P1(){ C = B – 1; B = 2*C;}P2(){ D = 2 * B; B = D - 1;}The number of distinct values that B can possibly take after the execution isa)3b)2c)5d)4Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev