Computer Science Paper 1 (Theory) : B) State How A Binary Tree Is A Recursive Data Structure

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Computer Science Paper 1 (Theory) 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: !"#!$)%" !#)!$ &lso state the law. b) 'iven, (" , #, $)% " )! #)). "# ! $)) write the function in canonical product of su* for*. c) +raw the truth table and logic circuit for a , - input ./0 gate. d) (ind the co*ple*ent of the following expression: ) ! #) e) 1f " 2 #) then write its: i) 3onverse ii) 3ontra positive [ 2 x 5 = 10 Question 2. a) +ifferentiate between the keyword extends and i*ple*ents.
b) State how a binary tree is a recursive data structure.

c) & *atrix 45167587 is stored in the *e*ory with each ele*ent requiring , bytes of storage. 1f the 4ase address at 45x7517 is 161, and the address 4587597 is 16:6, deter*ine the value x where the *atrix is stored in colu*n *a;or wise. d) 3onvert the following infix notation into its postfix for*: & ! "" 4! 3) ! " + ! <) = ( ) > ' e) What is a constructor? @tate one difference between a constructor and any other *e*ber function of a class. [ 2 x 5 = 10 Question !. a) Ahe following function is a part of so*e class which co*putes and sorts an array arr57 in ascending order using the bubble sort technique. Ahere are so*e places in the code *arked by ?1?, ?,?, ?9?, ?B?, ?C? which *ust be replaced by a state*ent> expression so that the function works properly:

class Arial D void bubblesort"intarr57) D inti,;,k,t*pE for"i%6E?1?Ei!!) D for";%6E?,?E;!!) D if"arr5;7F?9?) D t*p%arr5;7E ?B?%arr5;!17E arr5;!17%?C?E G G G G i) ii) iii) iv) v) What is the expression or state*ent at ?1? What is the expression or state*ent at ?,? What is the expression or state*ent at ?9? What is the expression or state*ent at ?B? What is the expression or state*ent at ?C? [1x5=5 b) Ahe following function witty") is a part of so*e class. What will be the output of the function witty") when the value of n is H@31<.3<I and the value of p is C. @how the dry run> working: class Arial1 D public void witty"@tring n, int p) D if"pJ6) @yste*.out.println"KK)E else D @yste*.out.println"n.char&t"p)!K.K)E witty"n,pL1)E @yste*.out.print"n.char&t"p))E G G G [5

Part II "ns#er se$en %uestions in this part& choosin' three %uestions (rom Section "& t#o (rom Section ) an* t#o (rom Section C. Section " "ns#er any three %uestions Question +. a) 'iven the 4oolean function ("&,4,3,+)% M"B,:,8,16,11,1,,1B,1C) i) 0educe the above expression by using B variable NL *ap, showing the various groups " i.e. octals, quads and pairs). ii) +raw the logic gate diagra* of the reduced expression. &ssu*e that the variables and their co*ple*ents are available as inputs. [+,1=5 b) 'iven the 4oolean function ("O,P,0,@)% Q"6,C,8,R,16,1,,19,1B,1C) i) 0educe the above expression by using B variable NL *ap, showing the various groups " i.e. octals, quads and pairs). ii) +raw the logic gate diagra* of the reduced expression. &ssu*e that the variables and their co*ple*ents are available as inputs. [+,1=5 Question 5. Ahe principal of a school intends to select students for ad*ission to 3lass 1 on the following criteria: @tudent is of the sa*e school and has passed the 3lass 4oard <xa*ination with *ore than :6S *arks. /0 @tudent is of the sa*e school, has passed the 3lass 4oard <xa*ination with less than :6S *arks but has taken active part in coLcurricular activities. /0 @tudent is not fro* the sa*e school but has either passed the 3lass board <xa*ination with *ore than :6S *arks or has participated in @ports at the national level. Ahe inputs are : 1.OUA@ @ O 3 A

@tudent is of the sa*e school Tas passed the 3lass 4oard <xa*ination with *ore than :6S *arks. Tas taken active part in coLcurricular activities. Tas participated in sports at the .ational Uevel.

/utput :L - +enotes ad*ission status 5 1 indicates granted and 6 indicates refused in all the cases.7 a) +raw the truth table for the inputs and outputs given above and write the @/O expression. b) 0educe "@,O,3,A) using Narnaugh)s *ap. +raw the logic gate diagra* for the reduced @/O expression for "@,O,3,A) using &.+ and /0 gate. #ou *ay use gates with two or *ore inputs. &ssu*e that the variable and their co*ple*ents are available as inputs. [ 5 x 2 = 10 9

