Exams › GATE › Technical
Consider the following context-free grammars:
G1: S → aS|B, B → b|bB
G2: S → aA|bB, A → aA|B|ε, B → bB|ε
Which one of the following pairs of languages is generated by G1 and G2, respectively?
- {a^m bⁿ | m > 0 or n > 0} and {a^m bⁿ | m > 0 and n > 0}
- {a^m bⁿ | m > 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}
- {a^m bⁿ | m ≥ 0 or n > 0} and {a^m bⁿ | m > 0 and n > 0}
- {a^m bⁿ | m ≥ 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}
Correct answer: {a^m bⁿ | m ≥ 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}
Solution
The correct option accurately describes the languages generated by the grammars: G1 allows for any number of 'a's followed by at least one 'b', while G2 requires at least one 'a' or one 'b', ensuring that both languages have the specified conditions on the counts of 'a's and 'b's.
Related GATE Technical questions
- We want to design a synchronous counter that counts the sequence 0-1-0-2-0-3 and then repeats. The minimum number of J-K flip-flops required to implement this counter is
- A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?
- Consider the following C program.
void f(int, short);
void main()
{
int i = 100;
short s = 12;
short *p = &s;
________; // call to f()
}
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
- The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
- Let G be a weighted connected undirected graph with distinct positive edge weights. If every edge weight is increased by the same value, then which of the following statements is/are TRUE?
P: Minimum spanning tree of G does not change
Q: Shortest path between any pair of vertices does not change
- Consider the following C program.
#include<stdio.h>
void mystery(int *ptra, int *ptrb) {
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
}
int main() {
int a=2016, b=0, c=4, d=42;
mystery(&a, &b);
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf("%d
", a);
}
The output of the program is _________.
⚔️ Practice GATE Technical free + battle 1v1 →