Question: PYTHON CODE Part A - Palindromic Bitlists Write a function palindrome binary(n) which returns a list of bitlists of length n, where every bitlist is

PYTHON CODE

Part A - Palindromic Bitlists

Write a function palindrome binary(n) which returns a list of bitlists of length n, where every bitlist is a palindrome. The returned list of bitlists must be in lexicographical order (think about the order of your options). You must use backtracking to solve this problem (i.e. do not use brute force).

Calling (palindrome_binary, 1) will return [[0],[1]]

Calling (palindrome_binary(3)) will return [[0,0,0],[0,1,0], [1,0,1], [1,1,1]]

Calling (palindrome_binary(5)) will return [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1]]

Calling (palindrome_binary(2)) will return [[0,0],[1,1]]

Calling (palindrome_binary(4)) will return [[0,0,0,0],[0,1,1,0], [1,0,0,1], [1,1,1,1]]

Do not use bin or zfill function.

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 Databases Questions!