Question -. a) Verify algebraically if, )#)$) ! )#)$ ! )#$ ! )#$) ! #)$) ! #)$ % ) ! #) [2 b) 0epresent the 4oolean expression ! #$) with the help of ./0 gates only. [2 c) +efine the ter*s contingency, contradiction and tautology. [! d) 3onsider the following truth table where & and 4 are two inputs and is the output: & 6 6 1 1 4 6 1 6 1

6 1 1 6

i) ii)

.a*e and draw the logic gate for the given truth table. Write the O/@ of "&,4)

[2 [1

Question .. a) +efine *ultiplexer and state one of its uses. +raw the logic gate diagra* for B:1Wultiplexer. [+ b) @tate how a half adder is different fro* a full adder. &lso give their respective uses. [! c) Wini*iXe the following expression using 4oolean laws: P"P)!O).0."P!0) [! &lso draw the logic gate for the reduced 4oolean expression.

Section ) &nswer any , questions. <ach progra* should be written in such a way that it clearly depicts the logic of the proble*. Ahis can be achieved by using *ne*onic na*es and co**ents in the progra*. Question /. & class 3o*bine contains an array of integers which co*bines two arrays into a single array including the duplicate ele*ents, if any, and sorts the co*bined array. @o*e of the *e*bers of the class are given below: C0ass 1ame 2ata mem3ers co*5 7 siXe 4em3er (unctions5metho*s 3o*bine"intnn) voidinputarray" ) void sort") void *ix"3o*bine &, 3o*bine 4) : : : : : : : 3o*bine integer array siXe of the array para*eteriXed constructor to assign siXe % nn to accept the array ele*ents sorts the ele*ents of co*bined array in ascending order using the selection sort technique. co*bines the para*eteriXed ob;ect arrays and stores the result in the current ob;ect array along with the duplicate ele*ents , if any. displays the array ele*ents.

void display" )

@pecify the class 3o*bine giving details of the constructor"int ), void inputarray" ), void sort"), void *ix"3o*bine, 3o*bine) and void display" ). &lso define the *ain function to create an ob;ect and call the *ethods accordingly to enable the task. [ 10 Question 6. +esign a class VowelWord to accept a sentence and calculate the frequency of words that begin with a vowel. Ahe words in the input string are separated by a single blank space and ter*inated by a full stop. Ahe description of the class is given below: C0ass 1ame 2ata mem3ers str freq 4em3er (unctions VowelWord") voidreadstr") voidfreqYvowel" ) void display") 7 : : 8o#e09or* to store a sentence to store the frequency of words beginning with a vowel. constructor to initialiXe data *e*bers to legal initial values. to accept a sentence. counts the frequency of the words beginning with a vowel. to display the original string and the frequency of the C

: : : :

words that begin with a vowel. @pecify the class VowelWord giving details of the constructor" ), void readstr"), void freqYvowel") and void display"). &lso defing the *ain function to create an ob;ect and call the *ethods accordingly to enable the task. [ 10 Question 10. & happy nu*ber is a nu*ber in which the eventual su* of the square of the digits of the nu*ber is equal to 1. <xa*ple : ,R :R 166 % ",), ! " R ), % B ! :B % :R % ":), ! " R), % 9: ! :B % 166 % " 1 ), ! " 6 ), ! " 6 ), % 1 ! 6 ! 6 % 1

Tence ,R is a happy nu*ber. <xa*ple : 1, % "1), ! ",), % 1 ! B % C Tence 1, is not a happy nu*ber. +esign a class Tappy to check if a given nu*ber is a happy nu*ber. @o*e of the *e*bers of the class are given below: C0ass 1ame 2ata 4em3ers n 4em3er (unctions7 Tappy" ) voidgetnu*"intnn) intsu*YsqYdigits"int x) voidishappy") 7 :appy

