1
:2
version 5
04.11.06
DFA
KMP
DFA∑ },,,,{ 0 FqQ δ
Q
∑
δ
∑→× QQ:δ
0q
F
Q={“on”,”off”}
∑= }"_{" pressedkey
"")"_","("
"")"_","("
onpressedkeyoff
offpressedkeyon
=
=
δ
δ
""0 offq =
""offF =
DFA
2






∈∈=
∈=
=
∑∑
∑
+
awawqwaq
aaqaq
qq
,)),,(
~
(),(
~
),(),(
~
),(
~
δδδ
δδ
εδ
LDFA
}),(
~
|{ 0 FwqwL ∈= δ
"
},01|{ *
∑∈== yxyxwwL
•
3
00
321
}1,0{
},,{
qF
qq
qqqQ
=
=
=
=
∑
),( aqδ
0q2q0q
3q2q2q
3q3q3q
)(3 nSn3q
3
)(2 nSn2q
n-1
)(0 nSn0q
n-1
n
n=0
•
nkkS ,,2,1,0)(3 =∀)(2 kS)(0 kS
)1(3 +nS)1(2 +nS)1(0 +nS
•3qn+1
3q
3q
)(3 nS3q
),( aqδn2q)(2 nS
nn+12q3qn+1
),( aqδ
•2qn+1
n
•0qn+1
nn=0
L
∑=
=
}1,0{
}3|{ bydividablenumberbinaryiswwL
4
5
LDFA
LW
}|{
}|{
}|{
}|{
*
LwWandworWwandLwwWL
LwwL
WwandLwwWL
WworLwwWL
∉∈∉∈=⊕
∈=
∈∈=∩
∈∈=∪
∑
LWWL ∪
‫ו‬
¡
WL ∩
¢ ‫ג‬‫ש‬‫ת‬ ‫ו‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ‫ת‬ ‫ו‬ ‫פ‬
.
LL
‫ת‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ¢ ‫ג‬
.
LWWL ⊕
‫ת‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ‫ה‬ ‫פ‬ ‫ש‬
.
KMP
LALA
L
A
A
6
)(4 nSn4q
)(3 nSn3q
)(2 nSn2q
)(1 nSn1q
w
w|w|+1
KMP
wy
wywy
w
ywy
O((|y|-|w|)|w|)
KMP
•:preprocessing
w
O(|w|)
7
•y
O(|y|)
•O(|w|+|y|)
•
KMP
CLRS
KMP
NFA
NFADFA
DFANFA
NFA
- NFA
DFA
NFA
NFANFA∑ },,,,{ 0 FqQ δ
Q
∑
0q
F
δ
∑ →× )(: QPQ εδ U
.
8
∑ →× )(: QPQ εδ U
0q1q,0q0q
2qΘ1q
ΘΘ2q
NFA
NFA
NFA
),,,...,,,( 12110 +kkk qrqrqrqi
iq1+iqir
wkrrw ...1=
LNFA
}|{ FinendwhichwforpathlegalexistwL =
DFA-NFA
NFA
}'1'0|{ stwoexactlyorsofnumberevenancontainswwL =
9
NFA
}110|{ substringthecontainnotdoeswwL =
NFA
}010000|{ substringasoreithercontainswwL =
DFANFADFA
NFA"" DFANFA ⊆
DFANFA
DFANFA
DFANFA
10
LNFA
NFADFADFA
DFANFA
L
DFADFA
LWWL ∪
‫ת‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ‫ה‬ ‫פ‬ ‫ש‬
.
NFA
LL
‫ת‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ¢ ‫ג‬
.
LWWL ⊕
‫ת‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ‫ה‬ ‫פ‬ ‫ש‬
.
}|{
......if 121121
LwwL
aaaawthenaaaaw
RR
kk
R
kk
∈=
== −−
LR
L
‫ת‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ¢ ‫ג‬
.
}|{* WlandLwlwWL ∈∈=
LWWL*
‫ת‬ ‫י‬ ‫ר‬ ‫א‬ ‫ל‬ ‫ו‬ ‫ג‬ ‫ר‬ ‫ה‬ ‫פ‬ ‫ש‬
.
NFA
NFA

מודלים חישוביים - תרגול מס 2 - אוניברסיטת חיפה