Yatra.com Interview Question Software Engineer / Developers


Country: India
Interview Type: In-Person


Comment hidden because of low score. Click to expand.
0
of 2 vote

Here is a sample program using five states

#include<stdio.h>

enum state
{
	STATE_NONE,
   STATE_ODDA,
   STATE_EVENA,
   STATE_ODDB,
   STATE_EVENB
}s;

int
 dfa(const char*str)
 {
 	 enum state ssa=STATE_NONE;
 	 enum state ssb=STATE_NONE;
 	 	
    int i=0;
    while(str[i]!= '\0')
    {
    	if(str[i] == 'a')
    	{
    		if(ssa == STATE_NONE)
			{
				ssa = STATE_ODDA;
			}	
    		else if(ssa == STATE_EVENA)
    		{
    			ssa= STATE_ODDA;
    		}
    		else
    		{
    			ssa= STATE_EVENA;
    		}
    	}	
    	if(str[i] == 'b')
    	{
    		if(ssb == STATE_NONE)
    		{
    			ssb = STATE_ODDB;
    		}	
    		else if(ssb == STATE_EVENB)
    		{
    			ssb = STATE_ODDB;
    		}
    		else
    		{
    			ssb = STATE_EVENB;
    		}
    	}	
    	i++;
    }
 
	if(ssa == STATE_EVENA && ssb == STATE_ODDB)
	{
		return 1;
	}
	
	return 0;
 }

int
 main()
 {
   int i=0;
   const char *str = "babababaabaabab";
   
   if(dfa(str))
   {
		printf("Passed dfa\n");
	}
   else
   {
   	printf("Not passed\n");
	}	 
   return 0;
 }

- raja roy on January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your program may work (haven't tried it) but, we're asked to draw a DFA, and, you have separate sets of states for As and Bs. In a DFA, all information must be combined into a single state; ie you'd have to have nodes for oddA_oddB, oddA_evenB, evenA_oddB, and evenA_evenB (plus start of course, evenA_oddB is an accepting state).

- JeffD on January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Name of the states is marked with two letters wich represents a and b status (Even, Odd)

imageshack.us/photo/my-images/819/automatzacarear.png/

- Joel on October 05, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More