Page 1 of 1

Suppose we are given an integer N and would like to have all the binary numbers smaller than or equal to N. In order to

Posted: Fri May 20, 2022 3:17 pm
by answerhappygod
Suppose we are given an integer N and would like to have all the
binary numbers smaller than or equal to N. In order to have the
results generated, one can use a queue to help. Please give an
approach that uses a queue to generate the results, write your
approach with pseudo-code, and discuss the time as well as space
complexity for your approach. Please note that the output should
have the binary numbers in increasing order. Input: 10
Output: [’1’, ’10’, ’11’, ’100’, ’101’, ’110’, ’111’, ’1000’,
’1001’, ’1010’] Explanation: 10 binary numbers are generated
sequentially Input: 13 Output: [’1’, ’10’, ’11’, ’100’, ’101’,
’110’, ’111’, ’1000’, ’1001’, ’1010’, ’1011’, ’1100’, ’1101’]
Explanation: 13 binary numbers are generated sequentially