COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

54
COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I Answer all questions in this part Question 1. a) State the two complement properties of Boolean Algebra. Verify any one of them using the truth table. b) Simplify the following Boolean expression stating clearly the laws used for simplification at each step. XY + XZ + XYZ c) Find the complement of: X.(Y’Z’ + YZ) d) Convert the following Product of Sum form into its corresponding Sum of Product form:- F(X,Y,Z)= π(2,4,6,7) e) Draw the truth table of the propositional logic expressions p→q and p↔q. [2 x 5 = 10] Question 2. a) Mention two points which distinguish a static data member from an ordinary data member in a class. b) Convert the following infix expression to its postfix form:- A / (B+C) +D * (E-F) c) What do LIFO and FIFO stand for? Name a data structure that follows LIFO principle and one that follows FIFO principle? d) A two dimensional array defined as x[3…6, -2…2] requires 2 bytes of storage space for each element. If the array is stored in row major order, determine the address of X[5,1], given the base address as 1200. e) List the nodes in the tree given below in : i) Preorder ii) Postorder [ 2 x 5 = 10] Question 3. (a) The following is a function of some class. It returns 1 if the number is a perfect number otherwise it returns 0. /* A perfect number is a number which is equal to the sum of its factors other than the number itself. */ intperfectNo(int n) { int ?1?; for(int j=1;?2?;j++) { if(?3?) sum ?4?; } 60 40 70 20 45 80 10 25 41 50 75 85

Transcript of COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Page 1: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008

PART I

Answer all questions in this part Question 1. a) State the two complement properties of Boolean Algebra. Verify any one of them using the truth

table. b) Simplify the following Boolean expression stating clearly the laws used for simplification at each

step. XY + XZ + XYZ

c) Find the complement of: X.(Y’Z’ + YZ)

d) Convert the following Product of Sum form into its corresponding Sum of Product form:- F(X,Y,Z)= π(2,4,6,7)

e) Draw the truth table of the propositional logic expressions p→q and p↔q. [2 x 5 = 10] Question 2. a) Mention two points which distinguish a static data member from an ordinary data member in a class. b) Convert the following infix expression to its postfix form:-

A / (B+C) +D * (E-F) c) What do LIFO and FIFO stand for? Name a data structure that follows LIFO principle and one that

follows FIFO principle? d) A two dimensional array defined as x[3…6, -2…2] requires 2 bytes of storage space for each

element. If the array is stored in row major order, determine the address of X[5,1], given the base address as 1200.

e) List the nodes in the tree given below in : i) Preorder ii) Postorder

[ 2 x 5 = 10]

Question 3. (a) The following is a function of some class. It returns 1 if the number is a perfect number otherwise it

returns 0. /* A perfect number is a number which is equal to the sum of its factors other than the number itself. */ intperfectNo(int n) {

int ?1?; for(int j=1;?2?;j++) {

if(?3?) sum ?4?;

}

60

40 70 20 45 80 10 25 41 50 75 85

Page 2: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

if(?5?) return 1;

else return 0;

} 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 x 5 = 5]

(b) The following functions show() and calling() are a part of some class. Assume that the parameter n is greater than 1 when the function is invoked. It returns the value 1when true otherwise it returns 0. Show the dry run/working. void calling() {

int f=2; show(n,f);

} int show(int n, int f) {

if(n==f) return 1;

if(n%f==0 || n==1) return 0;

else return(show(n,f+1));

} i) What will the function show() return when the value of n is 11? [2] ii) What will the function show() return when the value of n is 27? [2] iii) In one line state what function show() is doing? [1]

PartII Answer any seven questions in this part, choosing three questions from Section A and four questions

from Section B. Section A

Answer any three questions. Question 4. (a) Given F(A,B,C,D)= Σ(5,6,7,8,9,10,14)

Use Karnaugh map to reduce the given function F using the SOP form. Draw a logic gate diagram for the reduced SOP form. You may use gates with more than two inputs. Assume that the variables and their complements are available as inputs.

(b) X(A,B,C,D)= π(0,2,6,8,10,14) Use Karnaugh map to reduce the given function X using the POS form. Draw a logic gate diagram for the reduced POS form. You may use gates with more than two inputs. Assume that the variables and their complements are available as inputs. [ 5 x 2 = 10]

Page 3: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 5. The immigration rules of a country allow the issue of work cum stay permits to an applicant only if the applicant satisfies any one of the following conditions:-

• The spouse of the applicant is a permanent resident of that country, having lived there for at least five years.

OR • The applicant possesses certain special skills as specified in the “skill requirement list” of that

country and is sponsored by a permanent resident of that country. The inputs are:- A : The spouse or sponsor has permanent residence status. B : The spouse has lived in the country for 5 or more years. C : The applicant possesses the required special skills. D : Sponsorship by a permanent resident. Output:- X : Denotes eligible for permit issue. [ 1 indicates Yes and 0 indicates No in all cases]

a) Draw the truth tables for the inputs and outputs given above and write the SOP expression for X(A,B,C,D). [5]

b) Reduce X(A,B,C,D) using Karnaugh’s map. Draw the logic gate diagram for the reduced SOP expression for X(A,B,C,D) using AND & OR gates. You may use gates with more than 2 inputs. Assume that variables and their complements are available as inputs. [5]

Question 6.

(a) How is an XOR gate different from an OR gate? Draw a truth table representing a 3 input XOR operation. Derive its SOP expression and draw the logic gate diagram for the SOP expression. [4]

(b) What is the purpose of a multiplexer? Mention any two applications of a multiplexer. [3] (c) Draw the logic gate diagram for the following three input function F(X,Y,Z) using NOR gates

only. F(X,Y,Z)= Σ(0,1,3,4,7) [3] Question 7.

(a) Reduce the following expression using the laws of Boolean Algebra. Draw the logic gate diagram for the simplified expression:- F=A.(A’+B). C. (A+C) [4]

(b) State the principles of duality. Give an example. [3] (c) Convert AB + BC’ to its canonical SOP form using Boolean Algebra. [3]

Question 8.

(a) Draw the truth table and logic circuit diagram for a 3 x 8 decoder. State the difference between a multiplexer and a decoder. [5]

(b) Reduce the following Boolean expression to the simplest form:- A.[B+C(AB+AC)’] [3]

(c) Given F(X,Y,Z)= Σ(1,3,7) Prove F(X,Y,Z)= π ( 0,2,4,5,6) [2]

Page 4: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Section B Answer any 4 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 C++/Java

Question 9. NIC institute’s resource manager has decided to network the computer resources like printer, storage media, etc. so that minimum resources and maximum sharing could be availed. Accordingly printers are linked to a centralized system and the printing jobs are done on a ‘first come first served basis, only. This is like the first person’s printing job will get done first and the next person’s job will be done as the next job in the list and so on. In order to avoid collision, the restriction is that no more than 20 printing jobs can be added. Define the class Printjob with the following details: Class name : Printjob Data members job[] : array of integers to hold the printing jobs. Newjob : to add a new printing job into the array. Capacity : the maximum capacity of the integer array. Front : to point out to the index of the front. Rear : to point out to the index of the last. Member functions Printjob() : constructor to initialize data members.

Capacity=20, Front = Rear=-1 and call the function createJob().

void createJob() : to create an array to hold the printing jobs. void addJob() : adds the new printing job to the end of the last

printing job, if possible, otherwise displays the message “Printjob is full, cannot add any more”.

void removeJob() : Removes the printing job from the front if the printing job is not empty, otherwise displays the message “Printjob is empty”.

(a) Specify the class Printjob giving details of the constructor and the function void addJob(), void

createJob() and void removeJob() only. You do not need to write the main function. [8] (b) What is the common name of the entity described above? [1] (c) State one of its applications [1]

Question 10. A special number is a number in which the sum of the factorial of each digit is equal to the number itself. For example:- 145 = 1! + 4! + 5!

= 1 + 24 + 120 Design a class Special to check if a given number is a special number. Some of the members of the class are given below:

Page 5: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Class name : Special Data members N : Integer Member functions Special() : constructor to assign 0 to n Special(int) : Parameterized constructor to assign a value to ‘n’ void sum() : calculate and display the sum of the first and last digit of n. void isSpecial() : check and display if the number n is a special number. Specify the class Special giving details of the constructor, void sum() and void isSpecial(). You need not write the main function. [10] Question 11. A class Collection contains an array of 100 integers. Using the following class description create an array with common elements from two integer arrays. Some of the members of the class are given below: Class name : Collection Data members arr[] : integer array len : length of the array Member functions Collection() : default constructor Collection(int) : parameterized constructor to assign the length of the array. void inparr() : to accept the array elements. Collection common(Collection) : returns a Collection containing the common elements

of current Collection object and the Collection object passed as a parameter.

void arrange() : sort the array elements of the object containing common elements in ascending order using any sorting technique.

void display() : displays the array elements. Specify the class Collection giving the details of the constructors, void inparr() and void arrange(). Collection common(Collection). You need not write the main Function. [10] Question 12. A class Employee contains employee details and another class Salary calculates the employee’s net salary. The details of the two classes are given below: Class name : Employee Data members empNo : stores the employee number. empName : stores the employee name empDesig : stores the employee’s designation. Member functions: Employee() : default constructor. Employee(…) : parameterized constructor to assign values to data members. void display() : display the employee details. Class name : Salary

Page 6: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Data members basic : float variable to store the basic pay. Member functions Salary(…) : parameterized constructor to assign values to data members. void calculate() : calculates the employee’s net salary according to the

following rules: DA = 10% of basic HRA = 15% of basic Salary = basic + DA +H RA PF= 8 % of Salary Net Salary = Salary –PF Display the employee details and the Net salary.

Specify the class Employee giving details of the constructors and member function void display(). Using the concept of inheritance specify the class Salary giving details of the constructor and the member function void calculate(). The main function need not be written. [10] Question 13. A class Revstr defines a recursive function to reverse a string and check whether it is a palindrome. The details of the class are given below: Class name : Revstr Data members Str : stores the string. Revst : stores the reverse of the string. Member functions void getStr() : to accept the string. void recReverse(int) : to reverse the string using recursive technique. void check() : to display the original string, its reverse and whether

the string is a palindrome or not. Specify the class Revstr giving details of the functions void getStr(), void recReverse(int) and void check(). The main function need not be written. [10] Question 14. A class Modify has been defined with the following details: Class name : Modify Data members St : stores a string len : to store the length of the string. Member functions void read() : to accept the string inuppercase alphabets. void putin(int , char) : to insert a character at the specified position in the string and

display the changed string. void takeout(int) : to remove character from the specified position in the string

and display the changed string. void change() : to replace each character in the original string by the character which is a t a distance of 2 moves ahead. For example:- “ABCD” becomes “CDEF”, “XYZ” becomes “ZAB”. Specify the class Modify giving details of the functions vod read(), void putin(int,char), void takeout(int) and void change(). The main function need not be written. [10]

Page 7: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2009

PART I

Answer all questions in this part Question 1.

(a) Obtain the truth table to verify the following expression: X(Y+Z) = XY + XZ. Also name the law stated above.

(b) Answer the following questions related to the gate given below:

i) What is the output of the above gate if input A=0, B=1 ii) What are the values of the inputs if output is 1?

(c) Given F= A +(B=C) .( D’+E) . Find F’ and show the relevant working in steps. (d) State the dual for the following expression and also draw the logic gate diagram for the dual

expression obtained using NOR gate only. P= A.B + C.D

(e) For the given truth table where A,B,C are inputs and X is the output,

A B C D 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0

Write i) Canonical Sum of Product expression ii) Canonical Product of Sum expression [2 x 5 = 10]

Question 2.

(a) State a difference between linear and non linear data structure. Give one example of each. (b) Convert the following infix expression to its postfix form:-

((P*Q) / (R/S +T)) + U (c) Simplify the following expression by using the Boolean laws. Show the working in steps and also

mention the laws used.: X’Y’Z’ + X’Y’Z+ X’YZ+X’YZ’+ XY’Z+ XY’Z

(d) Each element of an array A[20][10] requires 2 bytes of storage. If the address of A[6][8] is 4000, find the base address at A[0][0] when the array is stored row major wise.

(e) Define inheritance. How is it useful in programming? [2 x 5 = 10]

Page 8: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 3. (a) The following function trial() and perform() are a part of some class. Answer the following parts

given below. Show the dry run/working. int trial() {

if(n==1) return 2;

else if(n==2) return 3;

else return trial(n-2) + trial(n-1);

} void perform(int p) {

int x; for(int i=1;i<=p;i++) {

x=trial(i); System.out.print(x+” “);

} } i) What will the function trial() return when the value of n is 4? [2] ii) What will be the output of the function perform() when the value of p is 5? [2] iii) In one line state what the function trial() is doing, apart from recursion? [1]

(b) Answer the following from the diagram of a binary tree given below:

i) Root of the tree. ii) External nodes of the tree. iii) List the nodes in the tree using inorder traversal. iv) Left subtree v) Height of the tree [1 X 5 = 5]

Page 9: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Part II Section A

Answer any three questions Question 4.

(a) F(P,Q,R,S)= P’Q’RS’ + P’QRS’ + PQ’R’S+PQ’RS’+PQ’RS+PQR’S+PQRS’+PQRS Use Karnaugh map to reduce the given function F using the SOP form. Draw a logic gate diagram for the reduced SOP form. You may use gates with more than two inputs. Assume that the variables and their complements are available as inputs.

(b) F(A,B,C,D)= π(0,1,2,3,5,7,9,13) Use Karnaugh map to reduce the given function F using the POS form. Draw a logic gate diagram for the reduced POS form. You may use gates with more than two inputs. Assume that the variables and their complements are available as inputs. [5 x 2 = 10]

Question 5. A provisional store announces a special discount on all its products as a festival offer only to those who satisfy any one of the following conditions:

• If he/she is an employee of the store and has a service of more than ten years OR

• If he/she is a regular customer of the store whose age is less than 65 years and is not an employee of the store

OR • If he/she is a senior citizen but not a regular customer of the store

The inputs are: E : Employee of the store R : Regular customer of the store S : Service of the employee is more than 10 years C : Senior citizen of 65 years or above Output X : Denotes eligible for discount[ 1 indicates YES and 0 indicates NO in all cases]

(a) Draw the truth table for the inputs and outputs given above an write the SOP expression for X(E,R,S,C)

(b) Reduce X(E,R,S,C) using Karnaugh’s map. Draw the logic gate diagram for the reduced SOP expression for X(E,R,S,C) using AND , OR gates. You may use gates with more than 2 inputs. Assume that the variables and their complements are available as inputs. [5 x 2= 10]

Question 6.

(a) Draw a truth table representing a 2 input XNOR gate and derive its SOP expression along with its logic gate diagram. [3]

(b) Simplify the following expression and convert it to its canonical POS form: (X.Y+Z)(Y+Z’.X) [3]

(c) From the logic circuit diagram given below, name the parts (1), (2), (3) and finally derive the Boolean expression and simplify it: [4]

Page 10: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 7. (a) Prove that the complement of A(A+B).B(B+C’) is a universal gate. [2] (b) Minimise the following expression. At each step state clearly the law used. [3]

Y=(A+B’).(B+CD)’ (c) Draw the truth table and logic circuit diagram for a decimal to binary encoder. [5]

Question 8.

(a) State a difference between multiplexers and decoders. Also state a use of each. [2] (b) Verify the following Boolean expression with the help of truth table. [3]

(c) Write the SOP expression, truth table and the logic circuit of full adder. [5]

Section B Answer any 4 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 C++/Java

Question 9. A magic number is a number in which the eventual sum of digits of the number is equal to 1. For example, 172 = 1 + 7 + 2 = 10

10 = 1 + 0 = 1 Then 172 is a magic number. Design a class Magic to check if a given number is a magic number. Some of the members of the class are given below: Class name : Magic Data members n : stores the number Member functions Magic() : constructor to assign 0 to n void getnum(intnn) : to assign the parameter value to the number, n=nn int Sum_of_digits(int) : return the sum of the digits of number void ismagic() : checks if the given number is a magic number by calling the function Sum_of_digits(int) and displays appropriate message. Specify the class Magic by giving details of the constructor, void getnum(int), intSum_of_digits(int) and void ismagic(). You need not write the main function. [10] Question 10. A transpose of an array is obtained by interchanging the elements of rows and columns. A class Transarray contains a two dimensional integer array of order [ m x n]. The maximum value possible for both ‘m’ and ‘n’ is 20. Design a class Transarray to find the transpose of a given matrix. The details of the members of the class are given below: Class name : Trasarray Data members arr[][] : stores the matrix elements m : integer to store the number of rows. n : integer to store the number of columns.

Page 11: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Member functions Transarray() : default constructor. Transarray(intmm,intnn) : to inititalize the size of the matrix, m=mm,n=nn. voidfillarray() : to enter elements into the matrix. void transpose(Transarray A) : to find the transpose of a given matrix. voiddisaparray() : displays the array in a matrix form. Specify the class Transarray giving details of the constructors, void fillarray(), void transpose(Transarray) and void disparray(). You need not write the main function. [10] Question 11. A library issues books on a rental basis at a 2% charge on the cost price of the book per day. As per the rules of the library, a book can be retained for 7 days without any fine. If the book is returned after 7 days, a fine will also be charged for the excess days as per the chart given below: Number of excess days Fine per day 1 to 5 2.00 6 to 10 3.00 Above 10 days 5.00 Design a class Library and another class Compute to perform the task. The details of the 2 classes are given below: Class name : Library Data members name : name of the book author : author of the book p : price of the book in decimals Member functions Library(…) : parameterized constructor to assign values to data members. void show() : display the book details class name : Compute Data members d : number of days taken in returning the book. f : to store the fine. Member functions Compute(…) : parameterized constructor to assign values to data

Members of both classes. void fine() : calculate the fine for excess days. void display() : displays the book details along with the number of days,

fine and total amount to be paid. Total amount is calculated as: (2% of price of book * total no. of days) + fine

Specify the class Library giving details of the constructors and void show(). Using the concept of inheritance, specify the class Compute giving details of the constructor, void fine() and the void display() function. You need not write the main function. [10]

Page 12: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 12. A class PrimeFac contains an array of 50 integers. Some of the members of the class are given below: Class name : PrimeFac Data members num[] : array to store integers. freq[] : array to store the frequency of prime factors of numbers. Member functions PrimeFac() : constructor to inititalize array elements to 0. void enter() : to enter values into array num[] voidfrefac() : to determine the frequency of prime factors of the numbers stored in num[] and assign it to freq[]. voiddisp() : to display both the arrays. Specify the classPrimeFac giving details of the constructor, void enter(), void frefac() and void disp(). You need not write the main function. [10] Question 13. Class Binary contains an array of n integers (n<=100) that are already arranged in ascending order. The subscripts of the array elements vary from 0 to n-1. The data members and member functions of class Binary are given below: Class name : Binary Data members A[] : integer array of 100 elements n : size of array l : location of the lower bound u : location of the upper bound Member functions: Binary(intnn) : constructor to initialize the size n to nn and the other instance variables. voidreaddata() : to fill the elements of the array in ascending order. intbinary_search(int v) : returns the location of the value(v) to be searched in the list by binary search method using the recursive technique. The function returns -1 if the number is not present in the given list.

(a) Specify the class Binary giving details of the constructor, void readdata() and intbinary_search(int). younedd not write the main function. [8]

(b) State the base case in the recursive technique binary_search(). [1] (c) What are the drawbacks of using the recursive technique? [1]

Page 13: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 14. A class SortWord has been defined with the following details: Class name : SortWord Data members txt : stores the word. len : stores the length of the word. Member functions SortWord() : default constructor voidreadTxt() : to accept the word in lower case. voidsortTxt() : to sort the word in alphabetical order of characters using bubble sort technique and display it. voidchangeTxt() : to change the case of vowels in the word to upper case. For example :- school becomes school. voiddisp() : to display the changed string. Specify the class SortWord giving the details of the functions constructor, void readTxt(), void sortTxt(), void changeTxt() and void disp(). You need not write the main function. [10]

Page 14: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2010

Question 1.

(a) If X=A’BC + AB’C + ABC + A’BC’ then find the value of X when A=1; B=0; C=1 (b) Verify if, P.(~P+Q’)=(P→Q) using truth table. (c) Draw the logic circuit of NOR using NAND gate only. (d) Convert the following function into its Canonical Sum-Of_products form:

F(X,Y,Z)= Σ(0,1,5,7) (e) Show that the dual of 𝑃’𝑄𝑅’ + 𝑃𝑄’𝑅 + 𝑃’𝑄’𝑅 is equal to the complement of

𝑃𝑄’𝑅 + 𝑄(𝑃’𝑅’ + 𝑃𝑅’) [2 x 5 = 10] Question 2.

(a) State the difference between an interface and a class. (b) Convert the following infix notation to postfix notation.

( A+B) / C * (D +E) (c) A character array B[7][6] has a base address 1046 at 0,0. Calculate the address at B[2][3] if the

array is stored Column Major wise. Each character requires 2 bytes of storage. (d) State the use of exception handling. Name the two types of exceptions. (e) i) What is the worst-case complexity of the following code segment :

for(int i=0;i<N;i++) {

Sequence of statements } for(int j=0;j<M;j++) {

Sequence of statements }

ii) How would the complexity change if the second loop went to N instead of M? [2 x 5 = 10] Question 3.

(a) The following function numbers(int) and numbers1(int) are a part of some class. Answer the questions given below showing the dry run/working:

public void numbers(int n) {

if(n>0) {

System.out.print(n+” “); numbers(n-2); System.out.print(n+” “);

} } public String numbers1(int n) {

If(n<=0) return “”;

return(numbers(n-1)+n+” “; }

i) What will be the output of the function numbers(int n) when n=5? [2] ii) What will the function numbers1(int n) return when n=6? [2] iii) State in one line what is the function numbers1(int) doing apart from recursion? [1]

Page 15: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(b) The following function is a part of some class. It sorts the array a[] in ascending order using insertion sort technique. There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which must be replaced by expression/ statement so that the function works correctly.

void insertsort(int a[]) {

int m= ?1?; int b,I,t; for(i=?2?;i<m;i++) {

t=a[i]; b=i-1; while(?3?>=0 && t<a[b]) {

a[b+1]= a[b]; ?4?;

} ?5?=t;

} }

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 Section A

Answer any three questions Question 4.

(a) Given F(P,Q,R,S)= Σ(0,2,5,7,8,10,11,13,14,15) (i) Reduce the above expression by using 4- variable K-Map, showing the various groups (i.e.

octals, quads and pairs). (ii) Draw the logic gate diagram of the reduced expression using NAND gate only.

(b) Given F(A,B,C,D)= (𝐴 + 𝐵 + 𝐶 + 𝐷) . (𝐴 + 𝐵 + 𝐶 + 𝐷’) . (𝐴 + 𝐵 + 𝐶’ + 𝐷’) . (𝐴 + 𝐵 + 𝐶’ + 𝐷) . (𝐴 + 𝐵’ + 𝐶 + 𝐷’). (𝐴

+ 𝐵’ + 𝐶’ + 𝐷’). (𝐴’ + 𝐵 + 𝐶 + 𝐷). (𝐴’ + 𝐵 + 𝐶’ + 𝐷) (i) Reduce the above expression by using 4- variable K-Map, showing the various groups (i.e.

octals, quads and pairs). (ii) Draw the logic gate diagram of the reduced expression using NOR gate only. [5 x 2 =10]

Question 5. A government institution intends to award a medal to a person who qualifies any one of the following criteria: The person should have been an Indian citizen and had lost his/her life in a war but has not completed 25 years of service.

OR The person must be an Indian citizen and has served the nation for a continuous period of 25 years or more but has not lost his/her life in a war.

OR

Page 16: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

The person is not an Indian citizen but has taken active part in activities for the upliftment of the nation. The inputs are: INPUTS A The person is/was an Indian citizen B Has a continuous service of more than 25 years C Lost his/her life in a war D Taken part in activities for upliftment of the nation Output X Denotes eligible for medal [ 1 indicates YES ad 0 indicates NO in all cases]

(a) Draw the truth table for the inputs and outputs given above and write the POS expression for X(A,B,C,D)..

(b) Reduce X(A,B,C,D) using Karnaugh’s map. Draw the logic gate diagram for the reduced POS expression for X(A,B,C,D) 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 x 2 = 10]

Question 6.

(a) What are Maxterms? Convert the following function as a Product of Maxterms: F(P,Q,R)= (P+Q).(P’+R’)

(b) State whether the following expression is a Tautology or Contradiction with the help of a truth table:

(X↔Z). [(X→Y).(Y→Z)] (c) What is a Multiplexer? Draw the truth table and logic diagram of a 8:1 multiplexer. [2+3+5=10]

Question 7.

(a) Draw the circuit diagram for a 3 to 8 decoder. (b) Draw the truth table for a half adder. Also derive a POS expression for the half adder and draw its

logic circuit. (c) Simplify the following expression and also draw the circuit for the reduced expression. [Show the

step wise working along with the laws used.] F= X. (Y+Z.(X.Y +X.Z)’) [3+3+4=10]

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. The co-ordinates of a point P on a two-dimensional plane can be represented by P(x,y) with x as the x co-ordinate and y as the y co-ordinate. The co-ordinates of midpoint of two points P1(x1,y1) and P2(x2,y2) can be calculated as P(x,y) where: x=x1+x2/2, y=y1+y2/2 Design a class Point with the following details: Class name : Point Data members x : stores the x co-ordinate y : stores the y co-ordinate

Page 17: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Member functions: Point() : constructor to initialize x=0 and y=0 void readPoint() : accepts the co-ordinates x and y of a point Point midpoint(Point A, Point B) : calculates and returns the midpoint of the two points A and B. void displaypoint() : displays the co-ordinates of a point Specify the class Point giving details of the constructor( ), member functions void readPoint(), Point midpoint(Point, Point) and void displaypoint() along with the main function to create an object and call the functions accordingly to calculate the midpoint between any two given points. [10] Question 9. Input a word in uppercase and check for the position of the first occurring vowel and perform the following operation.

(i) Words that begin with a vowel are concatenated with “Y” . For example, EUROPE becomes EUROPEY.

(ii) Words that contain a vowel in between should have the first part from the position of the vowel till end, followed by the part of the string from beginning till position of the vowel and is concatenated by “C”. For example PROJECT becomes OJECTPRC.

(iii) Words which do not contain a vowel are concatenated with “N”. For example, SKY becomes SKYN.

Design a class Rearrange using the description of the data members and member functions given below: Class name : Rearrange Data members Txt : to store a word Cxt : to store the rearranged word len : to store the length of the word Member functions Rearrange() : constructor to initialize the instance variables void readword() : to accept the word input in UPPERCASE void convert() : converts the word into its changed form and stores it in string Txt void display() : displays the original and the changed word Specify the class Rearrange giving the details of the constructor(), void readword(), void convert() and void display(). Define a main function to create an object and call the function accordingly to enable the task. [10] Question 10. Design a class Change to perform string related operations. The details of the class are given below: Class name : Change Data members str : stores the word newstr : stores the changed word len : stores the length of the word Member functions Change() : default constructor void inputword() : to accept a word char caseconvert(char ch) : converts the case of the character and returns it void recchange(int) : extracts characters using recursive technique and changes its case using caseconvert() and forms a new word void display() : displays both the words

Page 18: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(a) Specify the class Change, giving details of the constructor(), member functions void inputword(),

char caseconvert(char ch), void recchange(int) and void display(). Define the main function to create an object and call the functions accordingly to enable the above change in the given word. [8]

(b) Differentiate between finite and infinite recursion. [2]

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 pseudo codes. (Flowcharts are not required)

The programs must be written in Java. The algorithm must be written in general standard form wherever required.

Question 11. A super class Worker has been defined to store the details of a worker. Define a sub class Wages to compute the monthly wages for the worker. The details of both the classes are given below: Class name : Worker Data members : Name : to store the name of the worker Basic : to store the basic pay in decimal Member functions Worker(….) : parameterized constructor to assign values to the instance variables void display() : display worker details class name : Wages Data members hrs : stores the hours worked rate : stores rate per hour wage : stores the overall wage of the worker Member functions Wages(….) : parameterized constructor to assign values to the instance variables of both classes double overtime( ) : calculates and returns the overtime amount as (hours * rate ) void display() : calculates the wage using the formula

wage=overtime amount +basic pay and displays it along with other details Specify the class Worker giving details of the constructor() and void display(). Using the concept of inheritance, specify the class Wages giving details of the constructor(), double overtime() and void display(). The main function need not be written. [10] Question 12. Define a class Repeat which allows the user to add elements from one end (rear) and remove elements from one end (rear) and remove elements from the other end (front) only. The following details of the class Repeat are given below: Class name : Repeat Data members st[] : an array to hold a maximum of 100 integer elements cap : stores the capacity of the array

Page 19: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

f : to point to the index of the front r : to point to the index of the rear Member functions Repeat(int m) : constructor to initialize the data members

cap=m, f=0, r=0 and to create the integer array void pushvalue(int v) : to add integers from the rear index if possible else display the message “overflow” int popvalue() : to remove and return element from the front, if array is empty then return -9999 void disp() : displays the elements present in the list

(a) Specify the class Repeat giving details of the constructor(int), member function void pushvalue(int), int popvalue() and void disp(). The main function need not be written. [8]

(b) What is the common name of the entity described above? [1] (c) On what principle does this entity work? [1]

Question 13.

(a) A linked list is formed from the objects of the class, class ListNodes {

int item; ListNodes next;

} Write a method OR an algorithm to compute and return the sum of all integers items stored in the linked list. The method declaration is specified below:

int listsum(ListNodes start);

(b) What is Big ‘O’ notation? State its significance.

(c) Answer the following from the diagram of a Binary tree given below:

i) Name the parent node of E. [1] ii) Write the postorder tree traversal. [1] iii) Write the internal nodes of the tree. [1] iv) State the level of the root of the tree. [1]

Page 20: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2011

Question 1.

(a) State the two absorption laws. Verify any one of them using truth table. (b) Reduce the following expression :

F(A,B,C)= Σ(0,1,2,3,4,5,6,7) Also find the complement of the reduced expression.

(c) Name the logic gate for the following circuit diagram and write its truth table.

(d) Using truth table, verify whether the following is true or false: (p →q) = (q’→p’)

(e) If A=1, B=0, C=1 and D=1 find its i) maxterm ii) minterm [2 x 5 =10]

Question 2.

(a) How can we override a method in inheritance? (b) A square matrix A[m x m] is stored in the memory with each element requiring 2 bytes of storage.

If the base address A[1][1] is 1098 and the address at A[4][5] is 1144, determine the order of the matrix A[mxm] when the matrix is stored column majorwise.

(c) What is Big O Notation? (d) What is an exception? (e) Convert the infix expression to its postfix form:

A+B*C-D/E [2 x 5 =10] Question 3.

(a) The following is a part of some class. What will be the output of the function mymethod( ) when the value of counter is equal to 3? Show the dry run/ working. void mymethod(int counter)

{ if(counter= =0) System.out.println(“ “);

else {

System.out.println(“Hello “+ counter); mymethod(- -counter); System.out.println(“ “+ counter);

} } [5]

Page 21: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(b) The following function is a part of some class which computes and returns the greatest common divisor of any two numbers. There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, and ?5? which must be replaced by statement/expression so that the function works correctly.

int gcd(int a, int b) {

int r; while(?1?) {

r=?2?; b=?3?; a=?4?;

} if(a==0)

return ?5?; else

return -1; } i) What is the expression or statement at ?1? ii) What is the expression or statement at ?2? iii) What is the expression or statement at ?3? iv) What is the expression or statement at ?4? v) What is the expression or statement at ?5? [1 x 5 = 5]

Part II Answer seven questions in this Part, choosing three questions from Section A and two questions from

Section B and two questions from Section C. Section A

Answer any three questions from this Section Question 4.

(a) State the principle of duality. Give the dual of the following: (A’B)+(C.1)=(A’+C)(B+C) [3]

(b) Reduce the following Boolean expressions to their simplest forms:- i) {(CD)’+A} + A+ C.D + A.B ii) A.{B+C(A.B + A.C)’} [4]

(c) Verify using a truth table if: [3]

Question 5. (a) Given F(P,Q,R,S)= π(2,3,6,7,9,11,12,13,14,15)

Reduce the above expression using four variable K-map. Draw the logic gate diagram of the reduced expression using NOR gates only. [5]

(b) Given F(A,B,C,D)= A’B’C’D’ + A’B’C’D + AB’C’D’+ AB’C’D + A’BC’D’ +A’BCD’. Reduce the above expression by using four variable K-map. Draw the logic gate diagram of the reduced expression using NAND gates only. [5]

Page 22: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 6. (a) Show with the help of a logic diagram how a NAND gate is equivalent to an OR gate. [3] (b) Verify if the following is valid:

(A→B) ^ (A→C)= A→(B^C) [3] (c) What is a decoder? Draw the truth table and logic circuit diagram for a 2 to 4 decoder. [4]

Question 7.

(a) What is a Full Adder? Draw the truth table for a Full Adder. Also derive SOP expression for the Full Adder and draw its logic circuit. [4]

(b) State how a decoder is different from a multiplexer. Also state one use of each. [3] (c) Convert the following cardinal expression into its canonical form and reduce it using Boolean

laws: F(L,M,O,P) = π(0,2,8,10) [3]

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. Input a sentence from the user and count the number of times, the words “an” and “and” are present in the sentence. Design a class Frequency using the description given below: Class name : Frequency Data Members text : stores the sentence countand : to store the frequency of the word and. countan : to store the frequency of the word an. len : stores the length of the string.

Member functions Frequency() : constructor to initialize the data variables. void accept(String n) : to assign n to text where the value of the parameter should be in lowercase. void checkandfreq() : to count the frequency of and. void checkanfreq() : to count the frequency of an. void display() : to display the frequency of “an” and “and” with suitable messages.

Specify class Frequency giving details of the constructor(), void accept(String), void checkand freq() and void display(). Also define the main function to create an object and call methods accordingly to enable the task. [10] Question 9. A class DeciOct has been defined to convert a decimal number into its equivalent octal number. Some of the members of the class are given below: Class name : DeciOct Data members n : stores the decimal number oct : stores the equivalent octal number Member functions: DeciOct() : constructor to initialize the data members to 0 void getnum(int nn) : assigns nn to n void deci_oct() : calculates the octal equivalent of n and stores it in oct using the

recursive technique

Page 23: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

void show() : displays the decimal number n calls the function deci_oct() and displays its octal equivalent

(a) Specify the class DeciOct, giving details of the constructor(), void getnum(int), void deci_oct()

and void show(). Also define a main function to create an object and call the functions accordingly to enable the task. [8]

(b) State any two disadvantages of using recursion. [2] Question 10. You are given a sequence of n integers, which are called pseudo arithmetic sequences ( sequences that are in arithmetic progression). Sequence of n integers : 2, 5, 6, 8, 9, 12 We observe that 2 + 12 = 5 + 9 = 6 +8 = 14 The sum of the above sequence can be calculated as 14 x 3 = 42 For sequence containing an odd number of elements the rule is to double the middle element, for example 2, 5, 7, 9, 12 =2 +12 = 5 +9 = 7 +7 = 14 14 x 3 = 42 [ middle element = 7] A class pseudoarithmetic determines whether a given sequence is pseudo-arithmetic sequence. The details of the class are given below:-

Class name : Pseudoarithmetic Data members n : to store the size of the sequence a[ ] : integer array to store the sequence of numbers ans, flag : to store the status sum : to store the sum of sequence of numbers r : to store the sum of 2 numbers Member functions : Pseudoarithmetic( ) : default constructor void accept(int nn ) : to assign nn to n and to create an integer array. Fill in the elements of the array. boolean check( ) : return true if the sequence is a pseudo-arithmetic sequence

otherwise return false. Specify the class Pseudoarithmetic, giving details of the constructor(), void accept(int) and Boolean check(). Also define the main function to create an object and call methods 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 pseudo codes.

(Flowcharts are not required) The programs must be written in Java.

The algorithm must be written in general standard form wherever required. Question 11. A super class Record has been defined to store the names and ranks of 50 students. Define a sub class Rank to find the highest rank along with the name. The details of both classes are given below: Class name : Record Data members name[] : to store the names of students

Page 24: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

rnk[] : to store the ranks of students Member functions: Record() : constructor to initialize data members void readvalues() : to store names and ranks void display() : displays the names and the corresponding ranks class name : Rank Data members index : integer to store the index of the topmost rank Member functions Rank() : constructor to invoke the base class constructor and to

initialize index to 0. void highest() : finds the index location of the topmost rank and stores it in index without sorting the array void display() : displays the name and ranks along with the name having the topmost rank. Specify the class Record giving details of the constructor(), void readvalues(), void display(). Using the concept of inheritance, specify the class Rank giving details of constructor(), void highest() and void display(). The main function and algorithm need not be written. Question 12. Stack is a kind of data structure which can store elements with the restriction that an element can be added or removed from the top only. The details of class Stack are given below: Class name : Stack st[] : the array to hold names. size : the maximum capacity of the string array top : the index of the topmost element of the stack ctr : to count the number of elements of the stack Member functions Stack() : default constructor Stack(int cap) : constructor to initialize size=cap and top=-1 void pushname(String n) : to push a name into the stack. If the stack is full, display

the message “overflow”. String popname() : removes a name from the top of the stack and returns it. If the stack is empty, display the message “underflow”. void display() : Display the elements of the stack.

(a) Specify class Stack giving details of the constructors(), void pushname(String n), String popname() and void display(). The main function and algorithm need not be written.

(b) Under what principle does the above entity work? Question 13.

(a) A linked list is formed from the objects of the class, class Node {

int info; Node link;

} Write an algorithm OR a method for deleting a node from a linked list. The method declaration is given below: void deletenode(Node start)

Page 25: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(b) Distinguish between worst-case and best-case complexity of an algorithm. (c) Answer the following from the diagram of a Binary tree given below:

i) Write the postorder tree traversal ii) Name the leaves of the tree iii) Height of the tree iv) Root of the tree

Page 26: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2012

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

Question 1.

(a) Using truth table, verify the following expression: X + ( Y + Z ) = ( X + Y ) + Z Also state the law.

(b) Given, F(X, Y, Z)= (X’+ Y’). (Y + Z’) write the function in canonical product of sum form.

(c) Draw the truth table and logic circuit for a 2 – input XNOR gate. (d) Find the complement of the following expression: (e) X’ + XY’ (f) If (X → Y) then write its:

i) Converse ii) Contra positive [2 x 5 = 10]

Question 2. (a) Differentiate between the keyword extends and implements. (b) State how a binary tree is a recursive data structure. (c) A matrix B[10][7] is stored in the memory with each element requiring 2 bytes of storage. If the

Base address at B[x][1] is 1012 and the address B[7][3] is 1060, determine the value x where the matrix is stored in column major wise.

(d) Convert the following infix notation into its postfix form: A + (( B+ C) + ( D + E) * F ) / G

(e) What is a constructor? State one difference between a constructor and any other member function of a class. [2 x 5 = 10]

Question 3.

(a) The following function is a part of some class which computes and sorts an array arr[] in ascending order using the bubble sort technique. There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which must be replaced by a statement/ expression so that the function works properly: class Trial { void bubblesort(intarr[]) { inti,j,k,tmp; for(i=0;?1?;i++) { for(j=0;?2?;j++)

{ if(arr[j]>?3?)

{ tmp=arr[j];

?4?=arr[j+1]; arr[j+1]=?5?;

} } } }

Page 27: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

i) What is the expression or statement at ?1? ii) What is the expression or statement at ?2? iii) What is the expression or statement at ?3? iv) What is the expression or statement at ?4? v) What is the expression or statement at ?5? [1 x 5 = 5]

(b) The following function witty() is a part of some class. What will be the output of the function witty() when the value of n is “SCIENCE” and the value of p is 5. Show the dry run/ working: class Trial1 { public void witty(String n, int p) { if(p<0) System.out.println(""); else { System.out.println(n.charAt(p)+"."); witty(n,p-1); System.out.print(n.charAt(p)); } } } [5]

Part II

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)= Σ(4,6,7,10,11,12,14,15)

(i) Reduce the above expression by using 4 variable K- map, showing the various groups (i.e. octals, quads and pairs).

(ii) Draw the logic gate diagram of the reduced expression. Assume that the variables and their complements are available as inputs. [4 + 1 = 5]

(b) Given the Boolean function F(P,Q,R,S)= π(0,5,7,8,10,12,13,14,15) (i) Reduce the above expression by using 4 variable K- map, showing the various groups (i.e.

octals, quads and pairs). (ii) Draw the logic gate diagram of the reduced expression. Assume that the variables and their

complements are available as inputs. [4 + 1 = 5] Question 5. The principal of a school intends to select students for admission to Class XI on the following criteria:

• Student is of the same school and has passed the Class X Board Examination with more than 60% marks.

OR • Student is of the same school, has passed the Class X Board Examination with less than 60%

marks but has taken active part in co-curricular activities. OR

• Student is not from the same school but has either passed the Class X board Examination with more than 60% marks or has participated in Sports at the national level.

Page 28: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

The inputs are : INPUTS S Student is of the same school P Has passed the Class X Board Examination with more than 60% marks. C Has taken active part in co-curricular activities. T Has participated in sports at the National Level. Output :- X – Denotes admission status [ 1 indicates granted and 0 indicates refused in all the cases.]

(a) Draw the truth table for the inputs and outputs given above and write the SOP expression. (b) Reduce X(S,P,C,T) using Karnaugh’s map.

Draw the logic gate diagram for the reduced SOP expression for X(S,P,C,T) 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 x 2 = 10]

Question 6.

(a) Verify algebraically if, X’Y’Z’ + X’Y’Z + X’YZ + X’YZ’ + XY’Z’ + XY’Z = X’ + Y’ [2]

(b) Represent the Boolean expression X + YZ’ with the help of NOR gates only. [2] (c) Define the terms contingency, contradiction and tautology. [3] (d) Consider the following truth table where A and B are two inputs and X is the output:

A B X 0 0 0 0 1 1 1 0 1 1 1 0

i) Name and draw the logic gate for the given truth table. [2] ii) Write the POS of X(A,B) [1]

Question 7. (a) Define multiplexer and state one of its uses. Draw the logic gate diagram for 4:1Multiplexer. [4] (b) State how a half adder is different from a full adder. Also give their respective uses. [3] (c) Minimize the following expression using Boolean laws:

Q(Q’+P).R.(Q+R) [3] Also draw the logic gate for the reduced Boolean expression.

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 Combine contains an array of integers which combines two arrays into a single array including the duplicate elements, if any, and sorts the combined array. Some of the members of the class are given below:

Page 29: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Class Name : Combine Data members com[ ] : integer array size : size of the array Member functions/methods Combine(intnn) : parameterized constructor to assign size = nn voidinputarray( ) : to accept the array elements void sort() : sorts the elements of combined array in ascending order using the selection sort technique. void mix(Combine A, Combine B) : combines the parameterized object arrays and stores the result in the current object array along with the duplicate elements , if any. void display( ) : displays the array elements. Specify the class Combine giving details of the constructor(int ), void inputarray( ), void sort(), void mix(Combine, Combine) and void display( ). Also define the main function to create an object and call the methods accordingly to enable the task. [10] Question 9. Design a class VowelWord to accept a sentence and calculate the frequency of words that begin with a vowel. The words in the input string are separated by a single blank space and terminated by a full stop. The description of the class is given below: Class Name : VowelWord Data members str : to store a sentence freq : to store the frequency of words beginning with a vowel. Member functions VowelWord() : constructor to initialize data members to legal initial values. voidreadstr() : to accept a sentence. voidfreq_vowel( ) : counts the frequency of the words beginning with a vowel. void display() : to display the original string and the frequency of the words that begin with a vowel.

Specify the class VowelWord giving details of the constructor( ), void readstr(), void freq_vowel() and void display(). Also defing the main function to create an object and call the methods accordingly to enable the task. [10] Question 10. A happy number is a number in which the eventual sum of the square of the digits of the number is equal to 1. Example :

28 = (2)2 + ( 8 )2 = 4 + 64 = 68 68 = (6)2 + ( 8)2 = 36 + 64 = 100 100 = ( 1 )2 + ( 0 )2 + ( 0 )2 = 1 + 0 + 0 = 1

Hence 28 is a happy number. Example :

12 = (1)2 + (2)2 = 1 + 4 = 5 Hence 12 is not a happy number. Design a class Happy to check if a given number is a happy number. Some of the members of the class are given below:

Page 30: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Class Name : Happy Data Members n : stores the number Member functions: Happy( ) : constructor to assign 0 to n voidgetnum(intnn) : to assign the parameter value to the number n = nn intsum_sq_digits(int x) : returns the sum of the square of the digits of the number x, using the recursive technique. voidishappy() : checks if the given number is a happy by calling the functionsum_sq_digits(int) and displays an appropriate message. Specify the class Happy giving details of the constructor( ), void getnum( int), intsum_sq_digits(int) and void ishappy(). Also define a main function to create an object and call the methods to check for a happy number.

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 suing pseudo codes.

(Flowcharts are not required) The programs must be written in Java.

The algorithm must be written in general standard form wherever required. Question 11. Link is an entity which can hold a maximum of 100 integers. Link enables the user to add elements from the rear end and remove integers from the front end of the entity. Define a class Link with the following details: Class Name : Link Data members lnk[] : entity to hold the integer elements. max : stores the maximum capacity of the entity. begin : to point to the index of the front end. end : to point to the index of the rear end. Member functions Link(int mm) : constructor to initialize max=mm, begin=0, end=0. voidaddlink(int v) : to add an element from the rear index if possible otherwise display the message “ OUT OF SIZE “. intdellink() : to remove and return an element from the front index, if possible otherwise display the message “ EMPTY…” and return -99. void display() : displays the elements of the entity.

(a) Specify the class Link giving details of the constructor(int ), void addlink(int ), intdellink() and void display(). THE MAIN FUNCTION AND ALGORITHM NEED NOT BE WRITTEN. [9]

(b) What type of data structure is the above entity? [1]

Page 31: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 12. A super class Detail has been defined to store the details of a customer. Define a sub class Bill to compute the monthly telephone charge of the customer as per the chart given below: NUMBER OF CALLS RATE 1- 100 Only rental charge 101-200 60 paisa per call + rental charge 201-300 80 paisa per call + rental charge Above 300 1 rupee per call + rental charge The details of both the classes are given below: Class Name : Detail Data members name : to store the name of the customer. address : to store the address of the customer. telno : to store the phone number of the customer. rent : to store the monthly rental charge Member functions: Detail(..) : parameterized constructor to assign values to data members. void show() : to display the detail of the customer. Class Name : Bill Data members n : to store the number of calls. amt : to store the amount to be paid by the customer. Member functions: Bill(..) : parameterized constructor to assign values to data

Members of both classes and to initialize amt = 0.0. voidcal() : calculates the monthly telephone charge as per the charge given above. void show() : to display the detail of the customer and amount to be paid. Specify the class Detail giving details of the constructor( ) and void show(). Uisng the concept of inheritance, specify the class Bill giving details of the constructor( ), void cal() and void show(). THE MAIN FUNCTION AND ALGORITHM NEED NOT BE WRITTEN. [10] Question 13.

(a) A linked list is formed from the objects of the class, class node {

int p; String n; node next;

} Write an algorithm or a method to search for a name and display the contents of the node. The method declaration is given below: void search(node start, String b) [4]

Page 32: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(b) Answer the following from the diagram of the binary tree given below:

i) External nodes of the tree. [1] ii) Parent node of D. [1] iii) Inorder traversal of the tree. [1] iv) Right subtree of node B. [1]

Page 33: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2013

Part I Answer all questions.

While answering questions to this part, indicate briefly your working and reasoning, wherever required.

Question 1. (a) State the principle of duality. Write the dual of:

(P+Q’).R.1=P.R+Q’.R [2] (b) b) Minimize the expression using Boolean laws:

F= (A+B’).(B+CD)’ [2] (c) Convert the following cardinal form of expression into its canonical form :

F(P,Q,R)= π(1,3) [2] (d) Using a truth table verify:

(~P→Q) ^P = ( P^~Q) ˅(P ^Q) [2] (e) If A=1 and B=0, then find :

i) (A’+1).B ii) (A+B’)’ [2]

Question 2.

(a) Differentiate between throw and throws with respect to exception handling. [2] (b) Convert the following infix notation to its postfix form:

E*(F / (G-H) * I) + J [2] (c) Write the algorithm for push operation (to add elements ) in an array based stack. [2] (d) Name the file stream classes to :

i) Write data to a file in binary form. ii) Read data from a file in text form. [2]

(e) A square matrix M[][] of size 10 is stored in the memory with each element requiring 4 bytes of storage. If the base address at M[0][0] is 1840, determine the address at M[4][8] when the matrix is stored in row major wise. [2]

Question 3.

(a) The following function Recur() is a part of some class. What will be the output of the function Recur() when the value of n is equal to 10. Show the dry run/working. public void Recur(int n) { if(n>1) {

System.out.print(n+" "); if(n%2!=0) { n=3*n+1; System.out.print(n+" "); } Recur(n/2);

} }

Page 34: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(b) The following function is a part of some class. Assume n is a positive integer. Answer the given questions along with dry run / working. int unknown(int n) {

int i,k; if(n%2==0) {

i=n/2; k=1;

} else {

k=n; n--; i=n/2;

} while(i>0) {

k=k*i*n; i--; n--;

} return k;

}

Part II 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,2,4,5,8,9,10,12,13) i) Reduce the above expression by using 4-variable K-map, showing the various groups (i.e. octal, quads and pairs). [4] ii) Draw the logic gate diagram of 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) = Π(0,1,3,5,7,8,9,10,11,14,15) i) Reduce the above expression by using 4-variable K-map, showing the various groups (i.e. octals, quads and pairs). [4] ii) Draw the logic gate diagram of the reduced expression. Assume that the variables and their complements are available as inputs. [1]

Question 5. A Football Association coach analyses the criteria for a win/draw of his team depending on the following conditions.

• If the Centre and forward players perform well but Defenders do not perform well. OR

• If Goal keeper and Defenders perform well but the Centre players do not perform well. OR

• If all the players perform well.

Page 35: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

The inputs are: INPUTS C Centre players perform well D Defenders perform well F Forward players perform well G Goalkeeper performs well (In all of the above cases 1 indicates yes and 0 indicates no) Output: X - Denotes the win/draw criteria [ 1 indicates win/draw and 0 indicates defeat in all cases.]

(a) Draw the truth table for the inputs and outputs given above and write the POS expression for X(C,D,F,G). [5]

(b) Reduce X(C,D,F,G) using Karnaugh’s map. Draw the logic gat diagram for the reduced POS expression for X(C,D,F,G) 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. (a) In the following truth table x and y are inputs and B and D are outputs: [3]

INPUT OUTPUT

X Y B D 0 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0

Answer the following questions: i) Write the SOP expression for D. ii) Write the POS expression for B. iii) Draw the logic diagram for the SOP expression derived for D, using only NAND gates.

(b) Using a truth table, verify if the following proposition is valid or invalid: [3] (A→B) ^ (B→C) = (A→C)

(c) From the logic circuit diagram given below, name the outputs (1), (2) and (3). Finally derive the Boolean expression and simplify it to show that it represents a logic gate. Name and draw the logic gate. [4]

Page 36: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 7. (a) What are decoders? How are they different from encoders? [2] (b) Draw the truth table and a logic gate diagram for a 2 to 4 decoder and briefly explain its working.

[4] (c) c) A combinational logic circuit with three inputs P, Q, R produce output 1 if and only if an odd

number of 0’s are input. (i) Draw its truth table. (ii) Derive a canonical SOP expression for the above truth table. (iii) Find the complement of the above derived expression using De Morgan’s theorem and

verify if it is equivalent to its POS expression. [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. An emirp number is a number which is prime backwards and forwards. Example: 13 and 31 are both prime numbers. Thus 13 is an emirp number. Design a class Emirp to check if a given number is Emirp number or nt. Some of the members of the class are given below: Class Name : Emirp Data Members n : stores the number rev : stores the reverse of the number f : stores the divisor Member functions Emirp(int nn) : to assign n=nn, rev=0, and f=2 int isprime(int x) : check if the number is prime using the recursive technique and return 1 if prime otherwise return 0. void isEmirp() : reverse the given number and check if both the original number and the reverse number are prime, by invoking the function isprime(int) and display the result with an appropriate message. Specify the class Emirp giving details of the constructor(int), int isprime(int) and void isEmirp(). Define the main function to create an object and call the methods to check for Emirp number. [10]

Question 9. Design a class Exchange to accept a sentence and interchange the first alphabet with the last alphabet for each word in the sentence, with single letter word remaining unchanged. The words in the input are separated by a single blank space and terminated by a full stop. Example: Input: It is a warm day.

Ouput: tI si a marw yad Some of the data members and member functions are given below: Class Name : Exchange Data members sent : stores the sentence rev : to store the new sentence size : stores the length of the sentence

Page 37: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Member functions Exchange() : default constructor void readsentence() : to accept the sentence void exfirstlast() : extract each word and interchange the first and last alphabet of the word and form a new sentence. void display() : display the original sentence along with the new changed sentence. Specify the class Exchange giving details of the constructor(), void readsentence(), void exfirstlast() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task. [10] Question 10. A class Matrix contains a two dimensional integer array of order [ m x n ]. The maximum value possible for both m and n is 25. Design a class Matrix to find the difference of the two matrices. The details of the members of the class are given below: Class name : Matrix Data members arr[][] : stores the matrix element m : integer to store the number of rows n : integer to store the number of columns Member functions: Matrix(int mm, int nn) : to initialize the size of the matrix m=mm and n=nn void fillarray() : to enter the elements of the matrix Matrix SubMat(Matrix A) : subtract the current object from the matrix of parameterized object and return the resulting object. void display() : display the matrix elements. Specify the class Matrix giving details of the constructor(int,int), void fillarray(),Matrix SubMat(Matrix) and void display(). 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 Perimeter has been defined to calculate the perimeter of a parallelogram. Define a sub class Area to compute the area of the parallelogram by using the required data members of the super class. The details are given below: Class name : Perimeter Data Members a : to store the length in decimal b : to store the breadth in decimal

Page 38: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Member functions: Perimeter(…) : parameterized constructor to assign values to data Members double Calculate() : calculate and return the perimeter of a parallelogram as 2 *(length +breadth) void show() : to display the data members along with the perimeter of the parallelogram. Class name : Area Data Members h : to store the height in decimal b : to store the area of the parallologram Member functions: Area(…) : parameterized constructor to assign values to data Members of both classes. void doarea() : computes the area( breadth * height). void show() : to display the data members of both the classes along with the area and perimeter of the parallelogram. Specify the class Perimeter giving details of the constructor(…), double Calculate() and void show(). Using the concept of inheritance, specify the class Area giving details of he constructor(…), void doarea() and void show(). The main function and algorithm need not be written. [10] Question 12. A doubly queue is a linear data structure which enables the user to add and remove integers from either ends, i.e. from front or rear. Define a class Dequeue with the following details: Class name : Dequeue Data members arr[] : array to hold upto 100 integer elements lim : stores the limit of the dequeue front : to point to the index of front end rear : to point to the index of rear end Member function Dequeue(int l) : constructor to initialise the data members lim=l;

front=rear=0 void addfront(int val) : to add integer from the front if possible else display the

message (“Overflow from front”) void addrear(int val) : to add integer from the rear if possible else display the

message (“Overflow from rear”) int popfront() : returns element from front, if possible otherwise

returns -9999. int poprear() : returns element from rear, if possible otherwise

returns -9999. Specify class Dequeue giving details of the constructor(), void addfront(int), void addrear(int), int popfront(), and int poprear(). The main function and algorithm need not be written. [10]

Page 39: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 13. (a) A linked list is formed from the objects of the class,

class Node {

int item; Node next;

} Write an algorithm or a method to count the numbr of nodes in the linked list. The method declaration is given below: int count(Node ptr_start) [4]

(b) What is the worst case complexity f the following code segment: i) for(int p=0; p<N;p++) {

for(int q=0;q<M;q++) {

Sequence of statements }

} for(int r=0;r<X;r++) {

Sequence of statements } ii) How would the complexity change if all the loops went up to the same limit N? [2]

(c) Answer the following questions from the diagram of the binary tree given below: i) Preorder traversal of tree ii) Children of Node E iii) Left subtree of Node D iv) Height of the tree when the root of the tree is at level 0. [4]

Page 40: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2014

PART I

Answer all questions. While answering questions in this Part, indicate briefly your working and reasoning,

wherever required. Question 1

(a) From the logic circuit diagram given below, find the output 'F' and simplify it. Also, state the law represented by the logic diagram. [2]

(b) Write the truth table for a 2-input conjunction and disjunction in a proposition. [2] (c) Find the complement of XY'Z + XY + YZ' [2] (d) Convert the following expression into its canonical POS form : [2]

F(A,B) = (A +.B) . A' . (e) Minimize the following Boolean expression using the Karnaugh map: [2]

F(A,B,C) = �̅� B𝐶̅+ �̅�BC+ AB𝐶̅+ ABC] Question 2

(a) State two advantages of using the concept of inheritance in Java. [2] (b) An array AR [ -4 .... 6, -2 .... 12 ] , stores elements in Row Major Wise, with the address

AR[2][3] as 4142 . . If each element requires 2 bytes of storage, find the Base address. [2] (c) State the sequence of traversing a binary tree in: · [2]

(i) preorder (ii) postorder

(d) Convert the· following infix expression into its postfix form: [2] (A/B+C)*(D/ (E-F))

(e) State the difference between the functions int nextlnt() and boolean hasNextlnt( ). [2]

Question 3

(a) The following functions are part of some class: void fun 1 (chars[ ],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; funl(s,x+ I); }

} void fun2(String n) { char c[ ]=new char[n.length( )]; for( int i=O;i<c.length; i++) c[i]=n.charAt(i); funl(c,O); }

Page 41: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(i) What will be the output of funl() when the value Qf s[ ]={'J','U','N','E'} and x=l? [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 funl() 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 rep]aced by a statement/expression so that the function works properly:

