go to previous page   go to home page   go to next page

Answer:

Yes. The automaton will stay in the start state, which, for this automaton, is not a final state.


Java Implementation

Here is recognize in Java. Assume that the transition table has already been filled in.

  . . .
final int reject   = -1 ;              // number of the reject state 
int[numStates][128] transition ;       // one row per state, 
                                       // one column per character
  . . .
    
public boolean recognize(String str)
{
  int  state = 0;  // the current state
  int  index = 0;  // index of the current character
  char current;    // the current character
  
  // continue while there are input characters
  // and the reject state has not been reached
  while ( index < str.length() && state != reject )
  {
    current = str.charAt( index++ ) ;
    state   = transition[state][current] ;
  }
  
  // if the last character leads to a final state,
  // the string is accepted.
  if ( index == str.length() && isFinal( state ) )
    return true; 
  else
    return false;
} 

States are represented by integers starting at 0. The reject state is represented by -1. The input string is contained in a String object.


QUESTION 4:

What is the value of "abacc".charAt(0)