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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!