I have a positive integer array- {1,5,8,2,10} and a given value 7. I need to find whether a subset of the array exists such that the XOR of its elements is the value 7. In this case the subset is {5,2} because 5 xor 2 is 7. One naive solution is to find all the subsets and check whether a solution exist.I want some algorithm better than the naive. NOTE:-I just need to find whether a solution exists or not.I don't need to find the subset.
Efficient algorithm to find whether a subset of an integer array exists,the xor of all its elements is a given value?
3.6k Views Asked by user3522401 At
1
There are 1 best solutions below
Related Questions in ARRAYS
- Two different numbers in an array which their sum equals to a given value
- how to fill out the table with next values in array with one button
- How to sort a multi-dimensional array by the second array in descending order?
- Looping over defined array elements in Fortran
- Array appending after each onclick and loop in javascript
- PHP : How can I check Array in array?
- store numpy array in mysql
- Java Assign a Value to an array cell
- Saving FileSystemInfo Array to File
- Notice: Undefined offset: 1, but there is such offset
- How can I determine the index of the same set of characters between two strings that are of different lengths?
- Caused by: java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
- Pull out first occurrences from array
- How to read a file then store to array and then print?
- C++ won't read in scientific notation data from a .txt file
Related Questions in ALGORITHM
- Two different numbers in an array which their sum equals to a given value
- Given two arrays of positive numbers, re-arrange them to form a resulting array, resulting array contains the elements in the same given sequence
- Time complexity of the algorithm?
- Find a MST in O(V+E) Time in a Graph
- Why k and l for LSH used for approximate nearest neighbours?
- How to count the number of ways of choosing of k equal substrings from a List L(the list of All Substrings)
- Issues with reversing the linkedlist
- Finding first non-repeating number in integer array
- Finding average of an array
- How to check for duplicates with less time in a list over 9000 elements by python
- How to pick a number based on probability?
- Insertion Sort help in javascript -- Khan Academy
- Developing a Checkers (Draughts) engine, how to begin?
- Can Bellman-Ford algorithm be used to find shorthest path on a graph with only positive edges?
- What is the function for the KMP Failure Algorithm?
Related Questions in SUBSET-SUM
- Subset sum variant with a non-zero target sum
- Common Lisp: Using (let) for evaluating recursive function
- algorithm to get subset of array with target sum is not giving working
- Why does my Dynamic Programming Approach to the SSP always work?
- Optimizing Kadane's Algorithm for numpy
- Subset-Sum in Linear Time
- Subset sum for double data-type?
- Scheme Syntax Help: Using a function that I have defined in another program
- subset sum from recursive backtracking
- find all subsets that sum to x - using an initial code
- Subset sum recursively in Python
- correct me for using generators or tell me other way
- sql server : select rows who's sum matches a value
- Efficient algorithm to find whether a subset of an integer array exists,the xor of all its elements is a given value?
- NP-Complete Reduction for Subset Sum
Related Questions in BITWISE-XOR
- Solving bitwise XOR and ADD equation
- How to XOR numbers together then extract a number
- Calculating bitwise inversion of char
- Given XOR & SUM of two numbers. How to find the numbers?
- Efficient algorithm to find whether a subset of an integer array exists,the xor of all its elements is a given value?
- Cracking a Bitwise cipher
- Bitwise operations between an integer and an array of bits
- compiler warning "warning: iteration 10u invokes undefined behavior [-Waggressive-loop-optimizations]" for M[i] ^ k;
- We are missing some condition for n>2, can someone help to find special cases which our code is missing?
- Perform XOR operation on 2 "Long" variables and display the alphanumeric result in .NET Core Console Application
- Bitwise Operations in Angular Template Expressions
- Tensorflow cost function based on binary xor operation
- Double numbers and bitxor
- When bitwise and & operation is greater or equal to bitwise xor ^ operation?
- how to inverse my formula in bitwise xor to get the value of 53?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This boils down to solving a system of linear equations over the finite field with two elements (GF(2)). Bitwise XOR here is equivalent to adding two vectors. The sample inputs correspond to vectors like so.
The system looks like this.
The following Python code uses Gaussian elimination and is implemented using bitwise operations. For fixed-width integers, it runs in linear time. Forgive me for not reexplaining Gaussian elimination when there are a million better treatments on the Internet already.