Count of Subsets of a given Set with element X present in it | Function to calculate ( 2 ^ ( n - 1 ) ) ; Initially initialize answer to 1 ; If e is odd , multiply b with answer ; Function to count subsets in which X element is present ; Check if X is present in given subset or not ; If X is present in set then calculate 2 ^ ( n - 1 ) as count ; if X is not present in a given set ; Driver code
function calculatePower ( b , e ) { let ans = 1 ; while ( e > 0 ) { if ( e % 2 == 1 ) ans = ans * b ; e = e / 2 ; b = b * b ; } return ans ; } function CountSubSet ( arr , n , X ) { let count = 0 , checkX = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == X ) { checkX = 1 ; break ; } } if ( checkX == 1 ) count = calculatePower ( 2 , n - 1 ) ; else count = 0 ; return count ; } let arr = [ 4 , 5 , 6 , 7 ] ; let X = 5 ; let n = arr . length ; document . write ( CountSubSet ( arr , n , X ) ) ;