You are on page 1of 8

4/25/2012

Pendahuluan
Push Down Automata
• Latar belakang munculnya konsep PDA [1 & 3]
– Terdapat context-free languages yang tidak regular,
contoh
• {0n1n | 0=<n} Is not regular
• {0n1n | 0≤n≤k, for some fixed k} Is regular, for any fixed k
– Finite Automota tidak bisa mengenal semua context-
free languages  Finite Automata memiliki memory
yang terbatas
– A DFA can “remember” only a finite amount of
information, whereas a PDA can “remember” an infinite
amount of (certain types of) information

Pertemuan 11
Dosen Pembina :
Danang Junaedi

IF-UTAMA 2

Perbedaan FA dan PDA [7] Grammar-machine equivalence[3]

• Finite Automata • Push Down Atomata

IF-UTAMA 3 IF-UTAMA 4

IF-UTAMA 1
4/25/2012

Pushdown Automaton [3] Power of PDAs [3]

• Definisi [3] • PDAs are more powerful than FSAs.


– A PDA is an NFA-ε with a stack.
– Transitions are modified to accommodate stack operations • anbn, which cannot be recognized by an FSA, can easily
be recognized by the PDA.
• A pushdown automaton (PDA) is an abstract model
machine similar to the FSA • Stack all a symbols and, for each b, pop an a off the
stack.
• It has a finite set of states. However, in addition, it has a
pushdown stack. Moves of the PDA are as follows: • If the end of input is reached at the same time that the
1. An input symbol is read and the top symbol on the stack is
stack becomes empty, the string is accepted.
read.
2. Based on both inputs, the machine enters a new state and • It is less clear that the languages accepted by
writes zero or more symbols onto the pushdown stack.
• PDAs are equivalent to the context-free languages.
3. Acceptance of a string occurs if the stack is ever empty.
(Alternatively, acceptance can be if the PDA is in a final state.
Both models can be shown to be equivalent.)
IF-UTAMA 5 IF-UTAMA 6

PDAs to produce derivation NDPDAs are different from


strings [3] DPDAs [3]
• Given some BNF (context free grammar). Produce the • What is the relationship between deterministic PDAs and
leftmost derivation of a string using a PDA: nondeterministic PDAs?
• Consider the set of palindromes, strings reading the same forward and
1. If the top of the stack is a terminal symbol, compare it to the
backward, generated by the grammar
next input symbol; pop it off the stack if the same. It is an error
X → 0X0 | 1X1 | 2
if the symbols do not match.
• We can recognize such strings by a deterministic PDA:
2. If the top of the stack is a nonterminal symbol X, replace X on
1. Stack all 0s and 1s as read.
the stack with some string α, where α is the right hand side of
2. Enter a new state upon reading a 2.
some production X→ α.
3. Compare each new input to the top of stack, and pop stack.
• This PDA now simulates the leftmost derivation for • However, consider the following set of palindromes:
some context-free grammar. X → 0X0 | 1X1 | 0 | 1
• This construction actually develops a nondeterministic • In this case, we never know where the middle of the string is. To
recognize these palindromes, the automaton must guess where the
PDA that is equivalent to the corresponding BNF
middle of the string is (i.e., is nondeterministic).
grammar. (i.e., step 2 may have multiple options.)
IF-UTAMA 7 IF-UTAMA 8

IF-UTAMA 2
4/25/2012

Pendahuluan Model Fisik [9]

• Mekanisme kerja PDA [4] • Keterangan


– Memiliki tempat penyimpanan 1. Pita input berisi deretan simbol
yang tidak terbatas berupa yang akan diproses.
stack/tumpukan 2. Tumpukan dapat diisi oleh
– Stack  kumpulan dari elemen- simbol-simbol yang disusun
elemen yg sejenis dengan sifat secara LIFO (Last In First Out)
pengambilan dan penambahan 3. Pita input bergerak satu arah.
melalui suatu tempat yg disebut
top of stack (puncak stack) 4. Pada saat awal, head berada
tepat di atas simbol pertama,
– Sistem pengaturan LIFO (Last In Stack berisi simbol awal Stack.
First Out)
5. Status PDA dapat berubah-
– Operasi pop Pengambilan ubah sesuai dengan simbol
elemen dari stack input dan simbol teratas yang
– Operasi push  memasukkan terdapat dalam Stack.
elemen ke dalam stack

IF-UTAMA 9 IF-UTAMA 10

Formal Definition of a PDA [6] Formal Definition of a PDA [9]


P = (Q, Σ, Γ, δ, S, Z0, F)
di mana
• A pushdown automaton (PDA) is a seven-tuple: P = nama PDA.
Q = himpunan berhingga dari status PDA.
M = (Q, Σ, Г, δ, S, Z0, F) Σ = alfabet input.
Γ = himpunan simbol yang boleh terdapat pada Stack.
Q A finite set of states δ = himpunan transisi status.
Σ A finite set of input alphabet S = status awal.
Z0 = simbol pertama yang terdapat pada Stack
Г A finite set of stack alphabet F = himpunan status akhir.
Transisi status (δ) dinyatakan dalam bentuk
S The initial/starting state, S is in Q δ(qi, a, X) = {(qj, γ)} ; qi, qj ∈ Q ; a = Σ ; X = Γ ; γ = Γ*
Z0 • Deskripsi sesaat : (q, aw, α), di mana
A starting stack symbol, is in Г q = status mesin pada saat itu.
F A set of final/accepting states, which is a = simbol yang sedang terbaca oleh head
w = deretan simbol input yang belum terbaca.
a subset of Q α = deretan simbol dalam Stack. TOS ada di paling kiri.
• Contoh : (q1, 0101, ABB)
δ A transition function Jika deskripsi pada suatu saat adalah (q1, 0101, ABB) dan terdapat aturan
transisi berbentuk δ(q1, 0, A) = {(q2, CA), maka deskripsi mesin berubah
menjadi (q2, 101, CABB), ditulis (q1, 0101, ABB) |- (q2, 101, CABB).
IF-UTAMA 11 IF-UTAMA 12

IF-UTAMA 3
4/25/2012

Transition function [6] Example 1 - 1


• For the language {x | x = an bn, n ≥0 and n in {a,b}*}
• δ(q0 , 0 , Z0)=(q1 , 0Z0) M1 = (Q, Σ, Г, δ, S, Z0, F)
Q={q0, q1, q2, q3};
Start state 0 Σ={a,b};
Stack
symbol Z0 Г={a,$}
S={q0};
Z0 ={$};
Input Next state String γ=0Z0
symbol F={q3}final state atau {}  isi stack kosong
δ:
• If next state is still q0, this means the PDA has (1) δ(q0, a, $) = {(q1, a$)}
not reached the middle of the input string (2) δ(q1, a, a) = {(q1, aa)}
(3) δ(q1, b, a) = {(q2, ε)}
(4) δ(q2, b, a) = {(q2, ε)}
(5) δ(q2, ε, $) = {(q3, ε)}
IF-UTAMA 13 IF-UTAMA 14

Example 1 - 2 Example 1 - 3
• Example Computation: • Example Computation:
(1) δ(q0, a, $) = {(q1, a$)} (1) δ(q0, a, $) = {(q1, a$)}
(2) δ(q1, a, a) = {(q1, aa)} (2) δ(q1, a, a) = {(q1, aa)}
(3) δ(q1, b, a) = {(q2, ε)} (3) δ(q1, b, a) = {(q2, ε)}
(4) δ(q2, b, a) = {(q2, ε)} (4) δ(q2, b, a) = {(q2, ε)}
(5) δ(q2, ε, $) = {(q3, ε)} (5) δ(q2, ε, $) = {(q3, ε)}

Rule Applied State Input Stack Rules Applicable Rule Applied State Input Stack Rules Applicable
- q0 aabb $ (1) - q0 abb $ (1)
(1) q1 abb a$ (2) (1) q1 bb a$ (3)
(2) q1 bb aa$ (3) (3) q2 b ε$ -
(3) q2 b εa$ (4)
(4) q2 ε ε$ (5) • Karena state akhir bukan di q3 maka string abb ditolak
(5) q3 ε ε -

• Karena state akhir ada di q3 maka string aabb diterima

IF-UTAMA 15 IF-UTAMA 16

IF-UTAMA 4
4/25/2012

Example 2 - 1 [8] Example 2 - 2 [8]


• Example Computation:
• For the language {x | x = wcwr and w in {0,1}*} (1) δ(q1, 0, R) = {(q1, BR)} (7) δ(q2, 0, B) = {(q2, ε)}
M = ({q1, q2}, {0, 1, c}, {R, B, G}, δ, q1, R, q2) (2) δ(q1, 0, B) = {(q1, BB)} (8) δ(q2, ε, R) = {(q2, ε)}
δ: (3) δ(q1, 0, G) = {(q1, BG)} (9) δ(q1, 1, R) = {(q1, GR)}
(1) δ(q1, 0, R) = {(q1, BR)} (9) δ(q1, 1, R) = {(q1, GR)} (4) δ(q1, c, R) = {(q2, R)} (10) δ(q1, 1, B) = {(q1, GB)}
(2) δ(q1, 0, B) = {(q1, BB)} (10) δ(q1, 1, B) = {(q1, GB)} (5) δ(q1, c, B) = {(q2, B)} (11) δ(q1, 1, G) = {(q1, GG)}
(3) δ(q1, 0, G) = {(q1, BG)} (11) δ(q1, 1, G) = {(q1, GG)} (6) δ(q1, c, G) = {(q2, G)} (12) δ(q2, 1, G) = {(q2, ε)}
(4) δ(q1, c, R) = {(q2, R)} (12) δ(q2, 1, G) = {(q2, ε)}
(5) δ(q1, c, B) = {(q2, B)} Rule Applied State Input Stack Rules Applicable
- q1 01c10 R (1)
(6) δ(q1, c, G) = {(q2, G)}
(1) q1 1c10 BR (10)
(7) δ(q2, 0, B) = {(q2, ε)}
(10) q1 c10 GBR (6)
(8) δ(q2, ε, R) = {(q2, ε)} (6) q2 10 GBR (12)
(12) q2 0 εBR (7)
• Notes: (7) q2 ε εR (8)
– Rule #8 is used to pop the final stack symbol off at the end of (8) q2 ε ε -
a computation.
• Karena state akhir ada di q2 maka string 01c10 diterima
IF-UTAMA 17 IF-UTAMA 18

Example 2 - 3 [8] Jenis-Jenis PDA


• Example Computation:
(1) δ(q1, 0, R) = {(q1, BR)} (9) δ(q1, 1, R) = {(q1, GR)} 1. Ditinjau dari stack
(2) δ(q1, 0, B) = {(q1, BB)} (10) δ(q1, 1, B) = {(q1, GB)} – Non Extended PDA
(3) δ(q1, 0, G) = {(q1, BG)} (11) δ(q1, 1, G) = {(q1, GG)} δ(qi, a, α) = {(qj, γ)} ; qi, qj qj ∈ Q ; a ∈ Σ ; α, γ ∈ Γ* , dimana
(4) δ(q1, c, R) = {(q2, R)} (12) δ(q2, 1, G) = {(q2, ε)} • α adalah satu simbol teratas dalam stack.
(5) δ(q1, c, B) = {(q2, B)} • γ adalah deretan simbol yang menggantikan α
(6) δ(q1, c, G) = {(q2, G)} Contoh : δ(q1, c, G) = {(q2, G)}
(7) δ(q2, 0, B) = {(q2, ε)} – Extended PDA
δ(qi, a, α) = {(qj, γ)} ; qi, qj ∈ Q ; a ∈ Σ ; α, γ ∈ Γ* , dimana
(8) δ(q2, ε, R) = {(q2, ε)}
• α adalah deretan simbol teratas dalam stack.
• γ adalah deretan simbol yang menggantikan α
Rule Applied State Input Stack Rules Applicable
Contoh : δ(q1, a, bSb) = {(q2, S)}
- q1 1c1 R (9)
(9) q1 c1 GR (6) 2. Ditinjau dari fungsi transisi
(6) q2 1 GR (12) – Deterministik PDA
(12) q2 ε εR (8) δ(q, a, α) = {(p, γ)}
(8) q2 ε ε - contoh: δ(q0, a, a) = {(q1, ε)}
– Nondeterministik PDA
δ(q0, a, α) = {(p1, γ1), (p2, γ2), (p3, γ3), …}
• Karena state akhir ada di q2 maka string 1c1 diterima
contoh: δ(q0, a, a) = {(q0, aa), (q1, ε)}

19 IF-UTAMA 20

IF-UTAMA 5
4/25/2012

Studi Kasus Studi Kasus [9]


1. PDA yang dapat mengenali kalimat 0n1n, n = 1, 2, 3, …
P1 = (Q, Σ, Γ, δ, S, Z0, F) ; 3. PDA P3 = (Q, Σ, Γ, δ, S, Z0, F)
Q = {q0, q1} ; Σ = {0, 1}; Γ = {0, 1, Z} ; S = q0; Z0 = Z ; F = {} ; Q = {q0, q1, q2} ; Σ = {a, b} ; Γ = {a, b, Z} ; S=q0 ; Z0 = Z ; F = {q2} ;
δ sebagai berikut :
(1) δ(q0, 0, Z) = {(q0, 0Z)} (4) δ(q1, 1, 0) = {(q1, ε)}
δ sebagai berikut :
(2) δ(q0, 0, 0) = {(q0, 00)} (5) δ(q1, ε, Z) = {(q1, ε)} a. δ(q0, a, Z) = {(q0, aZ)}
(3) δ(q0, 1, 0) = {(q1, ε)} b. δ(q0, b, Z) = {(q0, bZ)}
Jika diberikan string input 00110101, bagaimanakah perubahan deskripsi sesaat c. δ(q0, a, a) = {(q0, aa), (q1, ε)}
dan komputasinya ? Termasuk ke dalam jenis PDA apakah P1?Jelaskan d. δ(q0, a, b) = {(q0, ab)}
alasannya! e. δ(v, b, a) = {(q0, ba)}
2. PDA P2 = (Q, Σ, Γ, δ, S, Z0, F) f. δ(q0, b, b) = {(q0, bb), (q1, ε)}
Q = {q, p} ; Σ = {a, b} ; Γ = {a, b, S, Z} ; S = q ; Z0 = Z ; F = {p} ; g. δ(q1, a, a) = {(q1, ε)}
δ sebagai berikut : h. δ(q1, b, b) = {(q1, ε)}
(1) δ(q, a, b) = {(q, bS)} (6) δ(q, a, S) = {(q, aS)} (11) δ(q, a, bSb) = {(q, S)} i. δ(q1, ε, Z) = {(q2, ε)}
(2) δ(q, b, b) = {(q, bb)} (7) δ(q, b, Z) = {(q, bZ)} (12) δ(q, ε, aZ) = {(p, ε)} Bagaimanakah perubahan deskripsi sesaat dan komputasinya
(3) δ(q, b, bS) = {(q, a)} (8) δ(q, b, a) = {(q, ba)} (13) δ(q, b, S) = {(q, bS)}
(4) δ(q, a, Z) = {(q, aZ)} (9) δ(q, b, ba) = {(q, aS)} (14) δ(q, ε, bSb) = {(q, S)}
jika diberi input ababab? Termasuk ke dalam jenis PDA apakah
(5) δ(q, a, a) = {(q, aa)} (10) δ(q, a, aSa) = {(q, S)} (15) δ(q, ε, aSa) = {(q, S)}
P3?Jelaskan alasannya
Jika diberikan input bbaabb, bagaimanakah perubahan deskripsi sesaat dan
komputasinya? Termasuk ke dalam jenis PDA apakah P2?Jelaskan
alasannya!
IF-UTAMA 21 22

Cara Mengkonstruksi PDA [9]


Konstruksi Push Down Automata
• Analisis skenario kerja PDA
– Buat skenario kerja PDA
– Definisi status-status yang diperlukan
– Definisikan PDA
• Analisis tata bahasa  Berdasarkan Tata
Bahasa Bebas Konteks

Pertemuan 12
Dosen Pembina :
Danang Junaedi

IF-UTAMA 24

IF-UTAMA 6
4/25/2012

Analisis skenario kerja PDA[9] Analisis skenario kerja PDA[9]


• Contoh : PDA yang mengenali 0i12i • Contoh : PDA yang mengenali 0i12i (Lanjutan)
– Buat skenario kerja PDA – Definisikan PDA
1. Jika saat awal, head membaca 0, TOS = Z, maka mesin telah P4 = (Q, Σ, Γ, δ, S, Z0, F)
membaca 0, simpan 00 ke dalam stack. • Q = himpunan status = {q0 , q1, q2}
2. Jika mesin telah membaca 0, head membaca 0, TOS = 0, maka mesin • Σ = himpunan simbol-simbol yang dibaca oleh head = {0, 1}
telah membaca 0, simpan 00 ke dalam stack. • Γ = himpunan simbol - simbol yang disimpan ke dalam stack = {0,Z}
3. Jika mesin telah membaca 0, head membaca 1, TOS = 0, maka mesin • S = q0
telah membaca 1, ambil simbol teratas dari stack.
• Z0 = Z
4. Jika mesin telah membaca 1, head membaca 1, TOS = 0, maka mesin
telah membaca 1, ambil simbol teratas dari stack. • F = {}
5. Jika mesin telah membaca 1, input sudah habis, TOS = Z, maka mesin • Terjemahkan skenario kerja ke dalam fungsi transisi
telah membaca 1, ambil simbol teratas dari stack, head tidak bergerak. 1. δ(q0 , 0, Z) = {(q1, 00Z)}
– Definisi status-status yang diperlukan 2. δ(q1, 0, 0) = {(q1, 000)}
• q0= saat awal 3. δ(q1, 1, 0) = {(q2, ε)}
• q1= mesin telah membaca 0 4. δ(q2, 1, 0) = {(q2, ε)}
• q2 = mesin telah membaca 1 5. δ(q2, ε, Z) = {(q2, ε)}

IF-UTAMA 25 IF-UTAMA 26

Analisis tata bahasa  Berdasarkan


Tata Bahasa Bebas Konteks[9]
Studi Kasus [9]
• Jika terdapat tata bahasa bebas konteks G = (Vn, Vt, P, S), maka 1. Buktikanlah bahwa kalimat 001111 diterima oleh P4 dan
PDA yang mengenali bahasa L(G) adalah P5
– P = (Q, Σ, Γ, δ, S, Z0, F) ; Q = {q} ; 2. Buatlah PDA diterministik P6 yang dapat mengenali
– Σ = Vt ; Γ = (Vn U Vt) ; S = q ; Z0 = S ; F = {} dan bahasa {0n1n | n > 0} U {1n0n | n > 0}
– δ sebagai berikut :
1. Jika A  α anggota dari P, maka δ(q, ε, A) mengandung (q, α)
3. Buatlah PDA P7 yang dapat mengenali bahasa L(G), di
2. δ(q, a, a) = {(q, ε)} untuk seluruh a ∈ Vt
mana G adalah sebagai berikut :
• Contoh: Tata bahasa bebas konteks untuk {0n12n | n > 0} G = (Vn, Vt, P, S) ; Vn = {N, D} ; Vt = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
G = (Vn, Vt, P, S); Vn = {X} ; Vt = {0, 1} ; S = S ; S = N ; P sebagai berikut :
P : { X  0X11 • ND
X  011 } • N  ND
– Maka • D0|1|2|3
P5 = (Q, Σ, Γ, δ, q0, Z0, F) ; Q = {q} ; Σ = {0, 1} ; Γ = {X, 0, 1} ; S = q; P7 = (Q, Σ, Γ, δ, q0, Z0, F) ; Q = {q0, q1} ; Σ = {0, 1}; Γ = {0, 1, Z} ; q0 = q0
; Z0 = Z ; F = {} ;
Z0 = S ; F = {} dan δ sebagai berikut :
1. δ(q, ε, X) = {(q, 0X11)} … ketentuan 1 4. Buatlah PDA P8 yang mampu mengenali bahasa
2. δ(q, ε, X) = {(q, 011)} … ketentuan 1 {02n1n|n>0}
3. δ(q, 0, 0) = {(q, ε)} … ketentuan 2
4. δ(q, 1, 1) = {(q, ε)} … ketentuan 2
27 IF-UTAMA 28

IF-UTAMA 7
4/25/2012

Referensi
1. http://www.dit.hcmut.edu.vn/~tru/AUTOMATA/chapter7.ppt, Tanggal Akses :
11 April 2009
2. http://www.cs.fit.edu/~dmitra/FormaLang/PushdownAutomata.ppt, Tanggal
Akses 11 April 2009
3. http://www.cs.nctu.edu.tw/~lwhsu/course/pl/slides/PZ03A.ppt, Tanggal Akses :
11 April 2009
4. http://semadionline.baliseven.com/materi/push_Down.ppt, Tanggal Akses : 8
April 2009
5. http://www.cs.unm.edu/~joel/cs401/Pushdown%20Automaton.ppt, Tanggal
Akses 11 April 2009
6. http://profile.iiita.ac.in/IIT2006110/Documents/fat/pushdown%20automata%20
230307%201800.ppt, Tanggal Akses : 11 April 2009
7. http://www.csc.lsu.edu/~busch/courses/theorycomp/fall2008/slides/PDA.ppt,
Tanggal Akses : 11 April 2009
8. http://www.cs.fit.edu/~dmitra/FormaLang/PushdownAutomata.ppt, Tanggal
Akses : 11 April 2009
9. Roni Djuliawan, M.T., “Diktat & Handout Kuliah Teori Bahasa &
Otomata”, Teknik Informatika – Universitas Widyatama, 2003

IF-UTAMA 29

IF-UTAMA 8

You might also like