Class 12 Computer Science Half Yearly Question Paper 2025 Answer Key

Class 12 Computer Science Half Yearly Question Paper 2025 Answer Key (NCERT Based)

Instructions :
• All questions are compulsory.
• Questions (1-6) carry 1 mark each.
• Questions (7-9) carry 2 marks each.
• Questions (10-11) carry 4 marks each.

1. Which SQL function is used to retrieve the smallest value from a specific column in a database table?
(A) LEAST ()
(B) MIN ()
(C) SMALLEST ()
(D) BOTTOM ()
Answer – (B) MIN ()

2. The access mode to open a text file in reading mode is ……………
Answer – ‘r’

3. For Binary Search, the element list must be sorted. (True / False)
Answer – True

4. Assertion (A) : The first element inserted in the stack is removed first.
Reason (R) : Stack uses the FIFO (First In First Out) method.
(A) Both Assertion (A) and Reason (R) are true and Reason (R) is not correct explanation of Assertion (A).
(B) Both Assertion (A) and Reason (R) are true but Reason (R) is not correct explanation of Assertion (A).
(C) Assertion (A) is true but Reason (R) is false.
(D) Both Assertion (A) and Reason (R) are false.
Answer – (D) Both Assertion (A) and Reason (R) are false.

5. Write syntax of “for” loop in C++.
Answer – for (initialization; condition; increment/decrement) {
// statements
}

6. Write the syntax of the INSERT command in SQL used to insert data into a table.
Answer – INSERT INTO table_name (column1, column2, …)
VALUES (value1, value2, …);

7. CASE STUDY : In a bank’s token system, customers are served in the order they arrive. Which data structure is most suitable for managing this system, and why?
Answer – The data structure most suitable for managing a bank’s token system where customers are served in the order they arrive is a Queue because a queue follows the FIFO (First In First Out) principle, so the first customer to take a token is served first. This ensures customers are served in the order they arrive, making it ideal for a bank’s token system.

8. Explain SUM () function, its syntax in SQL with example.
Answer – The SUM() function in SQL is used to calculate the total (sum) of values in a numeric column.

• Syntax:
SELECT SUM(column_name) FROM table_name;

• Example:
SELECT SUM(Salary) FROM Employees;

9. Write any two differences between binary file and text file?
Answer – Differences between binary file and text file :
• Binary Files – Store data in a machine-readable (binary) format that is not directly readable by humans. They contain raw binary data (sequences of 0s and 1s) representing various data types like images, audio, videos, or executable files. When opened in a text editor, they appear as unreadable or jumbled characters. Examples: .bin, .exe, .jpg
• Text Files – Store data in a human-readable format using character encoding schemes like ASCII or Unicode. They can be opened and viewed in standard text editors such as Notepad or VS Code, and their content is directly understandable by humans. Examples: .txt, .csv, .py

OR

What is serialization and deserialization in python?
Answer : Serialization (Pickling) – Serialization is the process of converting a Python object (like a list, dictionary, or custom object) into a byte stream. This allows the object to be saved to a file, sent over a network, or stored in a database while preserving its structure and data. Python provides the pickle module to perform serialization.
• Deserialization (Unpickling) – Deserialization is the reverse process, where the byte stream is converted back into the original Python object. This allows the program to restore the object exactly as it was. The pickle module is also used for deserialization.

10. Explain the process of exception handling.
Answer – Exception handling is the process of handling runtime errors in a program to prevent it from crashing. Python provides special blocks to catch and manage exceptions.
• Process of Exception Handling :
(i) Try Block – The code that may cause an exception is written inside the try block.
(ii) Except Block – If an exception occurs in the try block, the except block executes to handle the error.
(iii) Else Block (Optional) – If no exception occurs, the else block executes.
(iv) Finally Block (Optional) – Code inside the finally block executes regardless of whether an exception occurs or not, usually for cleanup tasks.

Example of Python :

try:
num1 = int(input(“Enter first number: “))
num2 = int(input(“Enter second number: “))
result = num1 / num2
except ZeroDivisionError:
print(“Error: Division by zero is not allowed!”)
except ValueError:
print(“Error: Invalid input, please enter integers only!”)
else:
print(“Result is:”, result)
finally:
print(“Execution completed.”)

OR

What is a linear queue in data structure? Write and explain an algorithm to insert an element into a linear queue.
Answer – A linear queue is a linear data structure that adheres to the First-In-First-Out (FIFO) principle, meaning the first element added to the queue is the first one to be removed. It has two distinct ends: the front where elements are removed (dequeue operation), and the rear where elements are added (enqueue operation). This structure mimics real-world queues, such as a line of people waiting for service.
• Algorithm to Insert (Enqueue) an Element in a Linear Queue :
1. Check Overflow:
If rear == MAX – 1, then queue is full → insertion not possible.
2. Initialize Front:
If front == -1, then set front = 0.
3. Insert Element:
Increment rear = rear + 1.
4. Store Element:
queue[rear] = item.
5. End.

11. What is sorting? Explain Bubble Sort in detail with example.
Answer – Sorting is the process of arranging data in a specific order, such as ascending or descending. It makes searching and analysis easier.
• Bubble Sort is a simple comparison-based sorting method. It works by repeatedly going through the list, comparing each pair of adjacent elements, and swapping them if they are in the wrong order. This continues until the list is completely sorted. For example, if we have the list [5, 3, 8, 4], then in the first pass 5 and 3 are compared and swapped to get [3, 5, 8, 4]. Next, 5 and 8 remain as they are, but 8 and 4 are swapped to give [3, 5, 4, 8]. In the second pass, 5 and 4 are compared and swapped, resulting in [3, 4, 5, 8]. After the third pass, the list is fully sorted in ascending order: [3, 4, 5, 8].

OR

Explain the following :
(a) LAN
Answer – LAN (Local Area Network) is a network that connects computers and devices within a small area, such as a home, office, or school. It allows sharing of resources like files, printers, and internet among connected devices.

(b) MAN
Answer – MAN (Metropolitan Area Network) is a network that covers a larger area than LAN, such as a city or town. It is used to connect multiple LANs together for communication and resource sharing over a wider area.

(c) WAN
Answer – WAN (Wide Area Network) is a network that spans a very large area, even across countries or continents. The Internet is the largest example of a WAN. It connects multiple LANs and MANs over long distances.

(d) WWW
Answer – WWW (World Wide Web) is a system of interlinked web pages accessible through the Internet. It allows users to view and access information, multimedia, and services using a web browser.