C-Programming |Gate-2013| Previous Year Questions| Set-7

Set-15 C-Programming Gate 2005

C-Programming |Gate-2013|

1. Consider the following function: [GATE – 2013]

int unknown(int n)
    int i, j, k = 0;
    for (i  = n/2; i <= n; i++)
        for (j = 2; j <= n; j = j * 2)
            k = k + n/2;
    return k;

a. Θ(n2)
b. Θ(n2 log n)
c. Θ(n3)
d. Θ(n3 logn)

Answer : b)

2. Consider the following languages. 

Which one of the following statements is FALSE? [GATE – 2013]

a. L2 is context-free.
b. L1∩ L2 is context-free.
c. Complement of L2 is recursive.
d. Complement of L1 is context-free but not regular.

Answer : d)
C-Programming |Gate-2013|

3.  The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed

void find_and_replace(char *A, char *oldc, char *newc) {

    for (int i = 0; i < 5; i++)
       for (int j = 0; j < 3; j++)
           if (A[i] == oldc[j]) A[i] = newc[j];

The procedure is tested with the following four test cases (1) oldc = “abc”, newc = “dab” (2) oldc = “cde”, newc = “bcd” (3) oldc = “bca”, newc = “cda” (4) oldc = “abc”, newc = “bac” The tester now tests the program on all input strings of length five consisting of characters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw? [GATE – 2013]

a. None
b. 2 only
c. 3 and 4 only
d. 4 only

Answer : c)


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *