Assignment 2 for CSCI 431

  1. Design a grammar and an equivalent finite state machine to recognize the language defined by this regular expression: (a+b)*aba(a+b)*


  2. Design a finite state machine to recognize strings of even numbers of right- and even numbers of left-hand braces "(" and ")" e.g. )()(())( is valid but )(()()(()) is not. Your input alphabet is just { (,) }.


  3. Design a recogniser (a state machine) for properly balanced strings of braces. e.g. (()()) is valid but )(()()(())is not. Again, your input alphabet is just { (,) }.


  4. What is the complexity of the following code segment, where n represents the number of data items to be processed:
    
       for i in 1 .. n loop
          for j in 1 .. n loop
             if (array[i] < array[j])
    	    swap(array[i], array[j]);
          end loop
       end loop