kuspia / Famous-Algo

Collection of Famous Algorithims written in CPP
3 stars 3 forks source link

add all detail #40

Closed Ashwanigupta9125 closed 2 years ago

Ashwanigupta9125 commented 2 years ago

all the detail in your way and u find any mistake than please help me

kuspia commented 2 years ago

you have to write the code which is error-free hence you should remove

Enumerating submasks of a bitmask

Resources:
https://www.geeksforgeeks.org/print-all-submasks-of-a-given-mask/

Implementation:

as these are not recognized by a CPP compiler

Moreover, you have mentioned that

Time complexity = O(3^n) 

which is impossible in the worst case it will go to O(2^n) where n is total number of bits (set and unset both), can u explain mew how you got 3^n ??

// submask = (submask - 1) & mask
         //here we take submask -1 to make last occur of 1 to zero
         // and taking '&' operation with given number to mask to find
         // all variation

? wdym here when u do submask-1 it actually flips all the bits from the first set bit that occur at rightmost position nd when you do & it gives u next submask which is smaller than previous one

kindly understand it and do the changes properly.