void selectsort(int []a) {

int I,J,t,m1n,m1npos; for( i=O;i<?l ?;i++) {

min==a[i]; minpos = i;

for(j=?2?;j <a.length;j++) {

if(min>au]) { ?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 t·he expressiop 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 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. 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]

Page 42: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(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. octal, quads and pairs). [4] (ii) Draw the logic gate diagram tor the reduced expression. Assume that the variables and their

complements are available as inputs. [1]

Question 5 A school intends to select candidates 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 l1eight is between 5 ft. and 6 ft. and weight is

between 50 kg. and 60 kg. OR

• The candidate is from the senior school and has height between 5 ft. and 6 ft., but the weight is not between 50 kg. and 60 kg.

The inputs are: INPUTS

S Student is from the Senior School W Weight is between 50 kg. and 60 kg. H Height is between 5 ft. and 6 ft. A Taken part in Inter-School Athletic Meet earlier

(In all of the above cases 1 indicates yes and 0 indicates no) Output: X - Denotes the selection criteria [l indicates selected and 0 indicates rejected in all cases.]

(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. [5] 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.

Question 6 ·

(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]

(c) Reduce the following expression using Boolean laws: [3] F(A, B, C, D) =(A' + C) (A'+ C') (A'+ B+ C'D)

Page 43: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 7

(a) Differentiate between XNOR and XOR gates. Draw the truth table and logic diagrams of 3 input XNOR gate. [4]

(b) Differentiate between a proposition and . wff. [2] (c) Define Half Adder. Construct the truth table and a logic diagram of a Half Adder. [4]

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 n?nemonic names and comments in the program.

(Flowcharts and Algorithms are not required.) The programs must be written in Java.

Question 8 A class Mixer has been defined to merge two sorted integer arrays in ascending order. Some of the members of the class are given below: Class name : Mixer Data members/instance variables : int arr[ ] : to store the elements of an array int n : to store the size of the array Member functions: Mixer(int nn) : constructor to assign n=nn void accept( ) : to accept the elements of the array in ascending

order without any duplicates Mixer mix(Mixer A) : to merge the current object array elements with the 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. Question 9 A class SeriesSum is designed to calculate the sum of the following series:

Sum = 𝑥2

1!+ 𝑥

4

3!+ 𝑥

6

5!+ ⋯ 𝑥𝑛

(𝑛−1)!

Some of the members of the class are given below: Class name : SeriesSum Data members/instance variables: 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(int xx, int nn) : constructor to assign x=xx and n==nn double findfact(int m) : to return the factorial of m using recursive technique. double findpower(int x, int y) : to return x raised to the power of y using recursive technique. void calculate( ) : to calculate the sum of the series by invoking the recursive

functions respectively void display( ) : to display the sum of the series

Page 44: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(a) Specify the class SeriesSum, giving details of the constructor(int, int), double findfact(int), double findpower(int, int), void calculate( ) and void display( ). Define the main( ) function to create an object and call the functions accordingly to enable the task. [8]

(b) State the two differences between iteration and recursion. [2] • 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: Class name : FiboString Data members/instance variables : x : to store the first string y : to store the second string z : to store the concatenation of the previous two strings n : to store the number of terms Member functions/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('+' ie 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 ''bah'' 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 two questions Each program should be written in such a way that it clearly depicts the logic of the problem stepwise.

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 ir1 general /

standard form, wherever required / specified. (Flowcharts are not required.)

Question 11 A super class Stock has beer1 defined to store the details of the stock of a retail sto14e. Define a subclass Purchase to store the details of the items purchased with the ne'N rate and updates the stock. Some of the members of the classes are given below: [10] Class name : Stock Data members/instance variables : item : to store the na.me 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 i11 stock Member functions: Stock ( ... ) : parameterized constructor to assign va]ues to the data, members void display() : to display the stock details

Page 45: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Class name : Purchase Data members/instance variables : pqty : to store the purchased quantity prate : to store the unit price of the p·urchased item Memlier functions I methods Purchase( ... ) : parameterized constructor to assign values to the data members of both classes void update ( ) : to update stock by addi11g the p:revious quantity by the purchased quantity and replace tl1e rate of the item if there is a difterence in the purchase rate. Also update the current stock value as: (quantity * u11it price) void display() : to display the stock details before and after updation Specify the class Stock, giving det·ails 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. 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. [10] Define a class Array_to_Stack with the following details: Class name : Array_ to_ Stack Data members/instance variables : m[] : to store the marks st[] : to store the stack elements cap : maximum capacity of the array and stack top : to point the index of the topmost element of the stack Methods/Member functions: Array_ to_ Stack (int n) : parameterized constructor to initialize cap = n and top= -1 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( ·) void pushmarks(int v) : to push the marks into the stack at top location if possible, otherwise, display ''not possible'' 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(). The main function and the algorithm need not be written .

Page 46: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 13 (a) A linked list is formed from the objects of the class: [4]

class Node {

int number; Node nextNode;

} Write an Algorithm OR a 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)

(b) Define the terms complexity and big 'O' notation. [2]

(c) Answer the following from the diagram of the Binary Tree given below:

(i) Root of the tree. [1] (ii) Left subtree [1] (iii) Inorder traversal of the tree [1] (iv) Size of the tree. [1]

Page 47: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2015

PART I

Answer all questions. While answering questions in this Part, indicate briefly your working and reasoning,

wherever required. Question 1

(a) Simplify: (𝐴 + 𝐶). (𝐴 + 𝐴.𝐷) + 𝐴.𝐶 + 𝐶 [2] (b) Draw a logic circuit for (A + B).(C + D).C [2] (c) Verify the following proposition with the help of a truth table: [2]

𝑃 𝑉 (~𝑃 Λ 𝑄) = 𝑃 𝑉 𝑄 (d) State De Morgan’s law and verify it, using a truth table. [2] (e) Answer the questions related to the circuit given below: [2]

(i) Give the output if, X=1 and Y=0 (ii) Name the basic gate represented by the above diagram.

Question 2

(a) Define computational complexity. Calculate the complexity using Big ‘O’ notation for the following code segment: [2] for(int k=0;k<n;k++) s+=k;

(b) Convert the following infix notation into postfix form: [2] X + (Y – Z) + (W + E) * F) / J

(c) Differentiate between this keyword and super keyword. [2] (d) The array D[-2…10] [3…8] contains double type elements. If the base address is 4110, find the

address of D[4][5], when the array is stored in Column Major Wise. [2] (e) State any two characteristics of a Binary tree. [2]

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/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] (ii) What will be returned by someFun(84,2)? [2] (iii) State in one line what does the function someFun( ) do, apart from recursion? [1]

Page 48: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(b) The following is a function of some class which checks if a positive integer is an Armstrong number by returning true or false. (A number is said to be Armstrong if the sum of the cubes of all its digits is equal to the original number.) The function does not use modulus (%) operator to extract digit. 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. boolean ArmstrongNum( 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 return false; } (i) What is the statement or expression at ?1? [1] (ii) What is the statement or expression at ?2? [1] (iii) What is the statement or expression at ?3? [1] (iv) What is the statement or expression at ?4? [1] (v) What is the statement or expression at ?5? [1]

PART - II 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,7,8,9,10,11). (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]

(b) Given the Boolean function: 𝑃(𝐴,𝐵,𝐶,𝐷) = 𝐴𝐵𝐶′𝐷′ + 𝐴′𝐵𝐶′𝐷′ + 𝐴′𝐵𝐶′𝐷 + 𝐴𝐵𝐶′𝐷 + 𝐴′𝐵𝐶𝐷 + 𝐴𝐵𝐶𝐷

(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]

Page 49: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 5 A person is allowed to travel in a reserved coach of the train, if he/she satisfies the criteria given below:

• The person has a valid reservation ticket and a valid ID proof. OR

• The person does not have a valid reservation ticket, but holds a valid pass issued by the Railway department with a valid ID proof.

OR • The person is a disabled person and holds a valid pass issued by the Railway department along

with a valid ID proof. The inputs are: INPUTS

R The person has a valid reservation ticket P The person holds a valid pass issued by the Railway department. D The person has a valid ID proof. H The person is a disabled person

(In all the above cases 1 indicates yes and 0 indicates no).

Output: T – Denotes allowed to travel (1 indicates yes and 0 indicates no in all the cases)

(a) Draw the truth table for the inputs and outputs given above and write the POS expression for T(R, P, D, H). [5]

(b) Reduce T(R,P,D,H) using Karnaugh map. [5]

Draw the logic gate diagram for the reduced POS expression for T(R, P, D, H) using only NOR gates. You may use gates with two or more inputs. Assume that the variable and their complements are available as inputs.

Question 6 ·

(a) Draw the truth table and logic gate diagram for an Octal to Binary encoder. [4] (b) What is a Multiplexer? State an application of a Multiplexer. Also, draw the logic diagram of a

4 : 1 Multiplexer. [4] (c) Verify the following expression using Boolean laws. Also, mention the law used at each step of

simplification. [2] 𝑋.𝑌.𝑍 + 𝑋.𝑌′.𝑍 + 𝑋.𝑌.𝑍′ = 𝑋. (𝑌 + 𝑍)

Question 7

(a) Derive a Boolean expression for the logic circuit given below and reduce the derived expression, using Boolean laws: [3]

(b) What are universal gates? Construct a logic circuit using NAND gates only for the expression: A . (B + C) [3]

(c) Define Half Adders. Draw the circuit diagram and the truth table for a Half Adder. [4]

Page 50: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

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 8 A class Admission contains the admission numbers of 100 students. Some of the data members / member functions are given below: [10] Class name : Admission Data member/Instance variable : Adno[] : integer array to store admission numbers Member functions/methods : Admission( ) : constructor to initialize the array elements void fillArray( ) : to accept the elements of the array in ascending order int binSearch(int 1, int u, int v) : to search for a particular admission number (v) using binary search and recursive technique and returns 1 if found otherwise returns – 1. Specify the class Admission giving details of the constructor, void fillArray( ) and int binSearch(int, int, int). Define the main( ) function to create an object and call the functions accordingly to enable the task. Question 9 A class Merger concatenates two positive integers that are greater than 0 and produces a new merged integer. [10]

Example: If the first number is 23 and the second is 764, then the concatenated number will be 23764.

Some of the members of the class are given below: Class name : Merger Date members/instance variables : n1 : long integer to store first number n2 : long integer to store second number mergNum : long integer to store the merged number Member functions: Merger( ) : constructor to initialize the data members void readNum( ) : to accept the values of the data members n1 and n2 void JoinNum( ) : to concatenate the numbers n1 and n2 and store it in mergeNum void show( ) : to display the original numbers and the merged number with appropriate messages Specify the class Merger, giving the details of the constructor, void readNum( ), void JoinNum( ) and void show( ). Define the main( ) function to create an object and call the functions accordingly to enable the task.

Page 51: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 10 A class TheString accepts a string of a maximum of 100 characters with only one blank space between the words. [10] Some of the members of the class are as follows: Class name : TheString Data member/instance variable : str : to store a string len : integer to store the length of the string wordcount : integer to store the number of words cons : integer to store the number of consonants Member functions/methods: TheString( ) : default constructor to initialize the data membrs TheString(String ds) : parameterized constructor to assign str=ds void countFreq( ) : to count the number of words and the number of consonants and store them in wordcount and cons respectively void Display( ) : to display the original string, along with the number of words and the number of consonants Specify the class TheString giving the details of the constructors, void countFreq( ) and void Display( ). Define the main( ) function to create an object and call the functions accordingly to enable the task.

SECTION-C Answer any two questions

Each program should be written in such a way that it clearly depicts the logic of the problem stepwise. 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 ir1 general /

standard form, wherever required / specified. (Flowcharts are not required.)

Question 11 WordPile is an entity which can hold maximum of 20 characters. The restriction is that a character can be added or removed from one end only.

Some of the members of classes are given below:

Class name : WordPile Data members/instance variables : ch[ ] : character array to hold the character elements capacity : integer variable to store the maximum capacity top : to point to the index of the topmost element Methods/Member functions: WordPile( int cap) : constructor to initialize the data member capacity = cap, Top = -1 and create the WordPile void pushChar( char v) : adds the character to the top of WordPile if possible, otherwise output a message ‘WordPile is full” char popchar() : returns the deleted character from the top of the WordPile if possible, otherwise it returns ‘\\’

Page 52: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

(a) Specify the class WordPile giving the details of the constructor, void pushChar(char) and char popChar( ). [8] The main function and algorithm need not be written.

(b) What is the name of the entity described above and state one of its applications. [2]

Question 12 A line on a plane can be represented by coordinates of the two-points p1 and p2 as p1(x1, y1) and p2(x2, y2). [10] A super class Plane is defined to represent a line and a sub class Circle to find the length of the radius and the area of circle by using the required data members of super class. Some of the members of both the classes are given below: Class name : Plane Data members/instance variables : x1 : to store the x-coordinate of the first end point y1 : to store the y-coordinate of the first end point Member functions/methods: Plane( int nd, int ny ) : parameterized constructor to assign the data members X1 = nx and y1 = ny void Show( ) : to display the coordinates Class name : Circle Data members/instance variables : x2 : to store the x-coordinate of the second end point y2 : to store the y-coordinate of the second end point radius : double variable to store the radius of the circle area : double variable to store the area of the circle Member functions / methods Circle(…) : parameterized constructor to assign values to data Members of both the classes void findRadius( ) : to calculate the length of radius using the formula: (�(𝑥2 − 𝑥1)2 + (𝑦2 − 𝑦1)2 / 2 Assuming that x1, x2, y1, y2 are the coordinates of the two Ends of the diameter of a circle void findArea( ) : to find the area of circle using formula :𝜋𝑟2. The value of pie (𝜋) is 22/7 or 3.14 void Show( ) : to display both the coordinates along with the length of the radius and area of the circle Specify the class Plane giving details of the constructor and void Show( ). Using the concept of inheritance, specify the class Circle giving details of the constructor, void findRadius( ), void findArea( ) and void Show( ). The main function and algorithm need not be written.

Page 53: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I

Question 13

(a) A linked list is formed from the objects of the class: [4] class Nodes { int num; Nodes next; }

Write an Algorithm OR a Method to print the sum of nodes that contains only odd integers of an existing linked list.

The method declaration is as follows: void NodesCount( Nodes starPtr )

(b) (i) Give the meaning of the following common expression in Big O notation: [1] O(N) O(N2)

(ii) List any two cases to analyse algorithm complexities. [1]

(c) Answer the following questions from the diagram of a Binary Tree given below: (i) Name the leaf nodes of the right sub-tree. [1] (ii) Write postorder traversal of the left sub-tree of node B including itself. [1] (iii) State the level number of nodes R and M when the root is at level 0. [1] (iv) Name the internal nodes of the tree. [1]

Page 54: COMPUTER SCIENCE PAPER 1 THEORY – YEAR 2008 PART I