Page 671 - Computer science 868 Class 12
P. 671
Question 11. [3 + 2]
(a) Answer the following from the binary tree given below:
A
B J
C F K
D G L
E H
(i) Write the internal nodes of left sub tree
(ii) What is the height and depth of node L
(iii) Write the in order traversal of the above tree
Ans. (i) Internal nodes of left sub tree B,C,F,D,G
(ii) Height of node L = and Depth = 4
(iii) C,D,E,B,G,H,F,A,K,L,1
(b) A linked list is formed from the objects of the class as given below:
class Link
{ String name;
Node next; }
Write an Algorithm OR a Method to count and return the frequency of names starting with ‘A’ or ‘a’ in the linked list using
method: int countA( Link begin )
Ans. Algorithm
Step1: Start
Step 2: Create pointer ptr and initialize it to begin
Step 3: Initialise c to 0
Step 4: Repeat steps 5 to 6 until ptr=null
Step 5: If ptr.name.charAt(0) = ‘A’ or ‘a’ then increase c by 1
Step 6: Move pointer to next node
Step 7: return c
Step 8: Stop
Java code:
int countA(Link begin)
{ Link ptr=new Link(begin);
c=0;
while(ptr!=null)
{ if(ptr.name.charAt(0)=='A' || ptr.name.charAt(0)=='a')
{ c=c+1; }
ptr=ptr.next;
}
return c;
}
669
Sample Paper 669

