Prashnikaप्रश्निका

Data structures - ISC Class 12 Computer Science Questions with Answers, Page 2

87 past-paper questions on Data structures from ISC Class 12 Computer Science papers (2026-2017), newest first, in full. Questions 21-40 are on this page, 20 to a page. Tap "Show answer" under a question to see its answer.

Practise these questions with filters
2025 · 2 marks · ProgramOpen: A linked list is formed from the objects of class VotersList. The class…

Write the program described below.

A linked list is formed from the objects of class VotersList. The class structure is given below.
class VotersList
{
    int age;
    VotersList link;
}
Write an Algorithm OR a Method to count and return total number of nodes whose age >= 60. The method prototype is as follows: int countNodes(VotersList start)
Show answer

Answer

AI
int countNodes(VotersList start)
{
    if (start == null)
        return 0;
    else
    {
        if (start.age >= 60)
            return 1 + countNodes(start.link);
        else
            return countNodes(start.link);
    }
}
Explanation: The method recursively traverses the linked list node by node using the link reference. At each node, if age is 60 or more it adds 1 to the count returned by the recursive call on the rest of the list (start.link); otherwise it simply returns the count from the rest of the list. The base case (start == null) returns 0 when the end of the list is reached. Tested with a 4-node list of ages {65, 45, 70, 30}, the method correctly returns 2 (the nodes with age 65 and 70).
2025 · 1 mark · MCQOpen: For the given Binary Tree, which traversal order will arrange the elements in…

Choose the correct option.

For the given Binary Tree, which traversal order will arrange the elements in ascending order?
  • (a)Post order
  • (b)Pre order
  • (c)In order
  • (d)Postfix order
Figure for this question
Show answer

Answer

AI

Correct option: c

