Question

(a) Generate all sequences of n digits 0, 1 and 2 that do not contain a...

(a) Generate all sequences of n digits 0, 1 and 2 that do not contain a substring of type XX. (E.g., the sequence 210102 is prohibited because it contains 1010.)

(b) Repeat the previous problem for binary strings of length n that do not contain a substring of type XXX.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a. Pseudo code to generate sequences of n digits 0, 1 and 2 that do not contain a substring of type XX is given below, here it first generate random number of n length by randno() function, then the generated sequence check to meet the condition.

Numseq : 12001

Output: 121

The "12001" is reduced to "121".

Main program :

Function Seqnum(n)

{

Input: n as the length of string

Output: sequence of string

Numseq =randno(n);

for i=1 to i<n

{

if (Numseq[i-1]!= Numseq[i])

(Numseq[k++]= Numseq[i-1])

else

While (Numseq[i-1]== Numseq[i])

I++;

}

Numseq[k++]= Numseq[i-1];

Numseq[k]=’\0’;

If(k!=n)

Seqnum(Numseq ,k)

}

Function randno(n){

For i=1 to i<=n

{

return Numseq[i]= rand()%2 // for digit 0, 1 and 2

}

}

b. The code for the binay string of 0 and 1 character.

Function Seqnum(n)

{

Input: n as the length of string

Output: sequence of string

Numseq =randno(n);

for i=1 to i<n

{

if (Numseq[i-1]!= Numseq[i])

(Numseq[k++]= Numseq[i-1])

else

While (Numseq[i-1]== Numseq[i])

I++;

}

Numseq[k++]= Numseq[i-1];

Numseq[k]=’\0’;

If(k!=n)

Seqnum(Numseq ,k)

}

Function randno(n){

For i=1 to i<=n

{

return Numseq[i]= rand()%1 // for binary 0 and 1

}

}

Add a comment
Know the answer?
Add Answer to:
(a) Generate all sequences of n digits 0, 1 and 2 that do not contain a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT