This is the section where all questions are compulsory . Each question individually carries 1 or 2 marks . Answers must be to the point without giving much unnecessary details.
Question 1
a) Simplify : (A+C).(A+A.D)+A.C+C [2]
Sol. (A+C).(A+A.D)+A.C+C
=(A+C).A+A.C+C
=(A.A+A.C)+(A.C+C)
= (A+A.C)+(A.C+C)
=A+C
(Since the name of the laws used is not specifically asked for you can excuse yourself from being so meticulous . Just for your knowledge in line 2 Redundance Law and in line 4 Idempotent and Redundance Laws are used. )
b) Draw a logic circuit for (A+B).(C+D).C [2]
Sol.
c ) Verify the following proposition with the help of a truth table
P ∨ (~P ∧ Q) = P ∨ Q
Sol.
d) State De Morgan's Law and verify it using a truth table . [2]
Sol. De Morgan's Law states that the complement of sum of the variables is same as the product of the individual complements of the variables and vice versa.
i) (A+B)'=A'.B'
ii) (A.B)'= A'+B'
Truth table for the proof of i) is as follows
(Since only 2 marks are allotted for the question , proof for any one of the equations is sufficient. I leave the truth table for proving the second equation as an exercise for you . )
e) Answer the questions related to the circuit below :
Output : 2 2 2 3
ii) What will be returned by somefun(84,2) [2]
Sol.
Output : 2 2 3 7
iii) State in one line what does the function somefun(x,y) do apart from recursion. [1]
Sol.It generates Prime Factors.
b) The following function is a class which checks of a positive integer is an Armstrong number by returning true or false . (A number is said to be armstrong if the sum of cubes of all it's digits is equal to the original number). The function does not use modulus to extract digits . There are some places in the code marked by ?1? , ?2? , ?3? , ?4? , ?4? , ?5? which may be replaced by a statement / expression so that the function works properly .
boolen Armstrong(int N)
{
int sum = ?1?;
int num = N;
while (num>0)
{
int f = num/10;;
int s = ?2?;
int digit = num - s;
sum + = ?3?;
num = ?4?;
}
if(?5?)
return true;
else
}
Question 1
a) Simplify : (A+C).(A+A.D)+A.C+C [2]
Sol. (A+C).(A+A.D)+A.C+C
=(A+C).A+A.C+C
=(A.A+A.C)+(A.C+C)
= (A+A.C)+(A.C+C)
=A+C
(Since the name of the laws used is not specifically asked for you can excuse yourself from being so meticulous . Just for your knowledge in line 2 Redundance Law and in line 4 Idempotent and Redundance Laws are used. )
b) Draw a logic circuit for (A+B).(C+D).C [2]
Sol.
c ) Verify the following proposition with the help of a truth table
P ∨ (~P ∧ Q) = P ∨ Q
Sol.
d) State De Morgan's Law and verify it using a truth table . [2]
Sol. De Morgan's Law states that the complement of sum of the variables is same as the product of the individual complements of the variables and vice versa.
i) (A+B)'=A'.B'
ii) (A.B)'= A'+B'
Truth table for the proof of i) is as follows
(Since only 2 marks are allotted for the question , proof for any one of the equations is sufficient. I leave the truth table for proving the second equation as an exercise for you . )
e) Answer the questions related to the circuit below :
i) Give the output if X=1 and Y=0
ii) Name the basic gates represented by the above diagram.
[2]
Sol . i) 1
ii) XOR gate
Question 2.
a) Define computational complexity . Calculate the complexity using Big 'O' notation for the following code segment
for(int k=0;k<n;k++)
s+=k; [2]
Sol. Computational complexity gives the practical difficulty of solving problems as measured by time , number of steps or memory space required about finite combinational objects . It is the growth rate or measurement of an algorithm.
Complexity of the above piece of code is O(n).
b) Covert the following infix notation into postfix form
X+(Y-Z)+((W+E)*F)/J [2]
Sol.
Stack Output
+ X
+( XY
+(- XYZ
+ + XYZ-
+( XYZ-+
+(( XYZ-+W
+((+ XYZ-+WE
+( XYZ-+WE+
+(* XYZ-+WE+F
+ / XYZ-+WE+F*J
+ XYZ-+WE+F*J/
null XYZ-+WE+F*J/+
c) Differentiate between this and super keyword. [2]
Sol. "this" keyword is used to refer current class instance variable.
"super" keyword on the other hand is used to refer immediate parent class instance variable.
d) The array D[-2...10][3...8] contains double type elements.If base address is 4110, find the address of D[4][5] when array is stored in Column Major Wise. [2]
Sol. Column Major Wise memory address of an element A[I][J] is given as A[I][J] = B+W*[(I-Lr)+M*(J-Lc)]
Here B=4110
W=64
I=4
Lr= -2
J=5
Lc=3
M= 10-(-2) +1
=13
hence , D[4][5] = 4110 + 64*(4-(-2))+13*(5-3)
= 4110 + 64*(6+ 26)
= 4110 + 64*32
= 4110 +2048
= 6158
e) State any two characteristics of a binary tree. [2]
Sol . i) Binary tree is a non linear data structure where every node contains an unique value.
ii) Every node contains at the most two sub nodes . Therefore a binary node at level d has maximum 2d nodes .
Question 3
a) The following function is a part of some class . Assume 'x' and 'y' are positive integers greater than 0 . Answer the given questions along with dry run or working.
void somefun(int x, int y )
{
if (x>1)
{
if(x%y==0)
{
System.out.print(y+" ");
somefun(x/y,y)
}
else
somefun(x,y+1)
}
}
i) what will be returned by somefun(24,2) [2]
Sol.
Function
|
Condition 1
|
Condition
|
Checking Value
|
Output
|
Somefun(24,2)
|
24>1 True
|
24%2==0
|
True
|
2
|
Somefun(24/2,2)
|
12>1 True
|
12%2==0
|
True
|
2
|
Somefun(12/2,2)
|
6>1 True
|
6%2==0
|
True
|
2
|
Somefun(6/2,2)
|
3>1 True
|
3%2==0
|
False
|
Somefun(3,2+1)
|
Somefun(3,3)
|
3>1 True
|
3%3==0
|
True
|
3
|
Somefun(3/3,3)
|
1>1 False
|
|
|
|
Function
|
Condition 1
|
Condition
|
Checking Value
|
Output
|
Somefun(84,2)
|
84>1 True
|
84%2==0
|
True
|
2
|
Somefun(84/2,2)
|
42>1 True
|
42%2==0
|
True
|
2
|
Somefun(42/2,2)
|
21>1 True
|
21%2==0
|
False
|
Somefun(21,2+1)
|
Somefun(21,3)
|
21>1 True
|
21%3==0
|
True
|
3
|
Somefun(21/3,3)
|
7>1 True
|
7%3==0
|
False
|
Somefun(7.3+1)
|
Somefun(7,4)
|
7>1 True
|
7%4==0
|
False
|
Somefun(7.4+1)
|
Somefun(7,5)
|
7>1 True
|
7%5==0
|
False
|
Somefun(7,5+1)
|
Somefun(7,6)
|
7>1 True
|
7%6==0
|
False
|
Somefun(7,6+1)
|
Somefun(7,7)
|
7>1 True
|
7%7==0
|
True
|
7
|
Somefun(7/7,7)
|
1>1 False
|
|
|
|
return false;
i) What is the expression at ?1?
ii) What is the expression at ?2?
iii) What is the expression at ?3?
iv) What is the expression at ?4?
v) What is the expression at ?5? [1*5=5]
i) 0
ii) f*10;
iii) Math.pow(digit,3); OR digit*digit*digit;
iv)f;
v)sum==N
No comments:
Post a Comment