Skip to content
Related Articles

Related Articles

Puzzle | Data Recovery Problem
  • Difficulty Level : Hard
  • Last Updated : 20 Aug, 2018
GeeksforGeeks - Summer Carnival Banner

Suppose you have three pen drives P1, P2 and P3 each having 1GB capacity. You have also 3GB data. You have to divide these data into P1, P2 and P3 such that if any one of the pen drive among P1, P2, P3 got crashed than you should be able to recover all the data from remaining two pen drives.

For example – if P1 is crashed then you should be able to recover 3GB data from P2 and P3.
Similarly in the case of P2 and P3.

Answer :

Suppose the 3GB data is divided into three groups A, B and C. Then the distribution would be like this
P1-> A^B
P2-> B^C
P3-> C^A

Now suppose pen drive P3 is lost and we are left with data of P1 and P2. As we know that
P1 contains data which is xor of A and B.
P2 contains data which is xor of B and C.

We can perform below steps to recover the whole data.

Step 1 : XOR of P1 and P2 gives (A^B)^(B^C) = B
Step 2 : XOR of this B which is obtained from step 1 with P1 gives (A^B)^B = A
Step 3 : XOR of this B which is obtained form step 1 with P2 gives (B^C)^C = C.

Performing the above-mentioned steps will give the data A, B, and C.

Similarly, we can perform these steps in the case of P1 and P2.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :