Computer Science Paper 1 Theory Year 2014
Computer Science Paper 1 Theory Year 2014
Paper 1
Theory
Year 2014
Part I
Answer all questions.
While answering questions to this part, indicate briefly your working and
reasoning, wherever required.
Question 1.
a) From the logic circuit given below, find the output ‘F’ and simplify it. Also,
state the law represented by the logic diagram.
b) Write the truth table for a two input conjunction and disjunction in a
proposition.
c) Find the complement of XY’Z + XY + YZ’
d) Convert the following expression into its canonical POS form: F(A,B)=
(A+B).A’
e) Minimise the following expression using a Karnaugh map:
F(A,B,C)=A’BC’+A’BC+ABC’+ABC
[2X5=
10]
Question 2.
a) State two advantages of using the concept of inheritance in Java.
b) An array AR[-4...6,-2....12], stores elements in Row Majorwise, with
address AR[2][3] AS 4142. If each element requires 2 bytes of storage,
find the Base address.
c) State the sequence of traversing binary tree in :
i) Preorder
ii) Postorder
d) Convert the following infix expression into its postfix form:
(A/B +C) * (D/(E-F))
e) State the difference between the functions intnextInt() and Boolean
hasNextInt().
[2x5
=10]
Question 3.
a) The following functions are part of some class:
void fun1(char s[], int x)
{
System.out.println(s);
char temp;
if(x<s.length/2)
{
temp=s[x];
s[x]=s[s.length-x-1];
s[s.length-x-1]=temp;
1
fun1(s,x+1);
}
}
void fun2(String n)
{
char c[]=new char[n.length()];
for(int i=0;i<c.length;i++)
c[i]=n.charAt(i);
fun1(c,0);
}
i) What will be the output of fun1() when the value of s[]={‘J’,’U’,’N’,’E’}
AND X = 1
[ 2]
ii) What will be the output of fun2() when the value of n= “SCROLL’?
[2]
iii) State in one line what does the function fun1() do apart from recursion.
[1]
b) The following is a function of some class which sorts an integer array a[] in
ascending order using selection sort technique. There are some places in
the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which may be replaced by a
statement/ expression so that the function works properly:
voidselectsort(int []a)
{
inti,j,t,min,minpos;
for(i=0;i<?1?;i++)
{
min=a[i];
minpos=i;
for(j=?2?;j<a.length;j++)
{
if(min>a[j])
{
?3?=j;
min=?4?;
}
}
t=a[minpos];
a[minpos]=a[i];
a[i]=?5?;
}
for(int k=0;k<a.length;k++)
System.out.println(a[k]);
}
i) What is the expression or statement at ?1?
[1]
ii) What is the expression or statement at ?2?
[1]
iii) What is the expression or statement at ?3?
[1]
iv) What is the expression or statement at ?4?
[1]
v) What is the expression or statement at ?5?
[1]
Part II
2
Answer seven questions in this part, choosing three questions from
Section A, two from Section B and two from Section C.
Section A
Answer any three questions
Question 4.
a) Given the Boolean function F(A,B,C,D) = ∑(0,1,2,3,5,6,7,10,13,14,15)
i) Reduce the above expression by using 4 variable Karnaugh map,
showing the various groups (i.e. octals, 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]
b) Given the Boolean function P(A,B,C,D) = π(0,1,2,3,5,6,7,10,13,14,15)
i) Reduce the above expression by using 4-variable Karnaugh map,
showing the various groups (i.e. octals, quads and pairs).
ii) Draw the logic gate diagram for the reduced expression. Assume
that the variables and their complements are available as inputs.
Question 5.
A school intends to select students for the Inter – school athletic meet, as per the
criteria given below:
• The candidate is from the Senior school and has participated in an inter
school athletic meet earlier.
OR
• The candidate is not from the Senior School, but the height is between 5
ft. and 6ft. And weight is between 50 kg and 60 kg.
OR
• The candidate is from the senior school and has height between 5ft. And
6ft., but the weight is not between 50 and 60 kg.
(In all the above cases 1 indicates Yes and 0 indicates No.)
a) Draw the truth table for the inputs and outputs given above and write the
SOP expression for X(S,W,H,A).
[5]
b) Reduce X(S,W,H,A) using Karnaugh map. Draw the logic gate diagram for
the reduced SOP expression for X(S,W,H,A) using AND and OR gate. You
may use gates with two or more inputs. Assume that the variable and their
complements are available as inputs. [ 5 ]
Question 6.
3
a) With the help of a logic diagram and a truth table explain a Decimal to
Binary encoder. [4]
b) Derive a Boolean expression for the logic diagram given below and
simplify it.
[3]
Question 7.
a) Differentiate between XNOR and XOR gates. Draw the truth table and
logic diagrams of three input XNOR gates.
[4]
b) Differentiate between proposition and wff.
[2]
c) Define half adder. Construct the truth table and logic diagram of a half
adder. [ 4 ]
Section B
Answer any 2 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.
Question 8.
A class Mixer has been defined to merge two sorted integer arrays in ascending
arrays in ascending order. Some of the members of the class are given below:
Class Name : Mixer
Data members
intarr[] : to store the elements of an array
int n : to store the size of the array
Member functions
Mixer(intnn) : Constructor to assign n = nn
void accept() : to accept the elements of the
arrayin ascending
order without any duplicates.
Mixer mix(Mixer A) : to merge the current object array
elements with the
4
parameterized array elements and return
the
resultant object.
void display() : to display the elements of the
array.
Specify the class Mixer, giving details of the constructor(int), void accept(), Mixer
mix(Mixer) and void display(). Define the main() function to create an object and
call the function accordingly to enable the task.
[ 10 ]
Question 9.
A class SeriesSum is designed to calculate the sum of the following series:-
Sum= x2/1! + x4/3!+x6/5!+….xn/(n-1)!
Some of the members of the class are given below:
Class name : SeriesSum
Data members
x : to store an integer number
n : to store number of terms
sum : double variable to store the sum of the series
Member functions
SeriesSum(intxx,intnn) : constructor to assign x=xx, n=nn
doublefindfact(int m) : to return the factorial of m using recursive
technique
void calculate() : to calculate the sum of the series by
invoking the recursive
functions repeatedly
void display() : to display the sum of the series
Question 10.
A sequence of Fibonacci strings is generated as follows:
S0 =”a”, S1=”b”, Sn=S(n-1)+S(n-2) where ‘+’ denotes concatenation. Thus the
sequence is: a,b,ba,bab,babba,babbabab,........ n terms.
Design a class FiboString to generate Fibonacci strings. Some of the members of
the class are given below:
5
n : to store the number of terms
Member methods
FiboString() : constructor to assign x=”a”, y=”b”
and
z=”ba”
void accept() : to accept the number of
terms ‘n’
void generate() : to generate and print the
Fibonacci strings.
The sum of (‘+’ i.e. concatenation)
first two strings is the third string.
Eg. “a” is first string, “b” is second
string then the third will be “ba”,
and fourth will be “bab” and so on.
Specify the class FiboString, giving details of the constructor(), void accept() and
void generate(). Define the main() function to create an object and call the
functions accordingly to enable the task.
[ 10 ]
Section C
Answer any 2 questions.
Each program/algorithm should be written in such a way that it clearly depicts
the logic of the problem step wise. This can also be achieved by using comment
in the program and mnemonic names or pseudo codes for algorithms.
(Flowcharts are not required)
The programs must be written in Java.
The algorithm must be written in general standard form wherever
required/specified.
Question 11.
A super class Stock has been defined to store the details of the stock of a retail
store. Define a subclass Purchase to store the details of the items purchased with
the new rate and updates the stock. Some of the members of the classes are
given below:
Class name : Stock
Data members:
item : to store the name of the item
qty : to store the quantity of an item in
stock
rate : to store the unit price of an item
amt : to store the net value of the item in
stock
Member functions:
Stock(......) : parameterized constructor to
assign values
to the data members
6
void display() : to display the stock details
Member functions
Purchase(.....) : parameterized constructor to
assign values
to the data members of both
classes
void update() : to update stock by adding
the previous
quantity by the purchased quantity
and replace the rate of item if there
is a difference in the purchase rate
of the item if there is a difference in
the purchase rate. Also update the
current stock value as:
(quantity * unit price)
Specify the class Stock, giving details of the constructor() and void display().
Using concept of inheritance, specify the class Purchase, giving details of the
constructor(), void update() and void display().
The main function and algorithm need not be written.
[ 10 ]
Question 12.
A stack is a linear data structure which enables the user to add and remove
integers from one end only, using the concept of LIFO(Last In First Out). An array
containing the marks of 50 students in ascending order is to be pushed into the
stack.
7
void input_marks() : to input the marks from user and store it in the
array m[] in
ascending order and simultaneously push the
marks into the stack st[] by invoking the
function pushmarks()
int popmarks() : to return marks from the stack if possible,
otherwise, return
-999
void display() : to display the stack elements
Specify the class Array_to_Stack, giving the details of the constructor(int), void
input_marks(), void pushmarks(int), int popmarks() and void display().
Question 13
a) A linked list is formed from the objects of a class:
class Node
{
int number;
Node nextNode;
}
Write an algorithm OR method to add a node at the end of an existing linked list.
The method declaration is as follows:
void addnode(Node start, int num)
[4]
b) Define the terms complexity and Big ‘O’ notation.
[2]
c) Answer the following from the diagram of the Binary Tree given below:
8
i) Root of the tree.
ii) Left subtree
iii) Inorder traversal of the tree
iv) Size of the tree
[4]