QP-Computer Science -2024
QP-Computer Science -2024
Maximum Marks: 70
(Candidates are allowed additional 15 minutes for only reading the paper.
They must NOT start writing during this time.)
Answer all questions from Part-I(compulsory) and six questions from Part-II,
choosing two questions from Section A, two from Section B and two from Section C.
All working including rough work, should be done on the same sheet as the question.
The intended marks for questions or parts of questions are given in brackets [ ]
Question 1
(i) If A and B are the inputs of a half adder, the sum of the half adder is [1]
(a) A OR B
(b) A AND B
(c) A XOR B
(d) A EX-NOR B
(ii) Assertion(A): Java uses string constant pool and once a String object is created with a
value, we are not allowed to perform any changes in that object.
Reason(R) : Strings in Java are immutable. [1]
(a) Both Assertion(A) and Reason(R) are true, and Reason is the correct explanation for
Assertion.
(b) Both Assertion(A) and Reason(R) are true, but Reason is not the correct explanation for
Assertion.
(c) Assertion(A) is true and Reason(R)is false.
(d) Assertion(A) is false and Reason(R) is true.
(iii) All interfaces in Java are by default. [1]
(a) public and private
(b) private and protected.
(c) public and abstract
Page 1 of 11
(d) public and protected.
(iv) Assertion(A): Half adder is faster than a full adder.
Reason(R) : Half adder produces only one output while a full adder gives two outputs.[1]
(a) Both Assertion(A) and Reason(R) are true, and Reason is the correct explanation for
Assertion.
(b) Both Assertion(A) and Reason(R) are true, but Reason is not the correct explanation for
Assertion.
(c) Assertion(A) is true, and Reason(R)is false.
(d) Assertion(A) is false, and Reason(R) is true.
(v) What is the complexity of the following code segment? [1]
int a=0,b=0;
for(int i =0; i<N;i++)
{
a *=10;
}
for(int j =0;j<M;j++)
{
b = b*8 + a;
}
(a) O(N*M)
(b) O(N+M)
(c) O(NM2)
(d) O(N2 + M2)
(vi) Which of these is not a correct statement? [1]
(a) Every class containing abstract method must be declared abstract.
(b) Abstract class defines only the structure of the class not its implementation.
(c) Abstract class can be initiated by the new operator.
(d) Abstract class can be inherited.
(vii) Find the complement of the expression P + Q’R. [1]
(viii) Differentiate between Direct and Indirect recursion. [1]
(ix) What happens if there is no base case in a recursive method? [1]
(x) Verify if ((P’ + Q). (Q’ + R))’ + (P’ + R) = 1 [1]
Page 2 of 11
Question 2
(i) Convert the following infix notation to its postfix form: [2]
A/B - C + D * E – A * C ^ F
(ii) A Matrix B[10][7] is stored in memory with each element requiring 2 bytes of storage. If
the base address at B[x][1] is 1012 and the address at B[7][3] is 1060, determine the value
of ‘x’ where the matrix is stored in column-major orientation. [2]
(iii) Read the following program segment and answer the questions that follow:
void CaseStr(String s, int i)
{
if(i < s.length())
{
char ch = s.charAt(i);
if(Character.isUpperCase(ch))
System.out.print(Character.toLowerCase(ch));
else
System.out.print(Character.toUpperCase(ch));
CaseStr(s, i+1);
}
}
(a) What will be the output of the function CaseStr(“MISSISSippi”, 0)? [2]
(b) In one line state what is the task performed by function CaseStr(…) apart from
recursion. [1]
(iv) The following function is a part of the class arrange which stores n integers in an array
arr[]. The member/function bubble sort()arranges the array in ascending order.
void bubblesort()
{
int swapped;
int upto=n-1;
do{
swapped=0;
for(int i=0;i< ?1?;i++)
{
if(a[i] >arr[i+1])
{
int val=arr[i];
arr[i] = a[i+1];
a[i+1]=val;
swapped=1;
}
}
upto=?2?;
}while (swapped==?3?);
Page 3 of 11
}
Answer six questions in this part, choosing two questions from Section A, two from Section B and
two from Section C.
SECTION - A
Answer any two questions.
Question 3
(i) A company intends to develop a device that shows the high-status power load for a
household invertor depending on the criteria given below:
• If the Air conditioner and geyser both are on
OR
• If the Air conditioner is off, but the Geyser and Refrigerator are on
OR
• If the Geyser is off, but Air conditioner and Water purifier are on.
OR
• When all are on
The inputs are:
A : Air conditioner is on
G : Geyser is on
R : Refrigerator is on
W : Water purifier is on
Output: X [1 indicates a high power, 0 indicates low power for all cases]
Draw the truth table for the inputs and outputs given above and write the SOP expression for
X(A,G,R,W). [5]
(ii) Simplify the Boolean expression (A’+C) (A’+C’) (A’+B+C’D) [3]
(iii) State the best-case and worst-case of a Linear Search algorithm. [2]
Page 4 of 11
Question 4
(i) Given the Boolean function F(G,H,I,J) =
G’H’I’J’+G’H’I’J+G’H’IJ’+G’HI’J+G’HIJ+G’HIJ’+GHI’J’+GHI’J+GHIJ+GH’I’J’+GH’IJ+GH’IJ’
(a) Reduce the above expression by using a 4-variable Karnaugh map, showing the various
groups (i.e. octal, quad or pairs). [4]
(b) Draw the logic gate diagram for the reduced SOP expression. Assume that the variables
and their complements are available as inputs. [1]
(ii) Given the Boolean function X(M,B,C,A) =
(M+B+C+A’).(M+B+C’+A).(M+B’+C+A).(M+B’+C’+A’).(M’+B’+C+A).(M’+B’+C+A’).
(iii) (M’+B’+C’+A). (M’+B+C’+A’).(M’+B+C’+A)
(a) Reduce the above expression by using a 4-variable Karnaugh map, showing the various
groups (i.e. octal, quad or pairs). [4]
(b) Draw the logic gate diagram for the reduced POS expression. You may use gates with
more than two inputs. Assume that variable and their complements are available as
inputs. [1]
Question 5
(iv) Draw the logic diagram and truth table to encode the decimal numbers(1,4,6,9,10) and
briefly explain its working. [3]
Page 5 of 11
SECTION - B
Answer any two questions.
Each program should be written in such a way that it clearly depicts the logic of the problem.
This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are not required)
The programs must be written in JAVA.
Question 6 [10]
A class SeriesSum has been defined to compute the following sum of series:
X2 + X4 + X6 + X8 + …….. Xn
1! 3! 5! 7! (n-1)!
Some of the members and functions of the class are as given below:
Class name : SeriesSum
Data Members
int x :to store the value of ‘x’.
int n :to store the limit of the series.
double sum : to store the sum of the series.
Member methods
SeriesSum(int x, int nn) :constructor to initialize the variables.
double findfact(int m) :to return the factorial of a number ‘m’ using the Recursive technique.
double power(int a, int b):to return ‘a’ raised to the power ‘b’ using the Recursive technique.
void calculate() :to calculate the sum of the series by invoking the recursive functions
wherever applicable.
void display() : displays the sum of the series.
Specify the class SeriesSum giving details of the constructor(int, int), double findfact(int), power(int, int),
void calculate() and void display(). Define the main() method to invoke the functions appropriately to enable
the task.
Question 7 [10]
Design a class Combine to combine the elements of two square matrices in such a way that the lower
triangular section of the new matrix is filled with lower triangular elements of the first matrix and its
upper triangular section is filled with the upper triangular elements of the second matrix. The left
diagonal of the new matrix is the sum of the left diagonal elements of the first and second matrix.
Page 6 of 11
Example:
1 2 3 20 21 22 21 21 22
4 5 6 23 24 25 4 29 25
7 8 9 26 27 28 7 8 37
Data members
Member functions
void combineMat(Combine A, Combine B): to fill the matrix of the current object with the elements
Define the class Combine giving the details of the constructor(), void accept(), void
combineMat(Combine, Combine) and void display(). Define a main() method to create an object
and invoke the functions appropriately.
Question 8 [10]
Encryption is a technique of coding messages to maintain their secrecy. A string array of size ‘n’
where ‘n’ is greater than 1 and less than 10, stores one sentence that ends with a full stop(.), in each
row of the array.
Write a program to define a class with the following specifications:
Class name : Encryption
Data members
Page 7 of 11
str[ ] :string array to store a sentence in each location
n : size of the array
Member methods
Encrpytion(int n) : parameterized constructor to initialize the size with ‘n’.
void accept() : to accept the elements into the string array
void encrypt(String s) : function which encrypts the odd row sentences such that each character in the
sentence is replaced by two characters ahead of it in a circular fashion and
displays the encrypted sentence.
void reverse(String s) : function which stores the even row sentences in reverse of order of its words
and displays the reversed sentence.
Specify the class Encryption giving details of the constructor(), void accept(), void reverse(s), void
encrypt(s). Define a main() function to create an object and call the functions accordingly to enable
the task.
Sample Input 1:
N=4
IT IS CLOUDY
IT MAY RAIN
THE WEATHER IS FINE
IT IS COOL
Sample Output 1:
KV KU ENQWFA
RAIN MAY IT
VJG YGCVJGT KU HKPG
COOL IS IT
Sample Input 2:
N = 13
Sample Output 2: Invalid size entered.
SECTION C
Answer any two questions.
Question 9 [5]
Page 8 of 11
A company increases the salary of employees at the beginning of every official year. A super class
named Employee contains the details of the employee. The sub class Increment has been defined to
calculate the increment on salary.
void show_details() : displays the details of the employee along with the increment and the new
salary.
Assume that the super class Employee has been defined. Using the concept of inheritance, specify
the class Increment giving details of the constructor(..), void calculate() and void show_details().
The super class and the main() method need not be written.
Question 10
Page 9 of 11
Namelist is a linear data structure which works in such a way that the user can enter and remove
names from one end only i.e. from the top.
(a) Specify the class by giving the details of only the functions void push(String s) and String
pop(). Assume that the other functions have been defined. The main() function need not be
written. [4]
(b) Name the entity implemented above. What is the principle of the above entity? [1]
Question 11
Page 10 of 11
(d) Write the sub-tree of node H. [1]
********END OF PAPER********
Page 11 of 11