Pds Booklet
Pds Booklet
Pds Booklet
KHARAGPUR
Stamp / Signature of the Invigilator
1. You must occupy your seat as per the Examination Schedule/Sitting Plan.
2. Do not keep mobile phones or any similar electronic gadgets with you even in the switched off mode.
3. Loose papers, class notes, books or any such materials must not be in your possession, even if they are irrelevant to the
subject you are taking examination.
4. Data book, codes, graph papers, relevant standard tables/charts or any other materials are allowed only when instructed
by the paper-setter.
5. Use of instrument box, pencil box and non-programmable calculator is allowed during the examination. However,
exchange of these items or any other papers (including question papers) is not permitted.
6. Write on both sides of the answer script and do not tear off any page. Use last page(s) of the answer script for rough
work. Report to the invigilator if the answer script has torn or distorted page(s).
7. It is your responsibility to ensure that you have signed the Attendance Sheet. Keep your Admit Card/Identity Card on the
desk for checking by the invigilator.
8. You may leave the examination hall for washroom or for drinking water for a very short period. Record your absence
from the Examination Hall in the register provided. Smoking and the consumption of any kind of beverages are strictly
prohibited inside the Examination Hall.
9. Do not leave the Examination Hall without submitting your answer script to the invigilator. In any case, you are not
allowed to take away the answer script with you. After the completion of the examination, do not leave the seat until
the invigilators collect all the answer scripts.
10. During the examination, either inside or outside the Examination Hall, gathering information from any kind of sources or
exchanging information with others or any such attempt will be treated as ‘unfair means’. Do not adopt unfair means and
do not indulge in unseemly behavior.
Marks Obtained
Marks obtained (in words) Signature of the Examiner Signature of the Scrutineer
Instructions related to this questions paper:
Page 2
1. Assume that on a certain machine an int variable is of size 32 bits (or 4 bytes), char variable is of size
8 bits (or 1 byte), and each memory address is of size 32 bits. Assume further that the sizeof() function
call returns the size of its operand in bytes. Answer the following questions. Marks: 1 + 2 = 3
(a) Consider the following structure:
struct myStruct {
char name[20];
int account_number;
struct myStruct *next;
};
What does sizeof(struct myStruct) return on this machine?
A. 26 B. 28 C. 48 D. 46
A. 40 B. 20 C. 4 D. 80
int main()
{
int *ptr;
*ptr = 10;
*ptr = 20;
*ptr = 30;
Page 3
printf("%d\n",*ptr);
return 0;
}
(c) Under what condition will this program print the string “Hello”?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr;
ptr = (int *)malloc(sizeof(int)*10);
if (ptr == NULL)
printf("Hello\n");
return 0;
}
3. Fill in the blanks to complete a C program that creates a singly linked list by repeatedly calling the
function push(). It then counts the number of nodes present in the singly linked list recursively using
the function getCount(). Each blank has at most one statement.
Page 4
/* move the head to point to the new node */
_____________________________;
Page 5
if ((n % 2) == 0) return power(x*x, n/2);
}
Let the time required to execute this program be T (n). Assume T (0) = c1 and T (1) = c2 .
(i) The recursive expression is given by T (n) = + c3
(ii) The exact solution to the above recursive expression is
(c) log(n!) = Θ( ∗ log(n)).
5. (a) What does the following function do on the elements of the array arr[]? Marks: 2
void whatdoIdo(int arr[], int size)
{
int i=0;
if(___________________) {
return _________________________________;
} else {
return _____________________;
}
}
(c) Now suppose you have two already sorted arrays ar1[] and ar2[] of EQUAL size n. The following
function attempts to find the median of the elements of the two arrays combined together. For
instance if ar1 = {1.0, 12.0, 15.0, 26.0, 28.0} and ar2 = {2.0, 13.0, 17.0, 30.0, 45.0}, you have to
find the median of the elements {1.0, 12.0, 15.0, 26.0, 28.0, 2.0, 13.0, 17.0, 30.0, 45.0}. Fill in the
blanks. Each blank has only ONE statement.
Marks: (0.5 + 1) + (0.5 + 1) + 0.5 + (0.5 ∗ 3) + (0.5 ∗ 3) + 1.5 = 8
Page 6
/* This function returns median of ar1[] and ar2[].
Assumptions in this function:
Both ar1[] and ar2[] are sorted arrays
Both have n elements */
float getMedian(float ar1[], float ar2[], int n)
{
int i = 0;
int j = 0;
int count;
float m1 = -1.0, m2 = -1.0; // contains medians from two arrays
for (count = 0; count <= n; count++)
{
if (i == n)
{
m1 = ____________;
m2 = ____________;
break;
}
else if (j == n)
{
m1 = ______________;
m2 = ______________;
break;
}
if (ar1[i] _________)
{
m1 = ______________;
m2 = ______________;
i________________;
}
else
{
m1 = _______________;
m2 = _______________;
j_______________;
}
}
return ___________________;
}
6. The following recursive function takes a string of given length as input and determines whether the
string is a palindrome. It returns 0 if the string is not a palindrome and 1 if it is. Fill in the blanks. Each
blank can have AT MOST one statement. Marks: 1 + 2 + 2 = 5
Page 7
7. Complete the following program, where the main function takes three strings A, B,C as input from the
user and determines whether the string A contains the regular expression B ∗ C, where ∗ stands for
any substring. For instance, if A = “abcdefg”, B = “bc” and C = “ef”, the function determines if an
occurrence of “bc” followed (not necessarily immediately) by an occurrence of “ef” can be detected in
“abcdefg”. In this case, the occurrence B ∗C is detected at index position 1 in A, and the main function
gives this output. Either of B or C can also be null. The main function makes use of another function
locateSubstr that checks whether a string A contains another string B as a substring, and if so, returns
the match index of B in A. Thus, when B and C are non-empty, the main function first finds if B is a
substring of A, and if that is the case, whether C is a substring for the remaining portion of A, where the
match for B ends. Fill in the blanks.
Each blank can have AT MOST one statement. Marks: 1 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 10
#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 1024
int locateSubstr ( char A[] , char B[] )
{
int i, j, match;
if (strlen(B) == 0) return 0;
for (i=0; i<=________________; ++i) if (A[i] == B[0]) {
match = 1;
for (j=0; j<______________; ++j) if (_______________)
{ match = 0; break; }
if (match)_________________;
}
return -1;
}
int main ()
{
char A[MAXLEN], B[MAXLEN], C[MAXLEN];
/* Assume the code to input strings from the users is here.
You need not write anything here */
/* i should store the matching index of B*C in A*/
int i,j,k;
if (strlen(B) == 0) i = _____________;
else if (strlen(C) == 0) i = _____________;
else{
j = locateSubstr(A,B);
if (j < 0) i=j;
else k = locateSubstr(____________________);
if (k>=0) i=____________________;
else i =________________;
}
if (i >= 0)
printf("The pattern B*C is found in A at idx %d\n", i);
else
printf("The pattern B*C is not found in A\n");
exit(0);
}
8. The following recursive function makes the base conversion. It reads two integers n and b from the
terminal (with n ≥ 0 and b > 1, both in base 10) and expresses n in base b. For example, the decimal
Page 8
expansion of 345 in base 10 is 345 = 3 × 102 + 4 × 10 + 5. Note that in this case 5 = 345%10 and
34 = 345/10; The output as printed by the program should be: (345) 10 = (3, 4, 5) 10. However,
please note that for n = 10 and b = 2, the program should print (10) 10 = (1, 0, 1, 0) 2 and NOT
(10) 2 = (1, 0, 1, 0) 2 .
Fill in the blanks. Each blank can have AT MOST one statement. Marks: 2 × 5 = 10
#include <stdio.h>
int main ()
{
int n, b;
printf("______________",n);
baseconv(n,b);
printf("____________",b);
exit(0);
}
A. 0 B. 9 C. 13 D. 14
Page 9
[iii] Which of the following is NOT a legal name of a C variable?
A. 12_pds B. _12pds C. pds_12 D. pds12_
(b) Find the 32-bit (single-precision) floating point representation of +41.6 in the IEEE 754 format.
Put only ONE binary digit in each gap/space provided below.
Mantissa:
Page 10
{
int p, q;
for (p=q=0; p<10; ++p) {
q = p + q;
++p;
}
printf("%d\n", q);
return 0;
}
Answer:
10. The following program computes the sum of the square of digits in the decimal representation of a non-
negative integer. For example, the sum of the square of digits for 320127 is 32 + 22 + 02 + 12 + 22 + 72 =
67. Fill in the blanks with appropriate C constructs.
Each blank can have AT MOST one statement. Marks: 1 + 1 + 1 + 1 + 2 + 1 = 7
#include <stdio.h>
int main ()
{
unsigned int n, d, sum;
/* Initialize sum */
sum = ____________________ ;
return 0;
}
Page 11
[Extra Page/ Rough Work]
Page 12
[Extra Page/ Rough Work]
Page 13
[Extra Page/ Rough Work]
Page 14