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
def calculatePower ( b , e ) : NEW_LINE INDENT ans = 1 ; NEW_LINE while ( e > 0 ) : NEW_LINE INDENT if ( e % 2 == 1 ) : NEW_LINE INDENT ans = ans * b ; NEW_LINE DEDENT e = e // 2 ; NEW_LINE b = b * b ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT def CountSubSet ( arr , n , X ) : NEW_LINE INDENT count = 0 ; checkX = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] == X ) : NEW_LINE INDENT checkX = 1 ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( checkX == 1 ) : NEW_LINE INDENT count = calculatePower ( 2 , n - 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 4 , 5 , 6 , 7 ] ; NEW_LINE X = 5 ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( CountSubSet ( arr , n , X ) ) ; NEW_LINE DEDENT