Prashnikaप्रश्निका
Code
About
Computer ScienceClass 12

Data structures - ISC Class 12 Computer Science Questions with Answers

87 past-paper questions on Data structures from ISC Class 12 Computer Science papers (2026-2017), newest first, in full. Questions 1-20 are on this page, 20 to a page. Tap "Show answer" under a question to see its answer. The syllabus covers Stack, Queue, Circular queue, Dequeue, Conversion of Infix to Prefix and Postfix, Single linked list, Binary trees and Tree traversals.

87questions
9years
2026newest
202611 questions
1 mark · Short answerOpen: Name the entity described above and state its principle.

Write the program described below.

Name the entity described above and state its principle.
Show the case
In any internet browser, a user can visit new webpages and go back to previously visited webpages. Each new webpage URL is stored in browser's memory such that when the user clicks 'Back' button, the previous webpage gets displayed. The details of the members of the class are given below: Class name : Browser Data members/instance variables: pages[ ] : an array to hold the URLs of visited webpages max : to store the maximum capacity of the array top : to point to the index of the last visited webpages Methods/Member functions: Browser(int cap) : constructor to assign max = cap and top = -1 void visit(String url) : to add URL of a new webpage if possible, else display the message "Browser history full" String back( ) : to remove and return the last visited webpage URL, if present, else to return the message "No previous browser history"
Show answer

Answer

Entity name: Stack Principle: LIFO (Last In, First Out). The most recently visited URL added to the stack is the first one retrieved when navigating back.
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:
Figure for this question
(a)[1]
Write the post-order traversal of the above tree.
(b)[1]
State the leaf nodes of the above tree.
(c)[1]
State the parent of Node D and the sibling of Node E.
Show answer

Answer (a)

Post-order traversal (left, right, root): C, E, G, F, D, B, J, I, H, A

Answer (b)

Leaf nodes (nodes with no children): C, E, G, J

Answer (c)

Parent of Node D = B Sibling of Node E = F
1 mark · Binary treeOpen: Write the pre-order traversal of the above tree.

Answer the following questions from the binary tree.

Write the pre-order traversal of the above tree.
Show answer

Answer

Pre-order traversal (Root -> Left -> Right): M, N, P, Q, T, U, O, R, S, V, W
4 marks · ProgramOpen: Specify the class Browser giving details of the functions void visit(String)…

Write the program described below.

Specify the class Browser giving details of the functions void visit(String) and String back( ). Assume that the other functions have been defined.
Show answer

Answer

void visit(String url)
{
    if (top == max - 1)
    {
        System.out.println("Browser history full");
    }
    else
    {
        top++;
        pages[top] = url;
    }
}

String back()
{
    if (top == -1)
    {
        return "No previous browser history";
    }
    else
    {
        String url = pages[top];
        top--;
        return url;
    }
}
2 marks · ProgramOpen: A linked list is formed from the objects of the class Word. The structure of…

Write the program described below.

A linked list is formed from the objects of the class Word. The structure of the class Word is given below:
class Word
{
    String value;
    Word next;
}
Write an Algorithm OR a Method to count and display the number of nodes whose value starts with a consonant. The method declaration is as follows: void countConsonant(Word first)
Show answer

Answer

void countConsonant(Word first)
{
    int count = 0;
    Word current = first;
    while (current != null)
    {
        if (current.value != null && current.value.length() > 0)
        {
            char ch = Character.toUpperCase(current.value.charAt(0));
            if (Character.isLetter(ch) && ch != 'A' && ch != 'E' && ch != 'I' && ch != 'O' && ch != 'U')
            {
                count++;
            }
        }
        current = current.next;
    }
    System.out.println("Number of nodes starting with a consonant: " + count);
}
Explanation: The method traverses the linked list starting from the first node. For each node, it checks if the first character of value is an alphabetic character and not a vowel (A, E, I, O, U). If so, count is incremented. After traversing the list, the count is displayed.
1 mark · Binary treeOpen: State the size of the left subtree and the right subtree.

Answer the following questions from the binary tree.

State the size of the left subtree and the right subtree.
Show answer

Answer

Size of the left subtree = 5 (nodes: N, P, Q, T, U) Size of the right subtree = 5 (nodes: O, R, S, V, W)
5 marks · Case basedOpen: A class CustomerService is defined to resolve customer service requests in the…

Answer the questions on the class described below.

A class CustomerService is defined to resolve customer service requests in the order in which they are received. The details of the members of the class are given below:
Class name:CustomerService
Data members/instance variables:
services[ ]:array to store customer service request
size:to store the maximum capacity of the array
first:to store the index of the first customer service request
last:to store the index of the last customer service request
Methods/Member functions:
CustomerService(int s):constructor to assign size = s, first = 0 and last = 0
void add(int reqst):to insert a request at index last, if space is available, otherwise display “Request cannot be accepted at the moment”
int del( ):to remove and return the request at index first, if any, else return -9999
(i)[4]
Specify the class CustomerService giving details of the functions void add(int) and int del( ). Assume that the other functions have been defined.
(ii)[1]
Name the entity described above and state its principle.
Show answer

Answer (i)

void add(int reqst)
{
    if (last == size)
        System.out.println("Request cannot be accepted at the moment");
    else
    {
        services[last] = reqst;
        last++;
    }
}

int del()
{
    if (first == last)
        return -9999;
    else
    {
        int val = services[first];
        first++;
        return val;
    }
}
(Tested (run for real) inside a complete class with size=3: adding a 4th request correctly printed "Request cannot be accepted at the moment", and the four del() calls correctly returned 101, 102, 103, then -9999.)

Answer (ii)

Entity: Queue Principle: FIFO (First In First Out) — the request that is added (inserted) first is the first one to be removed and serviced.
2 marks · ConversionOpen: Convert the following infix notation to prefix form. (P + Q / R) * (S + T / U)…

Answer the following.

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

Answer

Infix: $(P + Q/R) * (S + T/U) / V$ Step 1: $Q/R \to /QR$, so $P+Q/R \to +P/QR$ Step 2: $T/U \to /TU$, so $S+T/U \to +S/TU$ Step 3: $(P+Q/R)*(S+T/U) \to *\ +P/QR\ +S/TU$ Step 4: Divide the whole product by $V$: $\to /\ *+P/QR+S/TU\ V$ Prefix form: $/\ *\ +\ P\ /\ Q\ R\ +\ S\ /\ T\ U\ V$
2 marks · ProgramOpen: A linked list is formed from the objects of the class Node. The structure of…

Write the program described below.

A linked list is formed from the objects of the class Node. The structure of the class Node is given below:
class Node
{
    char ch;
    Node next;
}
Write an Algorithm OR a Method to count and display the number of upper-case and lower-case characters. The method declaration is as follows:
void countCase(Node startptr)
Show answer

Answer

void countCase(Node startptr)
{
    int upper = 0, lower = 0;
    Node p = startptr;
    while (p != null)
    {
        if (Character.isUpperCase(p.ch))
            upper++;
        else if (Character.isLowerCase(p.ch))
            lower++;
        p = p.next;
    }
    System.out.println("Upper-case count: " + upper);
    System.out.println("Lower-case count: " + lower);
}
Explanation: A pointer p starts at startptr and traverses the linked list node by node until it reaches null (end of list). At each node, Character.isUpperCase()/isLowerCase() checks the character ch and increments the appropriate counter; the counts are displayed once the traversal is complete. Tested (run for real) on the list H-e-L-l-O: output was 'Upper-case count: 3' and 'Lower-case count: 2', which is correct (H, L, O are upper-case; e, l are lower-case).
1 mark · Binary treeOpen: State the level of Node Q, when the root is at level 0.

Answer the following questions from the binary tree.

State the level of Node Q, when the root is at level 0.
Show answer

Answer

Level of Node Q = 2 (Root M is at level 0; nodes N, O are at level 1; nodes P, Q, R, S are at level 2).
2 marks · ConversionOpen: P / Q + (S * F + X / R)

Convert the following infix expression to prefix form.

$P / Q + (S * F + X / R)$
Show answer

Answer

Conversion from infix to prefix: Given infix: P / Q + (S * F + X / R) 1. Parenthesized term: (S * F + X / R) - S * F = * S F - X / R = / X R - * S F + / X R = + * S F / X R 2. Division: P / Q = / P Q 3. Addition: (/ P Q) + (+ * S F / X R) = + / P Q + * S F / X R Prefix form: + / P Q + * S F / X R
20259 questions
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]
Name the root of the left sub tree and its siblings.
(b)[1]
State the size and depth of the right sub tree.
(c)[1]
Write the in-order traversal of the above tree structure.
Show answer

Answer (a)

Official answer key
Root of the left subtree = B; its sibling = F (both B and F are children of the root A, so they are siblings of each other).

Answer (b)

Official answer key
The right subtree is rooted at F and contains the nodes F, C, G, H. Size = 4 nodes. Depth = 2 (the longest path from F down to the deepest node H is F -> G -> H, i.e. 2 levels/edges).

Answer (c)

Official answer key
In-order traversal (Left, Root, Right) of the whole tree: E D B A C F G H
1 mark · MCQOpen: ___________ is called a Self-Referential Data structure.

Choose the correct option.

___________ is called a Self-Referential Data structure.
  • (a)Stack
  • (b)Circular queue
  • (c)Linked List
  • (d)Double ended queue - dequeue
Show answer

Answer

Correct option: c

Answer: (c) Linked List. A linked list node contains a reference (pointer) to another node of the same type, so the structure refers to itself - this is what makes it a self-referential data structure.
2 marks · ProgramOpen: A linked list is formed from the objects of the class Cell. The class structure…

Write the program described below.

A linked list is formed from the objects of the class Cell. The class structure of the Cell is given below:
class Cell
{
    char m;
    Cell right;
}
Write an Algorithm OR a Method to print the sum of the ASCII values of the lower case alphabets present in the linked list. The method declaration is as follows:
void lowercase(Cell str)
Show answer

Answer

void lowercase(Cell str)
{
    int sum = 0;
    Cell temp = str;
    while (temp != null)
    {
        if (temp.m >= 'a' && temp.m <= 'z')
            sum = sum + (int) temp.m;
        temp = temp.right;
    }
    System.out.println("Sum of ASCII values of lowercase letters = " + sum);
}
The method traverses the linked list from the given node str to the end (right==null), adds the ASCII value of every lower-case character found (checked with the range 'a' to 'z') to sum, and finally prints the total.
3 marks · Case basedOpen: Answer the following questions based on the Binary Tree given below: Write the…

Answer the following questions from the binary tree.

Answer the following questions based on the Binary Tree given below:
(a)[1]
Write the in-order traversal of the right subtree.
(b)[1]
State the depth of the entire binary tree and depth of node E.
(c)[1]
Name the external nodes of the left subtree and internal nodes of the right subtree.
Show answer

Answer (a)

The right subtree is rooted at C: F (children K and L) is its left child and G (right child M) its right child; L has the left child N. In-order traversal (Left, Root, Right) of the right subtree: K, F, N, L, C, G, M

Answer (b)

Depth of the entire binary tree = 4 (longest path A, C, F, L, N has 4 edges). Depth of node E = 2 (A, B, E).

Answer (c)

External nodes of the left subtree (rooted at B): I, J, E. Internal nodes of the right subtree (rooted at C): C, F, G, L.
1 mark · MCQOpen: The Central Processing Unit (CPU) scheduling follows the principle of _________…

Choose the correct option.

