Question
Write the function lex less eq(a, b) that implements the lexicographic order between sequences a and b, i.e., returning True if and only if a
Write the function lex less eq(a, b) that implements the lexicographic order between sequences a and b, i.e., returning True if and only if a is lexicographically smaller than or equal to b. The functions behaviour is thus equivalent to the built in '<=' operator on sequences.
For example:
>>> lex_less_eq('tactic', 'tree')
True
>>> lex_less_eq('tactic', 'tactical display')
True
>>> lex_less_eq([1, 2, 3], [0, 1, 2, 3])
False
then, write the recursive function rbitlists(n) that generates a list of all bitlists of length n in lexicographic order. Explain the approach (base case and recursive case) and give an argument why this approach enumerates bitlists in lexicographic order.
For example:
>>> rbitlists(2)
[[0, 0], [0, 1], [1, 0], [1, 1]]
>>> rbitlists(3)
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]
False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started