(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.
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
}
}
(a) Generate all sequences of n digits 0, 1 and 2 that do not contain a...
Consider binary strings with n digits (for example, if n = 4 some of the possible strings are 0011, 1010, 1101, etc.) Let z be the number of binary strings of length n that do not contain the substring 000 Find a recurrence relation for z You are not required to find a closed form for this recurrence
Consider binary strings with n digits (for example, if n = 4 some of the possible strings are 0011, 1010, 1101, etc.)...
Let S be the set of all 7-digit numbers which do not contain 0 in any place — that is, each element of S is a string of 7 digits with each digit chosen from the set {1, 2, 3, 4, 5, 6, 7, 8, 9}. How many elements of S are there that don’t contain the substring 123? To qualify as having 123 as a substring, the numbers 1, 2 and 3 must appear in order and consecutively. For...
For each of the following, construct context-free grammars that generate the given set of strings. If your grammar has more than one variable, we will ask you to write a sentence describing what sets of strings you expect each variable in your grammar to generate. For example, if your grammar were: S → EO E → EE CC 0+ EC C+01 We would expect you to say “E generates (non-empty) even length binary strings; O generates odd length binary strings;...
A. Design a circuit using D flip-flops that will generate the
sequence 0, 0, 1, 0, 1, 1 and repeat. Do this by designing a
counter for any sequence of states such that the first flip-flop
takes on this sequence. There are many correct answers, but do not
duplicate states, because each state can have only one next
state.
B. A pulse-generating circuit generates eight repetitive pulses
as shown in the figure. Implement the pulse-generating circuit
using a binary counter...
Build PDA to generate all strings of the form 0 (n) 1 (2n+3) where n>=0 Build CFG to generate all strings of the form 0 (n) 1 (2n+3) where n>=0
2. A binary string is a finite sequence u-діаг . . . an, where each ai is either 0 or 1. In this case n is the length of the string v. The strings ai, aia2,... ,ai... an-1,ai... an are all prefixes of v. On the set X of all binary strings consider the relations Ri and R2 defined as follows: Ri-(w, v) w and v have the same length ) R2 = {(u, v) I w is a prefix...
Discrete mathematics
2) Let be eumber of ternary strings (of 0s, 1s and 2s) of length n that have no adjacent even digits. For example, so (the empty string), s3 (the strings 0, 1 and 2), while s2 5: 01, 0, 12, 2 because the strings 00,02, 20, 22 are not allowed, as they have adjacent even digits. As another example, the string 10112 is allowed, while the strings 10012 and 120121 are not allowed (a) Find #3; (b) find...
2. A binary string s a finite sequence u = ala2 . . . an, where each ai įs either 0 or 1. In this case n is the length of the string v. The strings ai,aia2,...,ai...an-1,aan are all prefixes of v. On the set X of all binary strings consider the relations Ri and R2 defined as follows R, = {(u, u) | w and u have the same length } {(w, u) | w is a prefix of...
2. A binary string is a finite sequence v = a1a2 . . . an, where each ai is either 0 or 1. In this case n is the length of the string v. The strings a1, a1a2, . . . , a1 . . . an−1, a1 . . . an are all prefixes of v. On the set X of all binary strings consider the relations R1 and R2 defined as follows: R1 = {(w, v) | w...
Problem 3. A ternary string is a sequence of O's, 1's and 2's. Just like a bit string, but with three symbols 0,1 and 2. Let's call a ternary string good provided it never contains a 2 followed immediately by a 0, i.e., does not contain the substring 20. Let Go be the number of good strings of length n. For example, G_1=3, and G. = 8 (since of the 9 ternary strings of length 2, only one is not...