280 likes | 294 Views
This lecture covers topics such as induction review, DFAs, NFAs, delta and delta hat, strings accepted, languages accepted. It also discusses common mistakes in homework and the application of the Pigeon Hole Principle.
E N D
Lecture 4NFAs CSCE 355 Foundations of Computation Topics: • Induction review • DFAs again • NFAs • Delta, delta hat • Strings accepted, languages accepted Sept 8, 2008
Review DFA • Delta hat • Path determined by input • DFA accepting a string • Language accepted by DFA
DFA Simulation in Ruby • # !/usr/bin/ruby • #MMM 9/5/2008 • # Simulation/Implementation of a DFA in Ruby • # the DFA M=(Q, Sigma, delta, q0, F) • numstates = 4 # Q = [0, 1, 2, 3] • alphabet = ['a', 'b'] # Sigma = {a, b} • # delta implemented as function • q0 = 0 # Start state is state 0 • acceptingState = Array.new(4, 0) • acceptingState[1] = 1 # F = { 1 }
def delta(state, inputChar) case when state == 0 case when inputChar == 'a' then return 1; when inputChar == 'b' then return 3 end when state == 1 case when inputChar == 'a' then return 2 when inputChar == 'b' then return 0 end . . . else return 999 end
# Start Simulation state = 0 print "alphabet = #{alphabet}\n" print "acceptingState = #{acceptingState}\n" # print "Enter the input string: " line = gets puts "line=#{line}" inp = line.chomp.split(//)
# foreach x in inp inp.each { |x| break x if x =="\n" ###break x if x =='X' nextstate = delta(state, x) print "delta(=#{state}, char=#{x}) = #{nextstate}\n" state = nextstate } if acceptingState[state] == 1 then puts "Accept" else puts "Reject" end