what will be regular express of this transition graph anyone?can make and explain this please i will be very thankful to him.
We can write some equations for this:
(q0) = e + (q1)a + (q3)b
(q1) = (q0)a + (q2)b
(q2) = (q1)b + (q3)a
(q3) = (q0)b + (q2)a
You can read these equations like this: "the set of strings that leads me to state X is the set of strings that lead me to state Y followed by symbol c, or the set of strings that lead me to state Z followed by symbol d, or..."
We can now solve these equations using substitution and a rule to eliminate self-references, namely:
if (q) = (q)x + y, then (q) = y(x*)
We can start solving the system by eliminating (q3):
(q0) = e + (q1)a + [(q0)b + (q2)a]b
(q1) = (q0)a + (q2)b
(q2) = (q1)b + [(q0)b + (q2)a]a
Distributing:
(q0) = e + (q1)a + (q0)bb + (q2)ab
(q1) = (q0)a + (q2)b
(q2) = (q1)b + (q0)ba + (q2)aa
We can get rid of (q1) now:
(q0) = e + [(q0)a + (q2)b]a + (q0)bb + (q2)ab
(q2) = [(q0)a + (q2)b]b + (q0)ba + (q2)aa
Distributing:
(q0) = e + (q0)aa + (q2)ba + (q0)bb + (q2)ab
(q2) = (q0)ab + (q2)bb + (q0)ba + (q2)aa
Grouping like terms:
(q0) = e + (q0)(aa + bb) + (q2)(ab + ba)
(q2) = (q0)(ab + ba) + (q2)(aa + bb)
Using the rule to remove self-reference:
(q0) = (aa + bb)* + (q2)(ab + ba)(aa + bb)*
(q2) = (q0)(ab + ba)(aa + bb)*
Substituting to get rid of (q2):
(q0) = (aa + bb)* + [(q0)(ab + ba)(aa + bb)*](ab + ba)(aa + bb)*
Distributing:
(q0) = (aa + bb)* + (q0)(ab + ba)(aa + bb)*(ab + ba)(aa + bb)*
Using the rule for self-reference:
(q0) = (aa + bb)*[(ab + ba)(aa + bb)*(ab + ba)(aa + bb)*]*
from the given transition diagram or DFA, equations for each state can be written as:
q0 = ε+q1.a+q3.b
q1 = q0.a+q2.b
q2 = q1.b+q3.a
q3 = q0.b+q2.a
substitute q3 in q2,
q2=q1.b+(q0.b+q2.a)a
q2=q2.aa+q0.ba+q1.b
substitute q1 in q2
q2=q2.aa+q0.ba+(q0.a+q2.b)b
q2=q2.aa+q0.ba+q0.ab+q2.bb
finally,
q2=q2(aa+bb)+q0(ba+ab)
It is in the form of t=tr+s
According to Arden's theorem,
the solution is t=sr*
So,q2=q0(ba+ab)(aa+bb)
Now substitute q3 in the equation q0,
q0=ε+q1.a+(q0.b+q2.a)b
q0=ε+q1.a+q0.bb+q2.ab
q0=q0.bb+(q1.a+q2.ab+ε)
substitute q1 in q0,
q0=q0.bb+(q0.a+q2.b)a+q2.ab+ε
q0=q0.bb+q0.aa+q2.ba+q2.ab+ε
q0=q0(bb+aa)+q2(ba+ab)+ε
Now substitute the q2 in the above equation,
q0=q0(bb+aa)+q0(ba+ab)(aa+bb)*(ba+ab)+ε
q0=q0((bb+aa)+(ba+ab)(aa+bb)*(ba+ab))+ε
Now q0 is in the form of t=tr+s so the solution is t=sr*
q0=((bb+aa)+(ba+ab)(aa+bb)(ab+ba))
The Regular Expression for the given DFA is:
q0=((bb+aa)+(ba+ab)(aa+bb)*(ab+ba))
enter image description here
Thank you
n = 1 : 1
n = 2 : 1
n = 3 : Fib(n-1) + Fib(n-2) + Fib(n-3) = Fib(2) + Fib(1) + Fib(0) = 1 + 1 + 0 = 2
n = 4 : Fib(n-1) + Fib(n-2) + Fib(n-3) = Fib(3) + Fib(2) + Fib(1) = 2 + 1 + 1 = 4
Basically, you add the 3 previous number before n.
T(n) = T(n-1)+n^c
T(n) = T(n-1)+c^n
where c is a constant
If you unroll the recursion, for the first case you will get:
1^c + 2^c + ... + (n-1)^c + n^c
which is a Faulhaber's formula. It tells you that the complexity is O(n^(c+1))
The second one is:
c^1 + c^2 + ... + c^(n-1) + c^n
which is the sum of geometrics and O(c^n)
Here's the question:
Solve the recurrence by obtaining a theta bound for T(n) given that T(1) = theta(1).
T(n) = n + T(n-3)
Attempted Solution:
T(n) = T(n-6) + (n-3) + n
= T(n-9) + (n-6) + (n-3) + n
= T(n-(n-1)) + [(n-n) + (n-(n-3)) + (n-(n-6)) + ... + n]
= T(1) + [0 + 3 + 6 + ... + n]
= theta(1) = 3[1 + 2 + 3 + ... + n/3]
= theta(1) + [(n/3)(n/3 + 1)]/2
= theta(1) + (n^2+3n)/6
When I double check to see if the solution fits the recurrence, it doesn't work.
The issue was that you were getting the wrong summation.
It doesn't start at 0, since your last T function was T(n - (n-1)) , which means previous one was T(n-(n-4)). So the summation starts at 4, and goes up till n.
If you don't know how to find the summation of this, I'd suggest you look at some of the proofs from the summation formula. This is what the solution looks like.
T(n) = T(n-3) + n
= T(n-6) + (n-3) + n
= T(n-(n-1)) + [ (n-(n-4)) + (n-(n-7)) + ... + n]
= T(1) + [4 + 7 + ... + n]
= theta(1) + (4 + n) * (n - 1)/6
I am trying to find the big O bound for the following recurrence relation:
T(n) = T(n-1) + n^c, where c >= 1 is a constant
So I've decided to solve this by using iteration:
T(n) = T(n-1) + n^c
T(n-1) = T(n-2) + (n-1)^c
T(n) = T(n-2) + n^c + (n-1)^c
T(n-2) = T(n-3) + (n-2)^c
T(n) = T(n-3) + n^c + (n-1)^c + (n-2)^c
T(n) = T(n-k) + n^c + (n-1)^c + .... + (n-k+1)^c
Suppose k = n-1, then:
T(n) = T(1) + n^c + (n-1)^c + (n-n+1+1)^c
T(n) = n^c + (n-1)^c + 2^c + 1
I'm not sure if this is correct however, plus I would really appreciate some guidance as to how to derive Big O from this. Thanks a lot!
Yes, you are correct:
T(n) = nc + (n-1)c + (n-2)c + … + 3c + 2c + 1,
and this sum is
T(n) = O(nc+1). See e.g. Faulhaber's formula. In fact, you can even determine the constant in the leading term (even if it's not germane to the algorithm's asymptotics): the sum is nc+1/(c+1) + O(c), as you can determine through e.g., using, say, integration.
What you have is not correct, but you were on the right track.
The mistake you made:
T(n) = T(n-3) + n^c + (n-1)^c + (n-2)^c
T(n) = T(n-k) + n^c + (n-1)^c + (n-k+1)^c
You cannot just go from the first line to the second line.
As you increase k, the number of terms in the right hand side increases too.
To see that think of writing it this way:
T(n) - T(n-1) = n^c.
T(n-1) - T(n-2) = (n-1)^c
..
T(n-k) - T(n-k-1) = (n-k)^c.
..
T(2) - T(1) = 2^c
What happens if you add these up?
Once you do that, can you see what the answer will be for c=1 and c=2? Can you figure out a pattern for the final answer from there?
Instead of working you way down from n, how about start by working your way up from 0 (I assume the recursion terminates at 0 and you left that bit out). When you start noticing a fixed point (ie a pattern which repeats the same in all cases) you have a good candidate for an answer. Try proving the answer, e.g. through induction.
I would start by observing that n^c, whilst of course influenced by the value of n, is not going to be any more complex for n vs. n + 1 - it's c that determines the "runtime" of that particular term. Given that, you can assume (at least I would) that the term has constant runtime and determine how many times the recursion will execute for a given n and you'll get your bound.
To figure these out, fill out a couple of terms and look for the pattern:
T(1) = 0 + 1^c
T(2) = T(1) + 2^c = 0 + 1^c + 2^c
T(3) = T(2) + 3^c = 0 + 1^c + 2^c + 3^c
T(4) = ...
Now express the pattern in terms of n and you have your answer.
Here it is:
T(n) = n^c + (n-1)^c + (n-2)^c + ... + 2^c + 1^c
< n^c + n^c + n^c + ... + n^c + n^c
= n * n^c
= n^(c+1)
which is O(nc+1).
To show this is a reasonable bound, note that when c = 1,
T(n) = n + (n-1) + (n-2) + ... + 2 + 1
= n * (n-1) / 2
which is clearly Θ(n2).