2 ^ n complexity algorithm
source link: https://www.codesd.com/item/2-n-complexity-algorithm.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
2 ^ n complexity algorithm
I need to implement and test an algorithm with a 2^n complexity. I have been trying to find one for a while. If there is any way I can acheive this by implementation -- with a exact complexity of 2^n that would be optimal. If anyone knows of a location I can find an example, or could help me implement one, that would be awesome :-). The basic operation can be anything, but a single statment like i++; would be best.
Generate all subsets of a set with n elements.
Added. The simplest way of generating all the subsets of S = {a0, a1, ..., an-1} is probably to translate between the binary representation of the rank and the subset.
Take S = {a0, a1, a2}.
rank binary subset
0 000 {}
1 001 {a0}
2 010 {a1}
3 011 {a0, a1}
4 100 {a2}
5 101 {a0, a2}
6 110 {a1, a2}
7 111 {a0, a1, a2}
So, a 1 in the binary means the corresponding element is in the subset. A 0 means the element is not in the subset.
But you should also lookup Gray code.
Related Articles
Basis of logarithms in time-complexity algorithms
Where to run complex algorithms? Server or client side?
Are there any cases where you would prefer a big-O time complexity algorithm greater than the lower algorithm?
Removing non-constants in the Complexity Algorithm
Big O Complexity algorithm
that take as n in complexity algorithms
Example of too complex algorithm?
Non monotonic temporal complexity algorithm
Is it possible to make a complexity algorithm O ((n!)!)?
For your complex algorithms, how do you measure its performance?
Construct a time complexity algorithm O (n) to find a value in two arrays
How to calculate the command (big O) for more complex algorithms (eg quicksort)
Time Complexity of an algorithm: how to decide which algorithm after computed time
How can I determine the time complexity of an algorithm when apparently the constant affects complexity, when I have been taught differently?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK