**COMPUTER SCIENCE (PAPER 1: THEORY)**

**(Maximum Marks: 70)
(Time allowed: Three hours)**

(Candidates are allowed additional 15 mins for only reading the paper. They must NOT start writing during this time.)

Answer all questions in 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 rest of the answer. The intended marks for questions or parts of questions are given in brackets [ ].

**PART I (20 Marks)**

Answer all questions.

While answering questions in this Part, indicate briefly your working and reasoning, wherever required.

**1(a) State the law represented by the following proposition and prove it with the help of a truth table: P V P = P [1]**

Law : Idempotent Law. It states that P v P = P.

P P P V P0 0 0 1 1 1

**(b) State the Principle of Duality. [1]**

Principle of Duality states that, to every Boolean Equation there exists another equation which is dual to the original equation. To achieve this, the AND’s (.) are converted to OR’s (+) and vice-versa, 0’s to l’s and vice versa, however, the complements remain unchanged.

**(c) Find the complement of the following Boolean expression using De Morgan’s law: F(a, b, c) = (b’ + c) + a [1]**

Complement of : F(a, b, c ) =(b’ + c ) + a

= (b’ + c)’ . a’

= b”. c’. a’ = b.c’.a’

**(d) Draw the logic diagram and truth table for a 2 input XNOR gate. [1]**

A B X0 0 1 0 1 0 1 0 0 1 1 1

**(e) If (P’ => Q) then write its: [1]**

a. Inverse : ( P => Q) OR P’ + Q’

b. Converse : ( Q => P) OR Q’ + P’

**2(a) What is an interface? How is it different from a class? [2]**

(a) Interface is a non primitive data type which has static and final data members and prototype of functions ( i.e. functions are not defined )

**Difference between Interface and Class : **Interface supports multiple inheritance whereas a Class does not support multiple Inheritance.

**(b) Convert the following infix expression to postfix form: P * Q / R + (S + T) [2]**

(b) Infix to postfix : P*Q/R+(S+T) = P*Q/R+ ST+ = PQ* /R + ST+ = PQ*R/ + ST+ = PQ*R/ST++

**(c) A matrix P[15][10] is stored with each element requiring 8 bytes of storage. If the base address at P[0][0] is 1400, determine the address at P[10][7] when the matrix is stored in Row Major Wise. [2]**

(c) Row Major Wise: P[i][j] = BA + W [ (i — lr )* column + (j — lc]

= 1400 + 8[ (10-0)*10 + (7-0)]

= 1400 + 856

P[10][7] = 2256

**(d) (i) What is the worst case complexity of the following code segment: [2]**

`for` `(` `int` `x = 1; x <= a; x++) { ` ` ` `statements; ` `} ` `for` `(` `int` `y = 1; y <= b; y++) { ` ` ` `for` `(` `int` `z = 1; z <= c; z++) { ` ` ` `statements; ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

= O(a) + O(b x c)

= O(a + bc)

**(ii) How would the complexity change if all the three loops went to N instead of a, b and c?**

= O(N) + O(N^{2})

= O(N^{2}), taking the dominant term.

**(e) Differentiate between a constructor and a method of a class. [2]**

(e) Constructor has the same name of the class where as a method has a different name. There is no returning type, not even void in constructor where as in a method it can return a value

**3. The following function magicfun() is a part of some class. What will the function magicfun() return, when the value of n=7 and n=10, respectively? Show the dry run/working: [5]**

`int` `magicfun(` `int` `n) ` `{ ` ` ` `if` `(n = = 0) ` ` ` `return` `0; ` ` ` `else` ` ` `return` `magicfun(n / 2) * 10 + (n % 2); ` `} ` |

*chevron_right*

*filter_none*

**(i) when n = 7**

OUTPUT : magicfun(7) magicfun(3) * 10 + 1 magicfun(1) *10 + 1 magic fun(0) *10 + 1 = 111

**(ii) when n = 10**

OUTPUT : magicfun(10) magicfun(5) * 10 + 0 magicfun(2) *10 + 1 magicfun(1) *10 + 0 magicfun(0) *10 + 1 = 1010

**PART – II (50 Marks)**

Answer six questions, choosing two questions from Section A, two from Section B and two from Section C.

**SECTION – A** (Answer any two questions)

**4(a) Given the Boolean function F(A, B, C, D) = R (2, 3, 4, 5, 6, 7, 8, 10, 11).
(i) Reduce the above expression by using 4-variable Karnaugh map, showing the various groups (i.e. octal, quads and pairs). [4]**

Quad 1: (M2+ M3+ M10, M11 ) = B’C

Quad 2: (M4, M5, M6, M7 ) = A’B

Quad 3: (M8, M10) = AB’D’

Hence F(A, B, C, D) = B’C + A’B + AB’D’

**(ii) Draw the logic gate diagram for the reduced expression. Assume that the variables and their complements are available as inputs. [1]**

**(b) Given the Boolean function F(P, Q, R, S) = R (0, 1, 2, 4, 5, 6, 8, 10).**

Quad 1 : (M0, M1, M4, M5) = Q + S

Quad 2 : (M0, M2, M4, M6) = P + S

Quad 3 : (M0, M2, M8, M10) = P + R

Hence F(P, Q, R, S) = (P + R) . (P + S) . (Q + S)

**(i) Reduce the above expression by using 4-variable Karnaugh map, showing the various groups (i.e. octal, quads and pairs). [4]**

**(ii) Draw the logic gate diagram for the reduced expression. Assume that the variables and their complements are available as inputs. [1]**

**5(a) A school intends to select candidates for an Inter-School Essay Competition as per the criteria given below:
The student has participated in an earlier competition and is very creative.
OR
The student is very creative and has excellent general awareness, but has not participated in any competition earlier.
OR
The student has excellent general awareness and has won prize in an inter-house competition.
The inputs are:
INPUTS
A participated in a competition earlier
B is very creative
C won prize in an inter-house competition
D has excellent general awareness**

**Output : X [1 indicates yes, 0 indicates no for all cases]
Draw the truth table for the inputs and outputs given above and write the POS expression for X(A, B, C, D). [5]**

A B C D X (OUTPUT)0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1

POS Expression: X (A, B, C, D) = R (0, 1, 2, 4, 6, 8, 9, 10)

**(b) State the application of a Half Adder. Draw the truth table and circuit diagram for a Half Adder. [3]
Application of Half Adder is to perform partial addition of two bits.
Truth table of Half Adder :**

A B Sum CARRY0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1

**(c) Convert the following Boolean expression into its canonical POS form: F(A, B, C) = ( B + C’) · (A’ + B) [2]**

Convert to Canonical form: F(A, B, C)

= (B + C’).(A’+ B)

= (B + C’+ 0) . (A’+ B + O)

= (B+C’+(A.A’)).(A’+B+(C.C’)) [xx’=0]

= (A+B+C’).(A’+B+C’).(A’+B+C)

**6(a) What is a Multiplexer? How is it different from a decoder? Draw the circuit diagram for a 8:1 Multiplexer. [5]**

(a) A Multiplexer is a combinational circuit which inputs parallel data and outputs one serial data where as, a Decoder is a combinational circuit which inputs n lines and outputs 2n or fewer lines.

Circuit diagram of a 8:1 Multiplexer :

**(b) Prove the Boolean expression using Boolean laws. Also, mention the law used at each step. F = (x’ + z) + [ (y’ + z) • (x’ + y) ]’ = 1 [3]**

F = (x’+z) + [ (y’+z).(x’+y) ] = 1

= (x’+z) + (y’+z)’ + (x’+y)’ **(De Morgan Law)**

= x’+z + y.z’ + xy’

= (x’+x)(x’+y’) + (z+z’)(z+y) = x’+y’+z+y (Distributive Law)

= 1 **(as y+y’=1)(Identity Law)**

**(c) Define maxterms and minterms. Find the maxterm and minterm when: P = 0, Q = 1, R = 1 and S = 0 [2]**

Maxterm : It is the sum of all its literals.

Minterms : It is the product of all its literals.

When P=0, Q=1, R=1, S=0

Maxterm = P + Q’ + R’ + S

Minterms = P’ Q R S’

**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.

**7. A class Palin has been defined to check whether a positive number is a Palindrome number or not.
The number ‘N’ is palindrome if the original number and its reverse are same.
Some of the members of the class are given below: [10]
Class name : Palin
Data members/instance variables:
num : integer to store the number
revnum : integer to store the reverse of the number
Methods/Member functions:
P a l i n ( ) : constructor to initialize data members with
legal initial values
void accept( ) : to accept the number
int reverse(int y) : reverses the parameterized argument ‘y’ and stores it in ‘revnum’ using recursive technique
void check( ) : checks whether the number is a Palindrome by invoking the function reverse( ) and display the result with an appropriate message
Specify the class Palin giving the details of the constructor( ), void accept( ), int reverse( int ) and void check( ). Define the main( ) function to create an object and call the functions accordingly to enable the task.**

`import` `java.util.*; ` `public` `class` `Palin { ` ` ` `int` `num, revnum; ` ` ` `static` `Scanner x = ` `new` `Scanner(System.in); ` ` ` `Palin() ` ` ` `num = ` `0` `; ` ` ` `revnum = ` `0` `; ` `} ` `void` `accept() ` ` ` `System.out.println(` `"Enter a number"` `); ` `num = x.nextlntO; ` `} ` `int` `reverse(` `int` `y) ` `{ ` ` ` `if` `(y > ` `0` `) ` ` ` `revnum = revnum * ` `10` `+ y % ` `10` `; ` ` ` `return` `reverse(y / ` `10` `); ` `} ` `else` `return` `revnum; ` `} ` `void` `check() ` `{ ` ` ` `int` `p = num; ` ` ` `if` `(num == reverse(p)) ` ` ` `System.out.println(` `"palindrome"` `); ` ` ` `else` ` ` `System.out.println(` `"not a palindrome"` `); ` `} ` `static` `void` `main() ` `{ ` ` ` `Palin obj = ` `new` `Palin(); ` ` ` `obj.accept(); ` ` ` `obj.check(); ` `} ` |

*chevron_right*

*filter_none*

**8. A class Adder has been defined to add any two accepted time. [10]
Example: Time A – 6 hours 35 minutes
Time B – 7 hours 45 minutes
Their sum is – 14 hours 20 minutes ( where 60 minutes = 1 hour)
The details of the members of the class are given below:
Class name : Adder
Data member/instance variable:
a[ ] : integer array to hold two elements (hours and
minutes)
Member functions/methods:
Adder( ) : constructor to assign 0 to the array elements
void readtime( ) : to enter the elements of the array
void addtime( Adder X, Adder Y) : adds the time of the two parameterized objects X and Y and stores the sum in the current calling object
void disptime( ) : displays the array elements with an appropriate message (i.e. hours = and minutes = )
Specify the class Adder giving details of the constructor( ), void readtime( ), void addtime(Adder, Adder) and void disptime( ). Define the main( ) function to create objects and call the functions accordingly to enable the task.**

`import` `java.util.*; ` `public` `class` `Adder { ` ` ` `int` `a[] = ` `new` `int` `[` `2` `]; ` ` ` `static` `Scanner x = ` `new` `Scanner(System.in); ` ` ` `Adder() ` ` ` `{ ` ` ` `a[` `0` `] = ` `0` `; ` ` ` `a[` `1` `] = ` `0` `; ` ` ` `} ` ` ` `void` `readtime() ` ` ` `System.out.println(` `"Enter hours and minutes"` `); ` ` ` `a[` `0` `] = x.nextInt(); ` ` ` `a[` `1` `] = x.nextInt(); ` ` ` `void` `disptime() ` ` ` `{ ` ` ` `System.out.println(` `"Hours="` `+ a[` `0` `]); ` ` ` `System.out.println(` `"Minutes="` `+ a[` `1` `]); ` ` ` `} ` ` ` `void` `addtime(Adder X, Adder Y) ` ` ` `{ ` ` ` `a[` `1` `] = X.a[` `1` `] + Y.a[` `1` `]; ` ` ` `a[` `0` `] = a[` `1` `] / ` `60` `; ` ` ` `a[` `1` `] = a[` `1` `] % ` `60` `; ` ` ` `a[` `0` `] += X.a[` `0` `] + Y.a[` `0` `]; ` ` ` `} ` ` ` `static` `void` `main() ` ` ` `{ ` ` ` `Adder a = ` `new` `Adder(); ` ` ` `Adder b = ` `new` `Adder(); ` ` ` `Adder c = ` `new` `Adder(); ` ` ` `a.readtimeO; ` ` ` `b.readtimeO; ` ` ` `c.addtime(a, b); ` ` ` `c.disptime(); ` |

*chevron_right*

*filter_none*

**9. A class SwapSort has been defined to perform string related operations on a word input. [10]
Some of the members of the class are as follows:**

**Class name : SwapSort
Data members/instance variables:
wrd : to store a word
len : integer to store length of the word
swapwrd : to store the swapped word
sortwrd : to store the sorted word
Member functions/methods:
SwapSort( ) : default constructor to initialize data members with legal initial values
void readword( ) : to accept a word in UPPER CASE
void swapchar( ) : to interchange/swap the first and last characters of the word in ‘wrd’ and stores the new word in ‘swapwrd’
void sortword( ) : sorts the characters of the original word in alphabetical order and stores it in ‘sortwrd’
void display( ) : displays the original word, swapped word and the sorted word
Specify the class SwapSort, giving the details of the constructor( ), void readword( ), void swapchar( ), void sortword( ) and void display( ). Define the main( ) function to create an object and call the functions accordingly to enable the task.**

`import` `java.util.*; ` `public` `class` `SwapSort { ` ` ` `String wrd, swapwrd, sortwrd; ` ` ` `int` `len; ` ` ` `static` `Scanner x = ` `new` `Scanner(System.in); ` ` ` `SwapSort() ` ` ` `{ ` ` ` `swapvvrd = ` `""` `; ` ` ` `sortwrd = ` `""` `; ` ` ` `} ` ` ` `void` `readword() ` ` ` `{ ` ` ` ` ` `System.out.println(` `"Enter word in Upper case"` `); ` ` ` `wrd = x.nextO; ` ` ` `len = wrd.lengthO; ` ` ` `} ` ` ` `void` `swapchar() ` ` ` `swapwrd = wrd.charAt(len - ` `1` `) + wrd.sub strin g(` `1` `, len - ` `1` `) ` ` ` `+ wrd.charAt(` `0` `); ` `} ` `void` `sortword() ` `{ ` ` ` `char` `c; ` ` ` `for` `(` `int` `i = ` `65` `; i <= ` `90` `; i++) ` ` ` `for` `(` `int` `j = ` `0` `; j < len; j++) ` ` ` `c = wrd.charAt(j); ` ` ` `if` `(c == i) ` ` ` `sortwrd += c; ` `} ` `} ` `} ` `void` `display() ` `{ ` ` ` `System.out.println(` `"Original word = "` `+ wrd); ` ` ` `System.out.println(` `"Swapped word = "` `+ swapwrd); ` ` ` `System.out.println(` `" Sorted word = "` `+ sortwrd); ` `} ` `static` `void` `main() ` ` ` `SwapSort x = ` `new` `SwapSort(); ` `x.readwordO; ` `x.swapchar(); ` `x.sortword(); ` `x.display(); ` `} ` |

*chevron_right*

*filter_none*

**SECTION – C**

Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem

step wise. This can be achieved by using comments in the program and mnemonic names or pseudo codes for algorithms. The programs must be written in Java and the algorithms must be written in general / standard form, wherever required / specified. (Flowcharts are not required.)

**10.A super class Product has been defined to store the details of a product sold by a wholesaler to a retailer. Define a sub class Sales to compute the total amount paid by the retailer with or without fine along with service tax. [5]
Some of the members of both the classes are given below:
Class name : Product
Data member/instance variable:
name : stores the name of the product
code : integer to store the product code
amount : stores the total sale amount of the product (in decimals)
Member functions/methods:
Product(String n, int c, double p) : parameterized constructor to assign data members name=n, code=c and amount = p
void show( ) : displays the details of the data members
Class name: Sales
Data member/instance variable:
day : stores number of days taken to pay the sale amount
tax : to store the service tax (in decimals)
totamt : to store the total amount (in decimals)
Member functions/methods:
Sales(…) : parameterized constructor to assign values to data members of both the classes
void compute( ) : calculates the service tax @ 12·4% of the actual sale amount calculates the fine @ 2·5% of the actual sale amount only if the amount paid by the retailer to the wholesaler exceeds 30 days calculates the total amount paid by the retailer as (actual sale amount + service tax + fine)
void show( ) : displays the data members of super class and the total amount
Assume that the super class Product has been defined. Using the concept of inheritance, specify the class Sales giving the details of the constructor(…), void compute( ) and void show( ).
The super class, main function and algorithm need NOT be written.**

`public` `class` `Sales ` `extends` `Product { ` ` ` `int` `day; ` ` ` `double` `tax, totamt; ` ` ` `Sales(String n, ` `int` `a, ` `double` `b, ` `int` `d) ` ` ` `{ ` ` ` `super` `(n, a, b); ` ` ` `day = d; ` ` ` `} ` ` ` `void` `compute() ` ` ` `{ ` ` ` `double` `f = ` `0.0` `; ` ` ` `tax = (` `12.4` `/ ` `100` `) * amount; ` ` ` `if` `(day > ` `27` `) ` ` ` `f = (` `2.5` `/ ` `100` `) * amount; ` ` ` `totamt = amount + tax + f; ` ` ` `void` `show() ` ` ` `{ ` ` ` `super` `.show(); ` ` ` `System.out.println(` `"No of days="` `+ day); ` ` ` `System.out.println(` `"Sales Tax="` `+ tax); ` ` ` `System.out.println(` `"Total Amount="` `+ totamt); ` |

*chevron_right*

*filter_none*

**11. Queue is an entity which can hold a maximum of 100 integers. The queue enables the user to add integers from the rear and remove integers from the front. Define a class Queue with the following details: [5]
Class name : Queue
Data Members / instance variables:
Que[ ] : array to hold the integer elements
size : stores the size of the array
front : to point the index of the front
rear : to point the index of the rear
Member functions:
Queue (int mm) constructor to initialize the data
size = mm, front = 0, rear = 0
void addele(int v ) : to add integer from the rear if possible
else display the message “Overflow”
int delele( ) : returns elements from front if present, otherwise displays the message “Underflow” and return -9999
void display ( ) : displays the array elements
Specify the class Queue giving details of ONLY the functions void addele(int) and int delele( ). Assume that the other functions have been defined. The main function and algorithm need NOT be written.**

`public` `class` `Queue { ` ` ` `int` `Quen = ` `new` `int` `[` `100` `]; ` ` ` `int` `max, f, r; ` ` ` `void` `addele(` `int` `v) ` `if` `(r < max - ` `1` `) ` ` ` `Que[+ - Fr] ` ` ` `= v; ` ` ` `else` `System.out.println(` `"Overflow"` `); ` `} ` `int` `delele() ` `if` `(f != r) ` `return` `Que[++f]; ` `else` `return` `-` `9999` `; ` |

*chevron_right*

*filter_none*

**12(a) A linked list is formed from the objects of the class Node. The class structure of the
Node is given below:
class Node
{
int num;
Node next;
}
Write an Algorithm OR a Method to count the nodes that contain only odd integers from an existing linked list and returns the count. The method declaration is as follows:
int CountOdd( Node startPtr ) [2]**

(a) **ALGORITHM:**

Step 1. Start

Step 2. Set temporary pointer to the first node

Step 3. Repeat steps 4 and 5 until the pointer reaches null. Return count Step 4. Check for odd and increment the counter.

Step 5. Move pointer to the next node

Step 6. End

**METHOD**:

`int` `CountOdd(Node startPtr) ` `{ ` ` ` `int` `c = ` `0` `; ` ` ` `Node temp = ` `new` `Node(startPtr); ` ` ` `while` `(temp != ` `null` `) { ` ` ` `if` `(temp.num % ` `2` `!= ` `0` `) ` ` ` `c++; ` ` ` `temp = temp.next; ` ` ` `return` `c; ` |

*chevron_right*

*filter_none*

**(b) Answer the following questions from the diagram of a Binary Tree given below:
(i) Write the postorder traversal of the above tree structure. [1]**

WFYNRZDGM

**(ii) State the level numbers of the nodes N and R if the root is at 0 (zero) level. [1]**

Level of N=1 and Level of R = 3

**(iii) List the internal nodes of the right sub-tree. [1]**

G and Z

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Computer Science Class XII (2016-17)
- CBSE Class 12 | Computer Science - Python Syllabus
- CBSE Class 11 | Computer Science - C++ Syllabus
- CBSE Class 11 | Computer Science - Python Syllabus
- What happens when we turn on computer?
- Unicode in Computer Network
- Generations of Computer
- Functional Components of a Computer
- Basics of Computer and its Operations
- Concept of Comments in Computer Programming
- What all is inherited from parent class in C++?
- Scanner Class in Java
- C++ string class and its applications
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- StringTokenizer class in Java with example | Set 1 ( Constructors)
- Java.io.File Class in Java
- Friend class and function in C++
- Difference between Abstract Class and Interface in Java
- String class in Java | Set 1
- CBSE Class 11 | Mobile Operating Systems - Symbian, Andriod and iOS

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.