How can I solve this deadlock related problem mathematically?
As per the question, all the even processes request only even resources(i.e. Ri &amp; Ri+2)
Where as odd processes request:
either,
odd resources(i.e. Rn-1 &amp; Rn-1-2) when 'n' is even.
or,
even resources (i.e. Rn-1 &amp; Rn-1-2) when 'n' is odd.

Deadlock can only happen when even and odd processes request overlaps i.e. odd processes have to request even resources which means 'n' must should be odd.

Mathematically,

Let Pn-i be an odd process then,

n-i&lt;=k

or,ceil(n-i)=k   here ceil() is ceiling function since the value at max can be equal to k.

i=ceil(n-k)---eqn(i)

For deadlock to happen,

i=n-i-2

substituting value of i from eqn(i), we have,

ceil(n-k)=n-i-2

solving further we get,

k=ceil((n+2)/2)  where 'n' is odd

since, 'n' must should be odd option A and C can be ignored now coming to option B substituting n=21 we get k=12 
In option D substituting n=41 we get k=22.

so option B is correct.For option D to be in deadlock k should be equal to 22.