I am too Lazy to update about me.

Not updated.

### Experience:

Not updated.
Tud
Example text
1 year 1 month ago
moreless
Tud
1 year 1 month ago

@divyakaturia05,

because, when the recursion stops, the control is retuned back to the parent functions :

See,

phase-1:

abc() -->  abc() --> abc () [here recursion stops]

so now when the last abc() prints "8 8", it returns control back to 2nd abc() which was called during recusion. Now, this abc() will execute the last printf() hence, prints "7 8" ( remember s is static) and returns the control back to 1st abc() and lasttly the 1st abc()  executes last printf() and prints "6 8 "

hence, the output:

6 6

7 7

8 8

8 8

7 8

6 8

If still unsure, I will suggest to revise how recursion calls works then look at this again you will find it easy.If you get any doubt in recursion calls also you can ask here!

This might help:

https://www.hackerearth.com/practice/notes/working-of-recursive-function/

moreless
Tud
1 year 1 month ago

What do we mean by checking for progress  ?

Let P1, P2, P3 .....Pn be processes sharing critical section. The progress requirement will state that the decision about the processes which want to enter the critical section must take into account only the process that want to enter the critical section and not those that do not what to enter the critical section.

What does this all means ?

Lets consider an example:

consider two processes , P1 & P2 sharing critical section and the critical section problem is resolved as follows:

P1

   Non-CS
while(turn !=0);
CS
turn = 1
Non-CS

P2

    Non-Cs
while(turn != 1);
CS
turn = 0
Non-CS

Lets , say initially turn = 0 and process P1 wants to enter the critical section (CS) means it has executed codes residing in Non-CS area

Now, process P1 will enter CS ( since while loop condition is false)

Now after execting CS, P1 sets turn = 1

Lets assume, P2 is still not finished will execution of its Non-CS section or it could still be in ready ques and not scheduled to the CPU.

Meanwhile, suppose Pagain gets scheduled to the CPU and again it want to enter the CS but it can not as turn =1 thus while loop for P1 will keep running.

So, here although P2 does not wants to enter the CS it is taken into consideration while designing the solution.

Therefore, progress condition is not met here.

Although, Mutual Execution condition is met here.(chek this for yourself).

Final Point: Yes, it can get hard to identify all the condition which are met or not when you are just beginning. It'll get easier if you practice more question (only practice quality question, start with previous GATE questions).

Pick a question, and dive deep into it. If stuck post it here. Will try to help!

moreless
Tud
1 year 1 month ago

Storage Class

A storage class define scope as well as lifetime of a variable.

Storage classes in C are:

1. Automactic
2. Static
3. External
4. Register

Here, only auto and static are used so lets focus on that:

(I)

What do we mean by writing auto int a; ?

That the variable will be destroyed when the function exits (i.e) completes execution.

By "destroyed" it mean that the memory space allocated to the variable will be freed, hence any value stored in that variable will be lost.

(II)

What do we mean when we write static int s ; ?

That the variable will not be destroyed till the end of program (NOTE: its till the end of program ). Therefore, the value that is stored in such variable persists (i.e stored in the memory) and when the function is again called the value is preserved.So, any expression using such statis variable will access the preserved value.

Now,

Lets look at the program. (Keep in mind that variable a is auto and variable s is static)

Phase-1: when 1st abc() is called

• abc() is called inside main()
• s=5
• after , a= ++s, a=6, s=6

output:

6 6

• since, a <= 7 is True , abc() is again called
• Now, s = 6,
• due to a=++s, a=7 , s= 7

output:

6 6

7 7

• again a <= 7 is True
• after this iteration, a=8, s=8

output:

6 6

7 7

8 8

• now, a <=7 is False
• threfore the recursion stops

output:

6 6

7 7

8 8

8 8

7 8

6 8

Phase-2: when 2nd abc() is called.

• abc() is called inside main()
• s=8 (remember that it is static)
• a = 9, s = 9 (due to a=++s)

output:

6 6

7 7

8 8

8 8

7 8

6 8

9 9

• now, a <=7 is False
• therfore, printf() is executed once more

output:

6 6
7 7
8 8
8 8
7 8
6 8
9 9
9 9

Hope this helps!

Keep in mind the concept of storage classes and recursion and you can understand this. If you find anything unclear about my explanation. Do not hesitate to ask! Keep Learning!

moreless
Tud
Example text
1 year 1 month ago

@shiwaay Wheather you ans is right or wrong, explaining how you arrived at the ans, will help you as well as other reading you ans!

Keep Learning!

moreless
KIRAN KUMAR
Sumit Verma
Ranita Biswas
Pritam Prasun
Pritam Prasun
905
Sumit Verma
10677
nandini
23797
Kuldip Gusani
36314
11 Jun 2017 - 10:42pm

@divyakaturia05,

because, when the recursion stops, the control is retuned back to the parent functions :

See,

phase-1:

abc() -->  abc() --> abc () [here recursion stops]

so now when the last abc() prints "8 8", it returns control back to 2nd abc() which was called during recusion. Now, this abc() will execute the last printf() hence, prints "7 8" ( remember s is static) and returns the control back to 1st abc() and lasttly the 1st abc()  executes last printf() and prints "6 8 "

hence, the output:

6 6

7 7

8 8

8 8

7 8

6 8

If still unsure, I will suggest to revise how recursion calls works then look at this again you will find it easy.If you get any doubt in recursion calls also you can ask here!

This might help:

https://www.hackerearth.com/practice/notes/working-of-recursive-function/