The Central Processing Unit (CPU) scheduling follows the principle of _________ data structure.
  • (a)Two-dimensional array
  • (b)Circular queue
  • (c)Double ended queue dequeue
  • (d)Stack
Show answer

Answer

Correct option: b

Answer: (b) Circular queue. CPU scheduling (e.g. round-robin scheduling) keeps the ready processes in a queue and cycles through them in FIFO order; this ready queue is typically implemented as a circular queue so it can wrap around continuously without wasting slots.
5 marks · Case basedOpen: A circular queue is a linear data structure that allows data insertion at the…

Answer the following on the class described.

A circular queue is a linear data structure that allows data insertion at the rear and removal from the front, with the rear end connected to the front end forming a circular arrangement. The details of the members of the class are given below: Class name : CirQueue Data members/instance variables: Q[ ] : array to hold integer values cap : maximum capacity of the circular queue front : to point the index of the front rear : to point the index of the rear Methods/Member functions: CirQueue(int n) : constructor to initialise cap = n, front = 0 and rear = 0 void push(int v) : to add integers from the rear index if possible else display the message "QUEUE IS FULL" int remove( ) : to remove and return the integer from front if any, else return -999 void print( ) : to display the elements of the circular queue in the order of front to rear
(i)[4]
Specify the class CirQueue giving the details of the functions void push(int) and int remove( ). Assume that the other functions have been defined. The main( ) function and algorithm need NOT be written.
(ii)[1]
State one application of a circular queue.
Show answer

Answer (i)

void push(int v)
{
    if ((rear + 1) % cap == front)
        System.out.println("QUEUE IS FULL");
    else
    {
        Q[rear] = v;
        rear = (rear + 1) % cap;
    }
}

int remove()
{
    if (front == rear)
        return -999;
    int val = Q[front];
    front = (front + 1) % cap;
    return val;
}
Explanation: push() adds v at the rear index and advances rear circularly (using %cap), but first checks whether the next rear position would collide with front (queue full). remove() checks for an empty queue (front==rear) and returns -999 in that case; otherwise it returns the element at front and advances front circularly. Tested and working correctly for wraparound and full/empty conditions.

Answer (ii)

A circular queue is used to implement a CPU/round-robin scheduler, where processes are cyclically given a fixed time slice on the CPU.
5 marks · Case basedOpen: A circular queue is a linear data structure that allows data insertion at the…

Answer the following on the class described.

A circular queue is a linear data structure that allows data insertion at the rear and removal from the front, with the rear end connected to the front end forming a circular arrangement. Given below are the details of class MerryGoRound Class name : MerryGoRound Data members/instance variables: q[ ] : an array to hold integers cap : to store the maximum capacity of the array front : to point the index of the front end rear : to point the index of the rear end Methods/Member functions: MerryGoRound(int n) : parameterised constructor to initialise cap = n, front = rear = 0 void add(int val) : to add integers from the rear index if possible, else display the message "QUEUE IS FULL" int remove( ) : to remove and return the integer from front if any, else return -999 void display( ) : to display the elements of the circular queue in the order of front to rear
(i)[4]
Specify the class MerryGoRound giving details of the functions void add(int) and int remove( ). Assume that the other functions have been defined. The main( ) function and algorithm need NOT be written.
(ii)[1]
State the principle on which the entity works.
Show answer

Answer (i)

void add(int val)
{
    if ((rear + 1) % cap == front)
        System.out.println("QUEUE IS FULL");
    else
    {
        q[rear] = val;
        rear = (rear + 1) % cap;
    }
}

int remove()
{
    if (front == rear)
        return -999;
    int val = q[front];
    front = (front + 1) % cap;
    return val;
}
Explanation: add() checks whether inserting at rear would collide with front (queue full) using modulo arithmetic to wrap around the array; if not full it stores val at q[rear] and advances rear circularly. remove() checks for an empty queue (front==rear) returning -999 in that case; otherwise it returns the element at front and advances front circularly. Tested with cap=4: after add(10),add(20),add(30), remove() correctly returns 10; then add(40) succeeds but a further add(50) correctly prints 'QUEUE IS FULL', and the queue then displays as 20 30 40.

