Generate all binary strings from given pattern | Recursive function to generate all binary strings formed by replacing each wildcard character by 0 or 1 ; replace ' ? ' by '0' and recurse ; replace ' ? ' by '1' and recurse ; NOTE : Need to backtrack as string is passed by reference to the function ; Driver Code
function print ( str , index ) { if ( index === str . length ) { document . write ( str . join ( " " ) + " " ) ; return ; } if ( str [ index ] === " " ) { str [ index ] = " " ; print ( str , index + 1 ) ; str [ index ] = " " ; print ( str , index + 1 ) ; str [ index ] = " " ; } else print ( str , index + 1 ) ; } var input = " " ; var str = input . split ( " " ) ; print ( str , 0 ) ;