more less
11 Jun 2017 - 10:28pm

What do we mean by checking for progress  ?

Let P1, P2, P3 .....Pn be processes sharing critical section. The progress requirement will state that the decision about the processes which want to enter the critical section must take into account only the process that want to enter the critical section and not those that do not what to enter the critical section.

What does this all means ?

Lets consider an example:

consider two processes , P1 & P2 sharing critical section and the critical section problem is resolved as follows:

P1

   Non-CS
while(turn !=0);
CS
turn = 1
Non-CS

P2

    Non-Cs
while(turn != 1);
CS
turn = 0
Non-CS

Lets , say initially turn = 0 and process P1 wants to enter the critical section (CS) means it has executed codes residing in Non-CS area

Now, process P1 will enter CS ( since while loop condition is false)

Now after execting CS, P1 sets turn = 1

Lets assume, P2 is still not finished will execution of its Non-CS section or it could still be in ready ques and not scheduled to the CPU.

Meanwhile, suppose Pagain gets scheduled to the CPU and again it want to enter the CS but it can not as turn =1 thus while loop for P1 will keep running.

So, here although P2 does not wants to enter the CS it is taken into consideration while designing the solution.

Therefore, progress condition is not met here.

Although, Mutual Execution condition is met here.(chek this for yourself).

Final Point: Yes, it can get hard to identify all the condition which are met or not when you are just beginning. It'll get easier if you practice more question (only practice quality question, start with previous GATE questions).

Pick a question, and dive deep into it. If stuck post it here. Will try to help!

more less
11 Jun 2017 - 10:02pm

Storage Class

A storage class define scope as well as lifetime of a variable.

Storage classes in C are:

1. Automactic
2. Static
3. External
4. Register

Here, only auto and static are used so lets focus on that:

(I)

What do we mean by writing auto int a; ?

That the variable will be destroyed when the function exits (i.e) completes execution.

By "destroyed" it mean that the memory space allocated to the variable will be freed, hence any value stored in that variable will be lost.

(II)

What do we mean when we write static int s ; ?

That the variable will not be destroyed till the end of program (NOTE: its till the end of program ). Therefore, the value that is stored in such variable persists (i.e stored in the memory) and when the function is again called the value is preserved.So, any expression using such statis variable will access the preserved value.

Now,

Lets look at the program. (Keep in mind that variable a is auto and variable s is static)

Phase-1: when 1st abc() is called

• abc() is called inside main()
• s=5
• after , a= ++s, a=6, s=6

output:

6 6

• since, a <= 7 is True , abc() is again called
• Now, s = 6,
• due to a=++s, a=7 , s= 7

output:

6 6

7 7

• again a <= 7 is True
• after this iteration, a=8, s=8

output:

6 6

7 7

8 8

• now, a <=7 is False
• threfore the recursion stops

output:

6 6

7 7

8 8

8 8

7 8

6 8

Phase-2: when 2nd abc() is called.

• abc() is called inside main()
• s=8 (remember that it is static)
• a = 9, s = 9 (due to a=++s)

output:

6 6

7 7

8 8

8 8

7 8

6 8

9 9

• now, a <=7 is False
• therfore, printf() is executed once more

output:

6 6
7 7
8 8
8 8
7 8
6 8
9 9
9 9

Hope this helps!

Keep in mind the concept of storage classes and recursion and you can understand this. If you find anything unclear about my explanation. Do not hesitate to ask! Keep Learning!

more less
11 Jun 2017 - 9:54am

See,

Even if only one process remains whose requirements can not be fullfilled, What does this implies ? That it'll wait for other process to release resources, which is not a safe state (meaning that there is possibility of deadlock).

It is not always the case that deadlock will take place, cause the processes holding resources might complete their execution  early, now the resouce could be given to the process having unment resource requirement.

But, while applying Banker's Algorithms we do not have any information about executtion time of various processes, therefore we can only say that a deadlock might take place.

Hope this helps!

If you still have any confusion, You can always ask ! Keep Learning!

more less
17 Apr 2017 - 5:50pm
@shweta, the the final answer is compiler dependent.

Look, here:
for the variable "n".There are two things:
1) Use "n" as the index of the array a.(After doing ++n)
2) Increment the the value of "n" by 1.(by doing n++)

Now, the confusion is :
whether to use the value of "n" before it is modified (incremented by doing n++) as the index, or after it . Different compilers will try to solve this confusion, by doing something like:
a) doing ++n on the value of "n" first (to be used as the index)
b) doing n++ first, and then ++n to calculate the index

This is undefined behaviour, and will depend on how a particular compiler handles such situation.
for more examples on undefined behaviour,
refer: https://en.wikipedia.org/wiki/Undefined_behavior [see the example section].

more less
17 Apr 2017 - 5:26pm

See, for any transaction T:

There could be any number of W(X) statements => Signifying that the value of data item "X" is written.

But when you write COMMIT at the end of transaction => it tells that all the changes made by that particular transaction is made permanent and visibile to all the other users (that may or may not be accessing the the data items modified by transaction T1)

Now, according to you the transaction should be considered to be COMMITTED, when a transaction does , W(X).

But, Consider that the transaction T1, modifies two data items, "X" and "Y",

now,

 T1 T2 R(X) R(Y) X = X - 100; Y = Y + 100; W(X) W(Y) COMMIT

Now, Ask yourself this question Is this a good idea to consider that the transaction is complete, beacause it has performed W(X) or W(Y) ?

Ans. is No

W(X) => writes  the value of X

And COMMIT => tells you that the transaction is complete.

Now,