Prashnikaप्रश्निका

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

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

Practise these questions with filters
2018 · 1 mark · Short answerOpen: List the leaf nodes of the tree.

Answer the following questions from the binary tree.

List the leaf nodes of the tree.
Figure for this question
Show answer

Answer

Checked answer.
The leaf nodes (nodes with no children) are $G, H$ and $F$.
2017 · 1 mark · Binary treeOpen: Write the postorder traversal of the above tree structure.

Answer the following questions from the binary tree.

Write the postorder traversal of the above tree structure.
Show answer

Answer

AI
W F Y N R Z D G M Postorder (left, right, root): left subtree of M is N with W, then Y (with its left child F): W F Y N; right subtree G with Z (right child R), then D: R Z D G; then the root M.
2017 · 1 mark · Binary treeOpen: State the level numbers of the nodes N and R if the root is at 0 (zero) level.

Answer the following questions from the binary tree.

State the level numbers of the nodes N and R if the root is at 0 (zero) level.
Show answer

Answer

AI
Level of N = 1 and level of R = 3. Root M is at level 0; N is a child of M (level 1); R is a child of Z, which is a child of G, a child of M (M 0, G 1, Z 2, R 3).
2017 · 5 marks · ProgramOpen: Queue is an entity which can hold a maximum of 100 integers. The queue enables…

Write the program described below.

Queue is an entity which can hold a maximum of 100 integers. The queue enables the user to add integers from the rear and remove integers from the front. Define a class Queue with the following details: Class name : Queue Data Members / instance variables: Que[ ] : array to hold the integer elements size : stores the size of the array front : to point the index of the front rear : to point the index of the rear Member functions: Queue (int mm) : constructor to initialize the data size = mm, front = 0, rear = 0 void addele(int v ) : to add integer from the rear if possible else display the message “Overflow” int delele( ) : returns elements from front if present, otherwise displays the message “Underflow” and return -9999 void display ( ) : displays the array elements Specify the class Queue giving details of ONLY the functions void addele(int) and int delele( ). Assume that the other functions have been defined. The main function and algorithm need NOT be written.
Show answer

Answer

AI
void addele(int v)
{
    if (rear == size)
        System.out.println("Overflow");
    else
    {
        Que[rear] = v;
        rear++;
    }
}

int delele()
{
    if (front == rear)
    {
        System.out.println("Underflow");
        return -9999;
    }
    else
    {
        int v = Que[front];
        front++;
        return v;
    }
}
Explanation: elements are added at the rear and removed from the front. The queue is full when rear == size (Overflow) and empty when front == rear (Underflow, returning -9999). Tested by running with a queue of size 3: adding a 4th element printed Overflow, deleting 10, 20, 30 worked and a 4th delete printed Underflow and returned -9999.
2017 · 2 marks · ConversionOpen: Convert the following infix expression to postfix form:

Convert the following notation as directed.

Convert the following infix expression to postfix form: $P * Q / R + (S + T)$
Show answer

Answer

AI
PQ*R/ST++ $P * Q / R + (S + T)$: $P*Q \to PQ*$; dividing by R gives $PQ*R/$; $(S+T) \to ST+$; the final + gives $PQ*R/ST++$.
2017 · 1 mark · Binary treeOpen: List the internal nodes of the right sub-tree.

Answer the following questions from the binary tree.

List the internal nodes of the right sub-tree.
Show answer

Answer

AI
G, Z The right sub-tree has root G with nodes Z, D and R. Internal (non-leaf) nodes are those with at least one child: G and Z. D and R are leaf nodes.
2017 · 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 num;
    Node next;
}
Write an Algorithm OR a Method to count the nodes that contain only odd integers from an existing linked list and returns the count. The method declaration is as follows:
int CountOdd( Node startPtr )
Show answer

Answer

AI
int CountOdd(Node startPtr)
{
    int count = 0;
    Node ptr = startPtr;
    while (ptr != null)
    {
        if (ptr.num % 2 != 0)
            count++;
        ptr = ptr.next;
    }
    return count;
}
Explanation: start at the first node, visit every node until ptr becomes null, add 1 to count whenever the value of num is odd (num % 2 != 0, which also works for negative numbers) and finally return count. Tested by running: the list 5, 8, -3, 12, 7 gives 3 and an empty list gives 0.

Questions on other pages on Data structures

Other Computer Science chapters