stores the nu*ber

: : : :

constructor to assign 6 to n to assign the para*eter value to the nu*ber n % nn returns the su* of the square of the digits of the nu*ber x, using the recursive technique. checks if the given nu*ber is a happy by calling the functionsu*YsqYdigits"int) and displays an appropriate *essage.

@pecify the class Tappy giving details of the constructor" ), void getnu*" int), intsu*YsqYdigits"int) and void ishappy"). &lso define a *ain function to create an ob;ect and call the *ethods to check for a happy nu*ber.

Section C "ns#er any 2 %uestions. <ach progra*>algorith* should be written in such a way that it clearly depicts the logic of the proble* step wise. Ahis can also be achieved by suing pseudo codes. "(lowcharts are not required) The pro'rams must 3e #ritten in ;a$a. The a0'orithm must 3e #ritten in 'enera0 stan*ar* (orm #here$er re%uire*.

Question 11. Uink is an entity which can hold a *axi*u* of 166 integers. Uink enables the user to add ele*ents fro* the rear end and re*ove integers fro* the front end of the entity. +efine a class Uink with the following details: C0ass 1ame 2ata mem3ers lnk57 *ax begin end 4em3er (unctions Uink"int **) voidaddlink"int v) intdellink") 7 : : : : <in= entity to hold the integer ele*ents. stores the *axi*u* capacity of the entity. to point to the index of the front end. to point to the index of the rear end.

: : :

void display")

constructor to initialiXe *ax%**, begin%6, end%6. to add an ele*ent fro* the rear index if possible otherwise display the *essage H /UA /( @1$< H. to re*ove and return an ele*ent fro* the front index, if possible otherwise display the *essage H <WOA#Z H and return L[[. displays the ele*ents of the entity.

a) @pecify the class Uink giving details of the constructor"int ), void addlink"int ), intdellink") and void display"). AT< W&1. (U.3A1/. &.+ &U'/01ATW .<<+ ./A 4< W01AA<.. [6 b) What type of data structure is the above entity? [1

Question 12. & super class +etail has been defined to store the details of a custo*er. +efine a sub class 4ill to co*pute the *onthly telephone charge of the custo*er as per the chart given below:

.UW4<0 /( 3&UU@ 1L 166 161L,66 ,61L966 &bove 966

0&A< /nly rental charge :6 paisa per call ! rental charge R6 paisa per call ! rental charge 1 rupee per call ! rental charge

Ahe details of both the classes are given below: C0ass 1ame 7 2ata mem3ers na*e : address : telno : rent : 4em3er (unctions7 +etail"..) void show") C0ass 1ame 2ata mem3ers n a*t 4em3er (unctions7 4ill"..) voidcal") void show")

2etai0 to store the na*e of the custo*er. to store the address of the custo*er. to store the phone nu*ber of the custo*er. to store the *onthly rental charge

: : 7 : :

para*eteriXed constructor to assign values to data *e*bers. to display the detail of the custo*er. )i00 to store the nu*ber of calls. to store the a*ount to be paid by the custo*er.

: : :

para*eteriXed constructor to assign values to data We*bers of both classes and to initialiXe a*t % 6.6. calculates the *onthly telephone charge as per the charge given above. to display the detail of the custo*er and a*ount to be paid.

@pecify the class +etail giving details of the constructor" ) and void show"). Uisng the concept of inheritance, specify the class 4ill giving details of the constructor" ), void cal") and void show"). AT< W&1. (U.3A1/. &.+ &U'/01ATW .<<+ ./A 4< W01AA<.. [ 10 R

Question 1!. a) & linked list is for*ed fro* the ob;ects of the class, class node D int pE @tring nE node nextE G Write an algorith* or a *ethod to search for a na*e and display the contents of the node. Ahe *ethod declaration is given below: void search"node start, @tring b) [+ b) &nswer the following fro* the diagra* of the binary tree given below:

i) ii) iii) iv)

<xternal nodes of the tree. Oarent node of +. 1norder traversal of the tree. 0ight subtree of node 4.

[1 [1 [1 [1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy