Category: Theoretical Computer Science

Theoretical Computer Science programs such as Finite state machine,Turing machine

finite state machine java code

finite state machine java code

import java.io.*; class FSM { public static void main (String args[])throws IOException { int fsm1,i,base=2,no=4,ans=0,ans1=0,m=0,m1=0,z=0; int b[]={0,0,1,1,2,2,3,3}; int c[]={0,1,0,1,0,1,0,1}; DataInputStream in=new DataInputStream(System.in); System.out.println(“Enter no of bits in Binary no”); fsm1=Integer.parseInt(in.readLine()); int a[]=new int[fsm1]; System.out.println(“Enter...

finite-state machine program in java For String abab (TCS)

finite-state machine program in java For String abab (TCS)

import java.io.*; class FSMS1 { public static void main(String args[])throws IOException { int n=0,i,f=0; DataInputStream in=new DataInputStream(System.in); String fsm; System.out.println(“Enter fsm input”); fsm=in.readLine(); System.out.print(“fsm table “); System.out.println(“\ta\tb”); System.out.println(“q0\tq1\tq0”); System.out.println(“q1\tq1\tq2”); System.out.println(“q2\tq3\tq0”); System.out.println(“q3\tq1\tq4”); System.out.println(“q4\tq4\tq4”); System.out.println(); System.out.print(“State...

Push Down Automata  program in java for Equal no of a’s and b’s

Push Down Automata program in java for Equal no of a’s and b’s

import java.io.*; class pda { public static void main(String args[])throws IOException { String s; int i; int pass=0; DataInputStream in=new DataInputStream(System.in); System.out.println(“Enter String”); s=in.readLine(); char ar[]=s.toCharArray(); Stack ob=new Stack(); for(i=0;i<s.length();i++) { if(ar[i]==’a’) ob.push(ar[i]); else...

turing Machine program in java for equal no of 1’s and 0’s

turing Machine program in java for equal no of 1’s and 0’s

import java.io.*; import java.lang.*; class turing_machine { public static void main(String args[])throws IOException { int i,n1,n,j,z,count=0,count1=0,turing_machine1; DataInputStream in=new DataInputStream(System.in); System.out.println(“Enter Input to turing machine”); String s; s=in.readLine(); turing_machine1=s.length(); char a[]=s.toCharArray(); System.out.print(“String->”); for(i=0;i<turing_machine1;i++) { System.out.print(“\t”+a[i]);...