0
0
DSA Pythonprogramming~5 mins

Two Non Repeating Elements in Array Using XOR in DSA Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does XOR operation do when applied between two same bits?
XOR of two same bits is 0. For example, 1 XOR 1 = 0 and 0 XOR 0 = 0.
Click to reveal answer
intermediate
Why XOR of all elements in an array with exactly two non-repeating elements results in XOR of those two unique elements?
Because XOR of two same numbers is 0, all repeating elements cancel out, leaving XOR of only the two unique elements.
Click to reveal answer
intermediate
How do you find a set bit in XOR of two unique numbers to separate them?
Find the rightmost set bit (bit with value 1) in the XOR result using expression: xor & (-xor). This bit differs between the two unique numbers.
Click to reveal answer
intermediate
Explain the step to separate array elements into two groups using the set bit.
Divide elements into two groups: those with the set bit and those without. XOR each group separately to find the two unique numbers.
Click to reveal answer
beginner
What is the time complexity of finding two non-repeating elements using XOR?
The time complexity is O(n) because we traverse the array a constant number of times.
Click to reveal answer
What is the XOR of a number with itself?
A0
BThe number itself
C1
DUndefined
If XOR of all elements in an array is 6, what does this represent when exactly two elements are unique?
ASum of two unique elements
BProduct of two unique elements
CXOR of two unique elements
DDifference of two unique elements
How do you find the rightmost set bit in a number x?
Ax & (-x)
Bx | (-x)
Cx & (x - 1)
Dx ^ (-x)
After finding the rightmost set bit, how are elements grouped?
ABy even and odd values
BRandomly
CBy greater or smaller than XOR value
DBy presence or absence of the set bit
What is the main advantage of using XOR to find two unique elements?
AUses extra memory
BRuns in O(n) time without extra space
CRuns in O(n^2) time
DRequires sorting
Describe the step-by-step process to find two non-repeating elements in an array using XOR.
Think about how XOR cancels duplicates and how to separate elements by a differing bit.
You got /4 concepts.
    Explain why XOR operation helps in identifying unique elements in an array where all others repeat twice.
    Focus on how XOR behaves with pairs and unique values.
    You got /4 concepts.