Answer (ii)

A circular queue works on the principle of FIFO (First In First Out), with the added feature that the rear end is logically connected back to the front end, forming a circular arrangement so that vacated front spaces can be reused instead of the queue getting prematurely full.
3 marks · Case basedOpen: Refer to the Binary Tree given below and answer the questions that follow…

Answer the following questions from the binary tree.

Refer to the Binary Tree given below and answer the questions that follow:
(a)[1]
Write the post-order traversal of the above tree structure.
(b)[1]
Name the internal nodes of the right subtree and the external nodes of the left subtree
(c)[1]
Write the size of the tree and the degree of node D.
Show answer

Answer (a)

Post-order traversal (Left, Right, Root) of the entire tree: A, C, E, D, B, H, I, G, F

Answer (b)

Right subtree (rooted at G): its nodes are G, I, H. Its internal nodes (nodes having at least one child) are G and I. Left subtree (rooted at B): its nodes are B, A, D, C, E. Its external/leaf nodes (nodes with no children) are A, C and E.

Answer (c)

Size of the tree (total number of nodes) = 9 (F, B, G, A, D, I, C, E, H). Degree of node D (number of children of D) = 2 (children C and E).
5 marks · Case basedOpen: Answer the questions based on the binary trees: Observe the following binary…

Answer the following questions.

Answer the questions based on the binary trees:
(a)[2]
Observe the following binary tree and identify its type. Justify your answer.
Figure for part (a)
(b)[2]
Observe the given tree and answer the following questions. (i) Why can the following tree not be termed as a full binary tree? (ii) What is the size of the given binary tree? (iii) Name the internal nodes of the given binary tree.
Figure for part (b)
(c)[1]
State any one condition for a balanced binary tree.
Show answer

Answer (a)

It is a complete binary tree. Every level is completely filled except possibly the last: level 0 has A, level 1 has B and C, level 2 has all 4 possible nodes D, E, F, G, and level 3 (the last, partially-filled level) has its nodes H, I, J packed as far left as possible (H and I under D, then J under E, with nothing under F or G).

Answer (b)

(i) It is not a full binary tree because node C has only one child (E) instead of exactly 0 or 2 children; a full binary tree requires every node to have either zero or two children. (ii) Size (total number of nodes) = 6 (A, B, C, F, D, E). (iii) Internal nodes (nodes with at least one child) = A, B, C.

Answer (c)

A binary tree is balanced if, for every node in the tree, the heights of its left and right subtrees differ by at most 1.

About Data structures

Data structures is a unit of the ISC Class 12 Computer Science syllabus.

The syllabus lists these topics: Stack, Queue, Circular queue, Dequeue, Conversion of Infix to Prefix and Postfix, Single linked list, Binary trees and Tree traversals.

Prashnika has 87 past-paper questions on Data structures, from papers of 2017-2026, asked in 9 different years. By kind: Binary tree (19), Program (19), Case based (15) and Short answer (13). They carry between 1 and 5 marks, and most are worth 2 marks.

To practise, use the Infix to postfix converter, the Binary tree and BST tool and the paper generator, which can build a practice paper from this chapter.

Common questions

What topics are in Data structures in ISC Class 12 Computer Science?

The syllabus lists Stack, Queue, Circular queue, Dequeue, Conversion of Infix to Prefix and Postfix, Single linked list, Binary trees and Tree traversals.

How many questions on Data structures are in ISC Class 12 Computer Science past papers?

Prashnika has 87 questions on Data structures, from papers of 2017-2026 (board, specimen, improvement and practice papers together).

What kinds of questions are asked on Data structures?

By kind: Binary tree (19), Program (19), Case based (15) and Short answer (13).

Questions on other pages on Data structures