Sunday, 15 November 2015

Specimen ISC Computer Science Theory (Solved) - (Part 1)

1a. State the two Distributive laws of Boolean Algebra. Prove any one of them with the help of a truth table .  [2]

Sol: The two Distributive Laws of Boolean Algebra are as follows
        i) X.(Y+Z)=(X.Y)+(X.Z)
       ii) X+(Y.Z)=(X+Y).(X+Z)

Truth table for i is as follows

Truth table for ii is as follows

(N.B. :You can choose any one of the above proofs)




Q1b.  Find the truth table to verify the expression p->q is equivalent to ~p->~q   [2]

Sol: The truth table for the given expression is as follows




      Hence proved.


Q 1c. Find the complement of the following - [(XY)'.X][(XY').Y]                         [2]

Sol: Complement of the above expression is as follows
[{(XY)'.X}.{(XY)'.Y}]'
=[(XY)'.X]'+[(XY)'.Y]'
=[(XY)']'+X'+[(XY)']'+Y'
=(X'+Y')'+X'+(X'+Y')'+Y'
=X.Y+X'+X.Y+Y'
=X.Y+X'+Y'


Q 1d. Simplify the following Boolean expression using laws of Boolean Algebra. At each step clearly state the law used for simplification.
                                                    Z(Z+X).X(Y+Y')                                                     [2]

Sol:                     Z(Z+X).X(Y+Y')
                         =Z(Z+X).X.1 (Complement law)
                         =(Z.Z+Z.X).X
                         =(Z+Z.X).X     (Idempotent Law)
                         =Z.X+Z.X.X
                         =Z.X+Z.X        (Idempotent Law)
                         =Z.X                  (Idempotent Law)


Q 1e. Given F(X,Y,Z)=XZ+XY+YZ. Write the function in canonical sum of products.        [2]

Sol.     XZ+XY+YZ
         =XZ(Y+Y')+XY(Z+Z')+YZ(X+X')     (A+A'=1 )
         =XYZ+XY'Z+XYZ+XYZ'+XYZ+X'YZ
         =XYZ+X'YZ+XY'Z+XYZ'   (A+A+A=A)




Q 2a. What do LIFO and FIFO stand for?                                                                               [2]

Sol:  LIFO stands for Last In First Out and FIFO stands for First In First Out. Both describes the way in which data is extracted from a certain data structure. In stack data is extracted in LIFO manner while in queue FIFO is followed.


Q 2b. For an array of real nos x[-6...8,-12.....20] , find the address of x[5][4] if x[1][1] is stored in location 100 in the column major order. Assume that each element requires 4 bytes.            [2]

Sol. The formula for memory calculation of a particular address using column major order is as follows

a[i][j]=B+W*[(i-Lr)+M*(j-Lc)]

B=100
W=4
i=5
Lr=1
M=8-(-6)=14
j=4
Lc=1.

Memory Address= 100+4*[(5-1)+14*(4-1)]
                            = 284




Q 2c. Convert the following infix expression to it's postfix form       b*[(a/d)-(c*(e-f))]         [2]

Sol.
                  Stack                                                  Output
                                                                              b
                *[(                                                         ba
               *[(/                                                         bad
               *[                                                            bad/
               *[-(                                                         bad/c
               *[-(*(                                                      bad/ce
               *[-(*(-                                                     bad/cef
               *[-(*                                                        bad/cef-
               *[-                                                           bad/cef-*
              *                                                               bad/cef-*-
             NULL                                                       bad/cef-*-*
                                                                   
So the postfix form is bad/cef-*-*


Q 2d. Define a binary tree.                                        [2]

Sol.  Binary tree is a tree data structure in which each node has at the most two children node referred to as the left node and the right node. The topmost node is called the root node and the last nodes are referred to as the leaf nodes. It is represented as the following
         



Q 2e. State difference between abstract class and interface .                      [2]

Sol:



Q 3a.  a) The following function is a part of some class. It returns the value 1 when the number is an
Armstrong number, otherwise it returns 0.
class Armstrong
{
/* An armstrong number is a number which is equal to the sum of the cube of its individual digits*/
int arms(int n)
{
int digit=0, sum=0;
int rem=n;
while(?1?)
{
digit=?2?;
sum=sum+?3?;
rem=?4?;
}
if(?5?)
return 1;
else
return 0;
}
}
i) What is the expression / value at ?1?
ii) What is the expression / value at ?2?
iii) What is the expression / value at ?3?
iv) What is the expression / value at ?4?
v) What is the expression / value at ?5?                                            [1*5=5]


Sol.
i) while(rem>0)
ii) digit=rem%10;
iii) sum= sum+(digit*digit*digit);
iv) rem=rem/10;
v) if(sum==n)


Q 3b. Give output of the following function where x an y are arguments greater than 0. Show the dry
run/ working.
int strange(int x , int y)
{
//Assuming x>0 y>0
if(x>y)
{
x=x-y;
return strange(x,y);
}
else
return x;
}
i) What will the function strange(20,5) return ?
ii) What will the function strange(15,6) return ?
iii) In one line state the type of function used.                                          [2+2+1]


Sol.
i) Dry run for strange(20,5) is as follows;
ii) Dry run for strange(15,6) is as follows:
  

iii) In the above question strange(x,y) is a recursive function.