Question: This assignment has to do with converting between sets, bit strings, and shortest latticepaths as we have been studying in class. Sets are represented by

This assignment has to do with converting between sets, bit strings, and shortest latticepaths as we have been studying in class. Sets are represented by lists and are subsets of[1,2,3,..., n]. The n-bit strings will be lists of length n where each entry is a 0 or 1(e.g.[1,0,1,1,1,0] for a 6-bit string). Lattice paths of length n will be lists of length n whereeach entry is either the string right or the string up(e.g.[right,up,right,right,up]).You will write three functions, one from each of the following groups.1. Sets & Bit Strings(a) Create a function setToBit whose inputs are an integer n and a subset A [1,2,3,..., n](so n is the cardinality of the larger set that A is a subset of).The function will return an n-bit string that corresponds to the subset A. Forinstance, if n =8 and A =[2,3,5,7], then your function will return the 8-bitstring [0,1,1,0,1,0,1,0](note that the 1s are in positions 2,3,5, and 7, whichcorrespond to the elements of A).(b) Create a function bitToSet whose input is a bit string B. The function willreturn a subset (i.e. list) that corresponds to the bit string B. For instance, ifB =[1,1,0,0,1,0,0,1], then your function will return the subset [1,2,5,8].2. Sets & Lattice Paths(a) Create a function setToLattice whose inputs are an integer n and a subsetA [1,2,3,..., n](so n is the cardinality of the larger set that A is a subsetof). The function will return a lattice path of length n that corresponds to thesubset A. For instance, if n =8 and A =[2,3,5,7], then your function will returnthe 8-bit string [right,up,up,right,up,right,up,right](note that the upentries are in positions 2,3,5, and 7, which correspond to the elements of A).(b) Create a function latticeToSet whose input is a lattice path P . The function willreturn a subset (i.e. list) that corresponds to the lattice path P . For instance, ifP =[up,up,right,right,up,right,right,up], then your function will returnthe subset [1,2,5,8].3. Bit Strings & Lattice Paths(a) Create a function bitToLattice whose input is a bit string B. The functionwill return a lattice path that corresponds to the bit string B. For instance, ifB =[1,0,1,0,0,1,0,1,1], then your function will return the list[up,right,up,right,right,up,right,up,up].
(b) Create a function latticeToBit whose input is a lattice path P . The functionwill return a bit string that corresponds to the lattice path P . For instance, ifP =[up,up,right,right,up,right,right,up], then your function will returnthe bit string [1,1,0,0,1,0,0,1].Make sure your functions are well documented. You should have one-line comments (usingthe single line comments with #) written in complete sentences that describe what each lineof code does.

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!