Answer: (c) In order. The given tree (root 4, left child 2, right subtree 7 with children 5 and 8, and 8's right child 9) is a binary search tree. An in-order traversal (left, root, right) of a BST always visits the nodes in ascending order: 2, 4, 5, 7, 8, 9.
2025 · 2 marks · ConversionOpen: Convert the following infix notation to postfix form. (A*B^C) + (D*E) where B^C…

Convert the following.

Convert the following infix notation to postfix form. (A*B^C) + (D*E) where B^C = $B^C$
Show answer

Answer

AI
$(A * B\text{^}C) + (D * E)$ Since ^ (exponentiation) has the highest precedence and is right-associative, evaluate B^C first: $B\ C\ \text{^}$ Then $A*(B\text{^}C) \to A\ B\ C\ \text{^}\ *$ $D*E \to D\ E\ *$ Combine both operands of the outer + : Postfix: $A\ B\ C\ \text{^}\ *\ D\ E\ *\ +$
2025 · 2 marks · ConversionOpen: Convert the following infix notation to prefix form.

Convert the following.

Convert the following infix notation to prefix form. $(A - B) / C * (D + E)$
Show answer

Answer

Official answer key
Infix: $(A-B)/C*(D+E)$ Step 1: $(A-B) \to {-}AB$ Step 2: $(A-B)/C \to {/}{-}ABC$ Step 3: $(D+E) \to {+}DE$ Step 4: Combine the two results with $*$: ${*}\ {/}{-}ABC\ {+}DE$ Prefix form: $*/-ABC+DE$
2025 · 5 marks · Case basedOpen: Recycle is an entity which can hold at the most 100 integers. The chain enables…

Answer the following on the class described.

Recycle is an entity which can hold at the most 100 integers. The chain enables the user to add and remove integers from both the ends i.e. front and rear. Define a class ReCycle with the following details: Class name : ReCycle Data members/instance variables: ele[ ] : the array to hold the integer elements cap : stores the maximum capacity of the array front : to point the index of the front rear : to point the index of the rear Methods / Member functions: ReCycle (int max) : constructor to initialize the data cap = max, front = rear = 0 and to create the integer array. void pushfront(int v) : to add integers from the front index if possible else display the message(“full from front”). int popfront( ) : to remove the return elements from front. If array is empty then return-999. void pushrear(int v) : to add integers from the front index if possible else display the message(“full from rear”). int poprear( ) : to remove and return elements from rear. If the array is empty then return-999.
(i)[4.0]
Specify the class ReCycle giving details of the functions void pushfront(int) and int poprear( ). Assume that the other functions have been defined. The main( ) function and algorithm need NOT be written.
(ii)[1.0]
Name the entity described above and state its principle.
Show answer

Answer (i)

Official answer key
void pushfront(int v)
{
    if (front != 0)
        ele[front--] = v;
    else
        System.out.println("full from front");
}

int poprear()
{
    if (front != rear)
        return ele[rear--];
    else
        return -999;
}
Explanation: This follows the same indexing scheme used by the already-defined pushrear()/popfront() methods of ReCycle. pushfront() stores the new value at the current front index and then decrements front (so ele[] fills from the front end downward), printing "full from front" if front has already reached 0 (no more room at that end). poprear() removes and returns the element at the current rear index and then decrements rear, unless front and rear have met (the structure is empty), in which case it returns -999.

Answer (ii)

Official answer key
The entity described is a Deque (Double Ended Queue). It works on a generalisation of the FIFO principle to both ends: insertion and deletion of elements are allowed from both the front and the rear of the structure, unlike a simple queue which allows insertion only at the rear and deletion only at the front.
2025 · 2 marks · ProgramOpen: A linked list is formed from the objects of the class Node. The class structure…

Write the program described below.

A linked list is formed from the objects of the class Node. The class structure of the Node is given below:
class Node 
{ 
    int n; 
    Node link; 
} 
Write an Algorithm OR a Method to search for a number from an existing linked list. The method declaration is as follows: void FindNode( Node str, int b )
Show answer

Answer

Official answer key
Algorithm: Step 1: Start. Set a temporary pointer temp = str (the head of the list). Step 2: Repeat step 3 while temp is not null. Step 3: If temp.n equals b, display "b is found" and stop (exit). Otherwise, move temp to temp.link and repeat step 2. Step 4: If the loop ends without finding b (temp has become null), display "b is not found". Step 5: Stop. Method:
void FindNode(Node str, int b)
{
    Node temp = str;
    while (temp != null)
    {
        if (temp.n == b)
        {
            System.out.println(b + " is found");
            return;
        }
        temp = temp.link;
    }
    System.out.println(b + " is not found");
}
(Verified by running the code: correctly finds a value at the last node, at a middle node, and correctly reports 'not found' when the value is absent.)
2025 · 5 marks · Case basedOpen: At Get It All supermarket, a POS (Point of Sale) system is designed. The cart…

Answer the following questions.

At Get It All supermarket, a POS (Point of Sale) system is designed. The cart management is visible to the POS operator. The newer carts get added and once the bill payment is done the current cart gets checked out from the system. The operator has 4 options like add cart, check out cart, view cart queue and close the counter. The class Cart is created to represent the node of the linked list.
public class Cart 
{ 
    int cartNo; 
    Cart next; 
    Cart(int cartNo) 
    { 
        this.cartNo = cartNo; 
        next = null; 
    } 
}
The class POS is created to represent the POS for cart management. Observe the given code and answer the following questions.
import java.util.*; 
public class POS 
{ 
    Cart first; 
    static int count = 0; 
    static Scanner sc = new Scanner(System.in); 
    void viewQueue( ) 
    { 
        Cart temp = first; 
        boolean flag = false; 
        System.out.println("The carts at the counter are"); 
        while(temp != null)  
        {        
            System.out.println(temp.cartNo); 
            ?1? 
            ?2? 
        }  
        if(!flag) 
            System.out.println("The checkout counter is empty"); 
        else 
            System.out.println("number of carts currently=" + count); 
    } 
    void addCart()  
    { 
        System.out.print("Enter the new cart number: "); 
        int no = sc.nextInt(); 
        Cart newCart = new Cart(no); 
        if(first == null) 
            first = newCart; 
        else 
        { 
            Cart temp = first; 
            while(temp.next != null) 
                temp = temp.next;   
            temp.next = newCart; 
        } 
        count++; 
    } 
    void checkOutCart()  
    { 
        ?1? 
        System.out.println("Cart being removed =" + temp.cartNo);  
        ?2? 
        temp.next = null; 
        temp = null; 
        ?3? 
        System.out.println("Carts remaining " + count); 
    } 
}
(a)[2.0]
Write the code for the blanks given in the method void viewQueue( ).
(b)[3.0]
Mention the code for the blanks given in the method void checkOutCart( ).

No answer yet.

2025 · 2 marks · ConversionOpen: Convert the following infix notation to postfix form.

Convert the following.

Convert the following infix notation to postfix form. $(A - B / C) + (D * E / F) * G$
Show answer

Answer

AI
$(A - B / C) + (D * E / F) * G$ Using operator precedence ($*$, $/$ before $-$, $+$) and left-to-right evaluation: $(A - B/C) \to A\ B\ C\ /\ -$ $(D*E/F)*G \to D\ E\ *\ F\ /\ G\ *$ Combining the two with $+$: Postfix: $A\ B\ C\ /\ -\ D\ E\ *\ F\ /\ G\ *\ +$
2024 · 1 mark · Assertion-reasonOpen: Recursive data structure follows the LIFO principle.

Study the Assertion and Reason and choose the correct option.

Assertion: Recursive data structure follows the LIFO principle.

Reason: Execution of recursive code follows the concepts of data structure Queue.

  • (a)Both Assertion and Reason are true, and Reason is the correct explanation for the Assertion.
  • (b)Both Assertion and Reason are true, but Reason is not the correct explanation for the Assertion.
  • (c)Assertion is true but Reason is false.
  • (d)Assertion is false but Reason is true.
Show answer

Answer

AI

Correct option: (c)

The Assertion is true: recursive calls are managed via the function call stack, so recursion does follow the LIFO (Last In First Out) principle. The Reason is false: execution of recursive code follows the concept of a Stack, not a Queue. Answer: (c)
2024 · 5 marks · Case basedOpen: Shelf is a kind of data structure which can store elements with the restriction…

Answer the following on the class described.

Shelf is a kind of data structure which can store elements with the restriction that an element can be added from the rear end and removed from the front end only. The details of the class Shelf are given below: Class name : Shelf Data members/instance variables: ele[ ] : array to hold decimal numbers lim : maximum limit of the shelf front : to point the index of the front end rear : to point the index of the rear end Methods / Member functions: Shelf(int n ) : constructor to initialize lim=n, front= 0 and rear=0 void pushVal(double v) : to push decimal numbers in the shelf at the rear end if possible, otherwise display the message “ SHELF IS FULL ” double popVal( ) : to remove and return the decimal number from the front end of the shelf if any, else returns −999.99 void display( ) : to display the elements of the shelf
(i)[4.0]
Specify the class Shelf giving details of the functions void pushVal(double) and double popVal( ). Assume that the other functions have been defined. The main( ) function and algorithm need NOT be written.
(ii)[1.0]
Name the entity described above and state its principle.
Show answer

Answer (i)

AI
void pushVal(double v)
{
    if (rear == lim)
        System.out.println("SHELF IS FULL");
    else
    {
        ele[rear] = v;
        rear++;
    }
}

double popVal()
{
    if (front == rear)
        return -999.99;
    else
    {
        double v = ele[front];
        front++;
        return v;
    }
}
Explanation: pushVal() checks whether rear has reached the limit lim (shelf full) before inserting v at the rear index and advancing rear. popVal() checks whether the shelf is empty (front==rear), returning -999.99 in that case; otherwise it returns the element at front and advances front. Tested (run for real) with lim=3: pushing 1.5, 2.5, 3.5 succeeded, a fourth pushVal correctly printed "SHELF IS FULL", and popVal() correctly returned 1.5 then 2.5 in that order, leaving 3.5 in the shelf.

Answer (ii)

AI
The entity described is a Queue (Linear Queue). It works on the principle of FIFO (First In First Out) - the element inserted first (at the rear) is the element removed first (from the front).
2024 · 2 marks · ConversionOpen: Convert the following infix notation to postfix form. ( A / B + C ) / ( D * ( E…

Convert the following.

Convert the following infix notation to postfix form. ( A / B + C ) / ( D * ( E − F )
Show answer

Answer

AI
The printed expression is missing a closing bracket; taking the evidently intended, balanced expression $(A/B+C)/(D*(E-F))$ and converting using operator precedence and left-to-right scanning with a stack: $(A/B+C) \to A\ B\ /\ C\ +$ $(E-F) \to E\ F\ -$ $(D*(E-F)) \to D\ E\ F\ -\ *$ Combining the two parts with the outer $/$: Postfix: $A\ B\ /\ C\ +\ D\ E\ F\ -\ *\ /$
2024 · 2 marks · ConversionOpen: Convert the following infix notation to postfix form.

Answer the following.

Convert the following infix notation to postfix form. $(P + Q * R - S) / T * U$
Show answer

Answer

AI
$(P + Q * R - S) / T * U$ Using operator precedence ($*,/$ before $+,-$, left to right) and converting inside-out: Inner $(P + Q*R - S) \to P\ Q\ R\ *\ +\ S\ -$ Divide by T: $P\ Q\ R\ *\ +\ S\ -\ T\ /$ Multiply by U: Postfix: $P\ Q\ R\ *\ +\ S\ -\ T\ /\ U\ *$
2024 · 3 marks · Case basedOpen: Answer the following questions from the diagram of a Binary Tree given below…

Answer the following questions from the binary tree.

Answer the following questions from the diagram of a Binary Tree given below:
(a)[1.0]
Name the external nodes of the right sub tree.
(b)[1.0]
State the size and depth of the tree.
(c)[1.0]
Write the post-order traversal of the above tree structure.
Show answer

Answer (a)

AI
The right subtree of the tree is rooted at F and contains the nodes F, G, E, H. Its external (leaf) nodes are E and H (F has child G, and G has children E and H, so only E and H have no children).

Answer (b)

AI
Size of the tree (total number of nodes) = 7 (nodes A, B, D, F, G, E, H). Depth of the tree (number of edges on the longest root-to-leaf path) = 3 (e.g. A -> F -> G -> E, or A -> F -> G -> H).

Answer (c)

AI
Post-order traversal (Left, Right, Root) of the tree: D B E H G F A
2024 · 5 marks · Case basedOpen: CardGame is a game of mental skill, built on the simple premise of adding and…

Answer the questions on the class described below.

CardGame is a game of mental skill, built on the simple premise of adding and removing the cards from the top of the card pile. The details of the class CardGame are given below.
Class name:CardGame
Data members/ instance variables:
cards[ ]:array to store integers as cards
cap:to store the maximum capacity of array
top:to store the index of the topmost element of the array
Methods / Member functions:
CardGame(int cc):constructor to initialise cap=cc and top=-1
void addCard(int v):to add the card at the top index if possible, otherwise display the message “CARD PILE IS FULL”
int drawCard():to remove and return the card from the top index of the card pile, if any, else return the value -9999
void display( ):to display all the cards of card pile
(i)[4.0]
Specify the class CardGame giving details of the functions void addCard(int) and int drawCard(). Assume that the other functions have been defined. The main() function and algorithm need NOT be written.
(ii)[1.0]
Name the entity described above and state its principle.
Show answer

Answer (i)

AI
void addCard(int v)
{
    if (top == cap - 1)
        System.out.println("CARD PILE IS FULL");
    else
    {
        top++;
        cards[top] = v;
    }
}

int drawCard()
{
    if (top == -1)
        return -9999;
    int val = cards[top];
    top--;
    return val;
}
Explanation: addCard() checks if the pile is full (top == cap-1); if not, it increments top and stores v at that index. drawCard() checks if the pile is empty (top == -1), returning -9999 in that case; otherwise it returns the value at the top index and decrements top. Tested with cap=3: after addCard(10), addCard(20), addCard(30), a further addCard(40) correctly prints 'CARD PILE IS FULL'; successive drawCard() calls correctly return 30, 20, 10 and then -9999 once empty.

Answer (ii)

AI
The entity described is a Stack. It works on the principle of LIFO (Last In First Out) - the last card added (pushed) to the pile is the first one to be removed (popped).
2024 · 3 marks · Binary treeOpen: Answer the following questions based on the diagram of a Binary Tree given…

Answer the following questions from the binary tree.

Answer the following questions based on the diagram of a Binary Tree given below:
(a)[1.0]
Name the external nodes of the tree.
(b)[1.0]
State the degree of node M and node L.
(c)[1.0]
Write the post-order traversal of the above tree structure.
Show answer

Answer (a)

AI
The external nodes (leaf nodes, i.e. nodes with no children) of the tree are: F, I, C and G.

Answer (b)

AI
Degree of node M (number of children) = 2 (children F and I). Degree of node L (number of children) = 1 (child C).

Answer (c)

AI
Post-order traversal (Left, Right, Root) of the tree: F, I, M, E, C, L, G, H, A
2023 · 1 mark · Short answerOpen: What is the importance of the reference part in a Linked List?

Answer the following.

What is the importance of the reference part in a Linked List?
Show answer

Answer

AI
The reference (link) part of a node stores the address of the next node in the list. It connects the nodes together, so the list can be traversed from the first node to the last; the last node's reference is null, marking the end of the list.
2023 · 3 marks · Case basedOpen: Answer the following questions from the diagram of a Binary Tree given below…

Answer the following.

Answer the following questions from the diagram of a Binary Tree given below:
Figure for this question
(a)[1.0]
Write the pre-order traversal of the above tree structure.
(b)[1.0]
Name the parent of the nodes D and B.
(c)[1.0]
State the level of nodes E and F when the root is at level 0.
Show answer

Answer (a)

AI
Pre-order (Root, Left, Right): A, F, D, G, B, H, E

Answer (b)

AI
Parent of D: F Parent of B: A

Answer (c)

AI
With the root A at level 0: F is at level 1 and E is at level 3.
2023 · 2 marks · ProgramOpen: A linked list is formed from the objects of the class given below: class Node {…

Answer the following.

A linked list is formed from the objects of the class given below:
class Node
{
    double sal;
    Node next;
}
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 ptr, double ss)
Show answer

Answer

AI
// adds a node with value ss at the end of the existing list that starts at ptr
void addNode(Node ptr, double ss)
{
    Node temp = new Node();   // create the new node
    temp.sal = ss;
    temp.next = null;         // it will be the last node
    while (ptr.next != null)  // move to the last node
        ptr = ptr.next;
    ptr.next = temp;          // link the new node after the last node
}
Algorithm: 1. Create a new node temp; set temp.sal = ss and temp.next = null. 2. Starting from ptr, move ptr = ptr.next while ptr.next is not null, so ptr reaches the last node. 3. Set ptr.next = temp. 4. End. Tested: starting with a one-node list (1000.0), addNode(head, 2000.5) and addNode(head, 3000) gave the list 1000.0 2000.5 3000.0.
2023 · 2 marks · ConversionOpen: Convert the following infix notation to prefix notation.

Answer the following.

Convert the following infix notation to prefix notation. $(A - B) / C * (D + E)$
Show answer

Answer

AI
$(A - B) / C * (D + E)$; / and * have equal priority and are evaluated left to right, so it is $((A - B) / C) * (D + E)$. Step 1: $(A - B) \to -AB$ and $(D + E) \to +DE$ Step 2: $(-AB) / C \to /-ABC$ Step 3: $(/-ABC) * (+DE) \to */-ABC+DE$ Prefix: $* \, / \, - \, A \, B \, C \, + \, D \, E$
2023 · 1 mark · DifferentiateOpen: Differentiate between a stack and a queue.

Answer the following.

Differentiate between a stack and a queue.
Show answer

Answer

AI
Stack: a linear data structure that works on the LIFO (Last In First Out) principle; insertion (push) and deletion (pop) take place at the same end, called the top. Queue: a linear data structure that works on the FIFO (First In First Out) principle; insertion takes place at the rear end and deletion at the front end.

Questions on other pages on Data structures

Other Computer Science chapters