Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can somebody explain the following xor property

I a forum it is mentioned that given array of n numbers:

arr[0........n-1]

The following conditon holds, ^ is the xor operator `

f(l,r) = f(0,r) ^ f(0,l-1)

where f(l,r) = arr[l]^arr[l+1]^........arr[r]

I checked the above taking number of arrays and different values of l and r and YES, it is true. But I don't understand how?

Can somebody please explain the logic behind this?

like image 576
J J Avatar asked Aug 08 '16 15:08

J J


People also ask

What is XOR property?

Important properties of XOR This is clear from the definition of XOR: it doesn't matter which way round you order the two inputs. Associative : A ⊕ ( B ⊕ C ) = ( A ⊕ B ) ⊕ C. This means that XOR operations can be chained together and the order doesn't matter.

How does XOR function work?

The XOR logical operation, exclusive or, takes two boolean operands and returns true if, and only if, the operands are different. Conversely, it returns false if the two operands have the same value.

What is XOR in math?

A connective in logic known as the "exclusive or," or exclusive disjunction. It yields true if exactly one (but not both) of two conditions is true. The XOR operation does not have a standard symbol, but is sometimes denoted (this work) or.


1 Answers

Use the simplest property of XOR

f(0,r) ^ f(0,l-1) = f(l,r)
=> (f(0,r) ^ f(0,l-1)) ^ f(0,l-1) =  f(0,l-1) ^ f(l,r)
=> f(0,r) = f(l,r) ^ f(0,l-1) [Since XOR is associative f(0,l-1) ^ f(0,l-1) = 0 and x ^ 0 = x]  
=> f(0,r) = (arr[0]^...arr[l-1])^(arr[l]^...^arr[r])

which is definition of f(0,r).

like image 164
Shashwat Kumar Avatar answered Sep 28 '22 01:09

Shashwat Kumar