






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







High-Probability Topics ยท All Four Modules
Total Marks: 40 Time Allowed: 1 Hour 30 Minutes Section A (MCQ) 20 ร 1 = 20 marks
Section B (MSQ) 5 ร 2 = 10 marks Section C (Prog) 2 ร 5 = 10 marks
Student Name Roll Number Date
_
A MCQ (Single correct) 20 ร 1 20 /
B MSQ (Multi correct) 5 ร 2 10 /
C Programming 2 ร 5 10 /
TOTAL (^40) /
General Instructions 1. All questions in Section A and B are compulsory. Attempt BOTH questions in Section C.
Choose the single BEST answer for each question. [1 mark each, no negative marking]
Module 1 โ Algorithms, Problem Solving & Computer Architecture
Q1. Which of the following BEST defines an algorithm?
(a) A high-level programming language such as Python or Java (b) A finite, ordered sequence of well-defined instructions to solve a specific problem (c) A type of computer memory used to store currently running programs (d) The physical processor (CPU) inside a computer
Q2. In a flowchart, which shape is used to represent a DECISION or conditional check?
(a) Rectangle โ represents a process or computation (b) Oval / rounded rectangle โ represents Start or Stop (c) Diamond โ represents a decision or yes/no condition
(d) Parallelogram โ represents input or output
Q3. Which of the following is NOT a core pillar of Computational Thinking?
(a) Decomposition (b) Pattern Recognition (c) Compilation (d) Abstraction
Q4. The correct order from problem to program in algorithmic thinking is:
(a) Program โ Pseudocode โ Flowchart โ Steps โ Problem (b) Problem โ Steps โ Flowchart โ Pseudocode โ Program (c) Flowchart โ Steps โ Pseudocode โ Problem โ Program (d) Steps โ Problem โ Program โ Flowchart โ Pseudocode
Q5. Which type of computer memory is VOLATILE โ loses its data when power is switched off?
(a) Hard Disk Drive (HDD) (b) Solid State Drive (SSD) (c) RAM โ Random Access Memory (Main Memory) (d) ROM โ Read-Only Memory
Module 2 โ Data Structures & Python Fundamentals
Q6. Which data structure follows the LIFO (Last In, First Out) principle?
(a) Queue (b) Array (c) Stack (d) Linked List
Q7. What is the output of: len([10, 20, 30, 40, 50])?
(a) 4 (b) 5 (c) 6 (d) 50
Q8. Which Python expression correctly accesses the LAST element of my_list?
(a) my_list[0] (b) my_list[-1] (c) my_list[last] (d) my_list.end()
Q9. What does my_list[1:4] return for my_list = [10, 20, 30, 40, 50]?
(a) [10, 20, 30] (b) [20, 30, 40] (c) [20, 30, 40, 50] (d) [10, 20, 30, 40]
Q10. Which Python operator extracts the LAST DIGIT of an integer n?
(a) n // 10 (floor division) (b) n ** 2 (exponentiation) (c) n % 10 (modulus / remainder) (d) n / 10 (true division)
Module 3 โ Sorting & Searching Algorithms
(d) It computes the sum of the first n natural numbers
Q20. Which statement about Von Neumann computer architecture is TRUE?
(a) The CPU and Main Memory are physically the same component (b) The Hard Disk stores the programs currently being executed (c) The CPU and Main Memory (RAM) communicate via a Bus (d) RAM is non-volatile and retains data permanently without power
One or more options may be correct. Full 2 marks: ALL correct options selected and NO wrong option selected. Partial 1 mark: only correct options selected but not all of them. 0 marks: any wrong option selected.
Q21. Which of the following are TRUE properties of a correct algorithm? [ Select ALL correct options ] (a) Finiteness โ the algorithm must terminate after a finite number of steps (b) Definiteness โ every step must be precisely and clearly defined (c) It must always use recursion to be considered a valid algorithm (d) Effectiveness โ every step must be basic enough to actually be carried out
Q22. Which of the following methods correctly swap the values of variables A and B in Python? [ Select ALL correct options ] (a) A, B = B, A โ Pythonic tuple swap (recommended approach) (b) A = B ; B = A โ direct assignment (DOES NOT work โ original A is lost) (c) temp = A ; A = B ; B = temp โ using a temporary variable (works correctly) (d) A = A+B ; B = A-B ; A = A-B โ arithmetic swap (works for numeric values)
Q23. Which of the following statements about Bubble Sort are CORRECT? [ Select ALL correct options ] (a) It compares adjacent elements and swaps them if they are in the wrong order (b) After each complete pass, the largest unsorted element settles at its final correct position (c) Its worst-case time complexity is O(nยฒ) (d) It is the most efficient sorting algorithm, ideal for very large datasets
Q24. Which of the following statements about Python Lists are TRUE? [ Select ALL correct options ] (a) Lists are mutable โ elements can be modified after the list is created (b) Lists are heterogeneous โ they can store elements of different data types (c) Lists are immutable, just like Python strings and tuples (d) my_list.append(x) adds the element x to the END of the list
Q25. Which of the following are valid and correct uses of a Python while loop? [ Select ALL correct options ] (a) while n != 0: with n = n // 10 โ processes each digit of n one at a time (b) while num != -1: โ keeps reading input until the user types -1 (sentinel pattern) (c) A while loop always executes exactly 10 times regardless of the condition (d) while True: combined with a break statement โ correctly simulates a do-while loop
Write your solution in Python OR Pseudo-code. Clearly state at the top which language you are using. Marks are awarded for correct logic, proper indentation, variable naming, and handling of edge cases. Attempt BOTH questions.
Write a program that accepts a positive integer N as input and prints:
(i) The total number of digits in N (ii) The sum of all digits of N (iii) Whether N is a palindrome number (reads same forwards and backwards) Example โ Input: N = 1221 โ Number of digits: 4 | Sum of digits: 6 | Palindrome: Yes Example โ Input: N = 1234 โ Number of digits: 4 | Sum of digits: 10 | Palindrome: No Hint: Use n % 10 to extract the last digit and n // 10 to remove it inside a while n != 0 loop. Marking: Loop structure (1) + Digit count (1) + Digit sum (1) + Palindrome logic (2)
Answer:
SECTION A โ MCQ | Quick Answer Reference
Q Ans Q Ans Q Ans Q Ans Q Ans
Q1 (b) Q5 (c) Q9 (b) Q13 (c) Q17 (c)
Q2 (c) Q6 (c) Q10 (c) Q14 (b) Q18 (c)
Q3 (c) Q7 (b) Q11 (b) Q15 (b) Q19 (b)
Q4 (b) Q8 (b) Q12 (c) Q16 (b) Q20 (c)
Detailed Explanations:
Q1. Answer: (b) An algorithm is a finite, ordered sequence of well-defined instructions that solves a specific problem. Key properties: Finiteness (must terminate), Definiteness (every step is clear), Input/Output, and Effectiveness.
Q2. Answer: (c) Standard flowchart shapes โ Diamond: Decision/Condition (yes/no branch), Rectangle: Process/Computation, Oval: Start or Stop, Parallelogram: Input or Output.
Q3. Answer: (c) The four pillars of Computational Thinking are: Decomposition, Pattern Recognition, Abstraction, and Algorithm Design. Compilation is a step in software development, not a CT pillar.
Q4. Answer: (b) The refinement path is: Problem (understand it) โ Steps (write algorithm) โ Flowchart (visualise) โ Pseudocode (draft logic) โ Program (actual code).
Q5. Answer: (c) RAM (Random Access Memory) is volatile โ all data is lost the moment power is removed. HDD and SSD are non-volatile secondary storage; data persists without power.
Q6. Answer: (c) A Stack is LIFO โ the last element pushed is the first one popped (like a stack of plates). A Queue is FIFO โ first element in is the first element out.
Q7. Answer: (b) len() counts the number of elements. The list has 5 elements (10,20,30,40,50), so len() = 5. Remember: len() gives count, not the last index (which would be 4).
Q8. Answer: (b) Python supports negative indexing: my_list[-1] returns the last element, my_list[-2] the second-last, and so on. This avoids needing to know the list length.
Q9. Answer: (b) Slicing my_list[start:stop] extracts elements from index start up to but NOT including stop. my_list[1:4] gives indices 1, 2, 3 โ values [20, 30, 40].
Q10. Answer: (c) n % 10 gives the remainder when n is divided by 10, which is always the units digit. For example: 1234 % 10 = 4 (last digit). n // 10 removes the last digit instead.
Q11. Answer: (b) Bubble Sort's inner loop compares arr[j] and arr[j+1] (adjacent neighbours) and swaps them if arr[j] > arr[j+1]. This causes larger values to progressively move rightward ('bubble up').
Q12. Answer: (c) Bubble Sort uses two nested loops each running up to n times โ O(nยฒ) worst-case. This happens when the list is sorted in reverse order and every comparison requires a swap.
Q13. Answer: (c) Selection Sort scans the unsorted portion to find the MINIMUM element, then swaps it with the first unsorted position. After k passes, the first k elements are in their final sorted positions.
Q14. Answer: (b) Binary Search requires the list to be SORTED. It compares the target with the middle element and eliminates half the search space each step โ impossible if data is unsorted.
Q15. Answer: (b) Binary Search halves the search space each comparison โ O(log n). Linear Search scans every element โ O(n). For n=1,000,000 elements: Binary needs ~20 comparisons, Linear needs up to 1,000,000.
Q16. Answer: (b) Greedy algorithms pick the locally optimal choice at each decision point without reconsidering past choices. Classic examples: coin change (largest coin first), activity selection, Huffman coding.
Q17. Answer: (c) Convert 1101 binary to decimal: (1ร2ยณ) + (1ร2ยฒ) + (0ร2ยน) + (1ร2n) = 8 + 4 + 0 + 1 = 13.
Q18. Answer: (c) ord(character) returns the Unicode/ASCII integer code for a character. Examples: ord('A')=65, ord('a')=97, ord('0')=48. The inverse function is chr(65)='A'.
Q19. Answer: (b) Each iteration: n % 10 extracts the last digit, then n = n // 10 removes it. The loop terminates when n becomes 0, having processed all digits from right to left.
Q20. Answer: (c) Von Neumann architecture: the CPU (with ALU and Control Unit) and Main Memory (RAM) are the two central components, connected by a Bus. Programs are loaded from secondary storage into RAM before the CPU can execute them.
SECTION B โ MSQ | Correct Options & Explanations
Q21. Correct: (a), (b), (d) CORRECT โ (a) Finiteness: must terminate in a finite number of steps; (b) Definiteness: every step must be precise and unambiguous; (d) Effectiveness: each step must be simple enough to be executed. WRONG โ (c) Recursion is NOT a required property of algorithms; many algorithms (e.g., iterative loops) use no recursion at all.
N = int(input('Enter a positive integer: '))
original = N # save N before modifying it digit_count = 0 digit_sum = 0 reversed_n = 0 temp = N
while temp != 0: digit = temp % 10 # last digit digit_count = digit_count + 1 # count it digit_sum = digit_sum + digit # add to sum reversed_n = reversed_n * 10 + digit # build reverse temp = temp // 10 # drop last digit
print('Number of digits :', digit_count) print('Sum of digits :', digit_sum)
if original == reversed_n: print('Palindrome : Yes') else: print('Palindrome : No')
How each line works:
temp % 10 Extracts the rightmost (last) digit. E.g. 1234 % 10 = 4
digit_count + 1 Increments a counter by 1 each iteration โ counts every digit.
digit_sum + digit Accumulates the running total of all digits.
reversed_n * 10 + digit Shifts existing reversed digits left by one place, then appends the new digit on the right. This rebuilds the number in reverse order.
temp // 10 Removes the rightmost digit by integer division. Loop ends when temp reaches 0.
original == reversed_n After the loop, compares the saved original with the fully reversed number. Equal means palindrome.
Dry-run trace for N = 1221:
Step temp (before) (^) temp%10digit = digit_count digit_sum reversed_n temp after//
1 1221 1 1 1 1 122
2 122 2 2 3 12 12
3 12 2 3 5 122 1
4 1 1 4 6 1221 0
Loop ends 0 โ 4 6 1221 โ
original = 1221, reversed_n = 1221 โ 1221 == 1221 โ Palindrome: Yes
Sample Output:
--- Run 1: N = 1221 --- Number of digits : 4 Sum of digits : 6 Palindrome : Yes
--- Run 2: N = 1234 --- Number of digits : 4 Sum of digits : 10 Palindrome : No
Marks breakdown: Correct while loop & termination (1) | Digit count logic (1) | Digit sum logic (1) | Palindrome reverse build (1) | Final comparison & output (1)
Q27. โ Bubble Sort โ Ascending Order
Bubble Sort uses two nested loops. The outer loop counts passes. The inner loop repeatedly compares neighbouring elements and swaps them if the left one is bigger โ so the largest value 'bubbles' to the end each pass.
arr = [64, 34, 25, 12, 22] n = len(arr)
for i in range(n - 1): # n-1 passes are enough swapped = False
for j in range(n - i - 1): # shrink inner range each pass if arr[j] > arr[j + 1]: # wrong order? arr[j], arr[j+1] = arr[j+1], arr[j] # swap swapped = True
print('After Pass', i + 1, ':', arr)
if swapped == False: # no swaps = already sorted break
print('Final sorted list :', arr)
How each part works:
for i in range(n - 1) Outer loop runs at most n-1 passes. After n-1 passes, all elements are guaranteed to be sorted.
swapped = False Reset the flag at the start of every pass. Used to detect if any swap happened.
for j in range(n - i - 1) Inner loop only checks up to the unsorted portion. After pass i, the last i elements are already in their final positions โ no need to revisit them.
if arr[j] > arr[j+1] Compares two adjacent elements. If the left is larger, they are in the wrong order.
arr[j], arr[j+1] = arr[j+1], arr[j] Python tuple swap โ swaps both values in one line without a temporary variable.
if swapped == False: break If the inner loop completed without a single swap, the list is already sorted. We break early โ this is the optimisation that gives O(n) best-case performance.
Pass-by-pass trace for arr = [64, 34, 25, 12, 22]: