Chapter 4: Introduction to Problem Solving
Complete Detailed Solutions (Including Full 5-Mark Answers)
Section B: 2 Marks Questions
1. Why do we need testing and debugging?
Testing is required to ensure the software meets user requirements, responds within expected times, and
generates correct outputs for all possible inputs [cite: 4]. Debugging is necessary to identify and rectify
syntactical or logical errors found during testing phases so the program functions accurately [cite: 4].
2. What is an algorithm? Give one real-life example.
An algorithm is a finite sequence of exact steps that, if followed correctly, leads to the desired result in a finite
amount of time [cite: 4]. A real-life example is following a recipe to prepare a dish or following steps to ride a
bicycle [cite: 4].
3. List any TWO characteristics of a good algorithm.
Two characteristics of a good algorithm are Precision (the steps are precisely stated and defined) and
Finiteness (it always stops after a finite number of steps) [cite: 4].
4. Define precision and uniqueness.
• Precision: The individual steps of the algorithm are precisely stated and clearly defined [cite: 4].
• Uniqueness: The results of each step are uniquely defined and depend only on the input and the result of
the preceding steps [cite: 4].
5. Why is finiteness important?
Finiteness is crucial because an algorithm must always stop after a finite number of steps to ensure it reaches
a solution in a finite amount of time rather than running endlessly in an infinite loop [cite: 4].
6. What is the purpose of a flowchart?
A flowchart serves as a visual representation of an algorithm [cite: 4]. Its purpose is to showcase the logic of
the problem solution while excluding implementation details and clearly revealing the flow of control during
execution [cite: 4].
7. What are the components of a flowchart?
A flowchart is made up of standardized geometric shapes (like boxes, diamonds, and ovals) that represent
specific steps or actions, connected by directional arrows that indicate the order or link among those steps
[cite: 4].
8. Draw symbols for: a) Process b) Decision.
• a) Process: Represented by a rectangle (Action Symbol) to indicate a process, action, or single step [cite:
4].
• b) Decision: Represented by a diamond shape to indicate a branching point based on a true/false or yes/no
question [cite: 4].
9. What is pseudocode? Mention any one feature.
Pseudocode is a non-formal language consisting of detailed descriptions of instructions intended for human
reading to help programmers write algorithms [cite: 4]. One key feature is that it cannot be executed directly by
a computer and avoids strict programming syntax [cite: 4].
10. Write pseudocode to add two numbers.
INPUT num1 [cite: 4]
INPUT num2 [cite: 4]
COMPUTE Result = num1 + num2 [cite: 4]
PRINT Result [cite: 4]
11. Why is pseudocode useful for non-programmers?
For non-programmers, actual programming codes are difficult to read and understand [cite: 4]. Pseudocode
provides a human-readable roadmap, helping them review the logic to confirm that the proposed
implementation will achieve the desired outcome [cite: 4].
12. Describe the term "sequence" in the context of algorithms.
In algorithm design, "sequence" refers to a flow of execution where all the steps or statements are executed
one after the other in a strict order from start to finish [cite: 4].
13. Difference between IF and ELSE IF.
• IF: Checks a primary condition and executes its block of statements if the condition evaluates to true [cite: 4].
• ELSE IF (ELIF): Used when there are multiple alternative conditions; it is evaluated only if the preceding
condition turns out to be false [cite: 4].
14. What does iterative mean in algorithm design?
Iterative means executing a specific set of program statements repeatedly for a finite number of times until a
specified condition is satisfied [cite: 4].
15. What is a loop? Give one daily life example.
A loop is a programming construct that repeats tasks efficiently based on a condition [cite: 4]. A daily life
example is clapping your hands five times, or jumping on the spot until you get tired [cite: 4].
16. When is WHILE construct is used?
The WHILE construct is used to execute a block of code repeatedly as long as the control condition remains
true [cite: 4]. It handles situations where the exact number of repetitions is unknown beforehand [cite: 4].
17. What is a counter variable? Give example.
A counter variable is used within a loop to keep track of the number of times the loop has been repeated [cite:
4]. Example: count = count + 1 [cite: 4].
18. Why do we need verification of algorithms?
Verification is required to ensure that the algorithm works correctly in every situation and yields the expected
output for various inputs, avoiding costly software failures [cite: 4].
19. What is a dry run? Why is it performed?
A dry run is the manual simulation method of taking an input value and walking through all the steps of the
algorithm [cite: 4]. It is performed to identify incorrect steps and missing details in the algorithm logic [cite: 4].
20. Define "space complexity" in algorithm analysis.
Space complexity refers to the amount of memory that is needed or utilized by a computer to execute a
specific algorithm [cite: 4].
21. Define "time complexity" in algorithm analysis.
Time complexity refers to the amount of processing time an algorithm needs to run its calculations and
generate an output [cite: 4].
22. What is syntax in programming?
Syntax is the set of rules or grammar that governs the formulation of statements in a specific programming
language, dictating spellings, order of words, and punctuation [cite: 4].
23. Define decomposition. Why is it useful?
Decomposition is the process of breaking down a complex problem into smaller, simpler sub-problems [cite:
4]. It is useful because these simpler parts can be solved independently by different teams and combined later
[cite: 4].
24. Difference between compiler and interpreter.
• Compiler: Translates the entire source code into object code all at once, reporting errors after scanning the
whole program [cite: 4].
• Interpreter: Translates and executes the program one line at a time, stopping immediately upon hitting an
error [cite: 4].
25. What is source code? Mention its feature.
Source code is the ordered set of instructions written in a high-level programming language [cite: 4]. Its
primary feature is that it uses English-like syntax, making it easier for humans to read, write, and maintain
[cite: 4].
26. Give a real-life example of decomposition.
A real-life example of decomposition is designing a complex railway reservation system by breaking it down
into smaller sub-problems, such as trains information, reservation info, food service, and billing service [cite:
4].
27. What is an Armstrong number?
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is exactly equal
to the number itself [cite: 4]. For example, 371 is an Armstrong number because 3³ + 7³ + 1³ = 371 [cite: 4].
28. What is a single-digit number algorithm?
A single-digit number algorithm is a process that uses conditionals to classify a numerical input [cite: 4]. For
instance, it checks if a given Number < 9; if true, it outputs "Single Digit" [cite: 4].
29. Explain the difference between pseudocode and a flowchart.
A flowchart is a graphical or visual representation of an algorithm using standardized shapes connected by
arrows [cite: 4]. Pseudocode is a non-formal, textual representation of instructions written in human-readable
language without strict syntax [cite: 4].
30. What are conditionals in programming?
Conditionals are programming constructs used to check specific possibilities or rules [cite: 4]. A program
evaluates one or more conditions and performs actions depending on whether the condition yields true or
false [cite: 4].
31. What is the significance of decision making in algorithms?
Decision making is significant because it allows an algorithm to behave differently based on the outcomes of
conditions [cite: 4]. It enables the algorithm to select from one of two or more alternative paths [cite: 4].
32. Describe the term "branching" in algorithms.
Branching refers to a decision point in an algorithm—usually represented by a diamond shape in a flowchart—
where a true/false question is asked, splitting the execution path into two distinct branches [cite: 4].
33. What is the role of an algorithm in problem-solving?
The role of an algorithm is to serve as a precise roadmap for the programmer before writing code [cite: 4]. It
outlines the exact logical steps needed to solve a problem, increasing reliability and efficiency [cite: 4].
34. Difference between source code and machine language.
Source code is written by humans in high-level programming languages close to natural languages [cite: 4].
Machine language consists entirely of 0s and 1s that are directly executed by computer hardware [cite: 4].
35. What are conditionals? Why required?
Conditionals evaluate to true or false values and direct program flow [cite: 4]. They are required whenever a
problem involves multiple possibilities, forcing the program to take action only if a specific condition is fulfilled
[cite: 4].
Section C: 3 Marks Questions
1. Explain any three characteristics of good algorithm with examples.
• Precision: Steps must be precisely stated and defined (e.g., specifying exact mathematical operations
rather than vague descriptions) [cite: 4].
• Uniqueness: Results of each step must depend only on the input and preceding steps [cite: 4].
• Finiteness: The algorithm must always stop after a finite number of steps [cite: 4].
2. Explain the importance of pseudocode before actual coding.
Pseudocode safeguards against leaving out important steps by mapping logic in human-readable language
[cite: 4]. It allows non-programmers to review and confirm the proposed implementation's logic before coding
begins [cite: 4].
3. Write pseudocode for calculating the area and perimeter of a rectangle.
INPUT length
INPUT breadth
COMPUTE Area = length * breadth
PRINT Area
COMPUTE Perim = 2 * (length + breadth)
PRINT Perim [cite: 4]
4. Write pseudocode and flowchart to check even or odd number.
PRINT "Enter the Number"
INPUT number
IF number MOD 2 == 0 THEN
PRINT "Number is Even"
ELSE
PRINT "Number is Odd" [cite: 4]
5. Draw flowchart for Child/Teenager/Adult classification.
1. Start terminal $ ightarrow$ 2. Enter Age $ ightarrow$ 3. Is Age < 13? (Yes: Print "Child", No: Check next) $
ightarrow$ 4. Is Age < 20? (Yes: Print "Teenager", No: Print "Adult") $ ightarrow$ 5. Stop [cite: 4].
6. What is the significance of iterative steps in an algorithm?
Iterative steps allow statements to execute repeatedly while a condition holds true [cite: 4]. This eliminates
writing thousands of redundant lines of code, making algorithms highly efficient [cite: 4].
7. Write algorithm to find sum and average of 5 numbers.
Step 1: SET count = 0, sum = 0
Step 2: WHILE count < 5, REPEAT steps 3-5
Step 3: INPUT num
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: average = sum / 5
Step 7: PRINT average [cite: 4]
8. Write pseudocode to accept numbers until 0 and find average.
Step 1: SET count = 0, sum = 0
Step 2: INPUT num
Step 3: WHILE num != 0, REPEAT steps 4-6
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: INPUT num
Step 7: average = sum / count
Step 8: PRINT average [cite: 4]
9. Explain how to handle time addition in pseudocode when minutes exceed 60.
Use a conditional check: IF (mm_total >= 60) [cite: 4]. Increment total hours by 1 (hh_total =
hh_total + 1) and subtract 60 from minutes (mm_total = mm_total - 60) to maintain proper time
format [cite: 4].
10. Explain time complexity and space complexity.
• Time Complexity: Measures the amount of processing time an algorithm requires to run and generate an
output [cite: 4].
• Space Complexity: Measures the amount of memory utilized by a computer to execute an algorithm [cite:
4].
11. Why do we need compiler or interpreter?
Computers understand only machine language (0s and 1s), while humans write source code in high-level
languages [cite: 4]. Translators are required to bridge this gap and convert source code into executable object
code [cite: 4].
12. Write the pseudocode to print all multiples of 5 between 10 and 25.
SET num = 10
WHILE num <= 25:
PRINT num
num = num + 5 [cite: 4]
13. Write an algorithm to find the greatest of two numbers.
INPUT num1, num2
IF num1 > num2:
PRINT num1 is greatest
ELSE:
PRINT num2 is greatest [cite: 4]
14. Write an algorithm to calculate the water bill based on consumption.
Calculate charges using consumption slabs: first 100 units @ 5, next 150 @ 10, above 250 @ 20, plus a fixed
monthly meter charge of 75 [cite: 4].
15. How do you write an algorithm to read the marks of three subjects and calculate the
aggregate?
INPUT sub1, sub2, sub3
aggregate = sub1 + sub2 + sub3
percentage = (aggregate / 300) * 100
PRINT aggregate, percentage [cite: 4]
16. Describe the pseudocode to classify numbers as "Single Digit," "Double Digit," or "Big."
INPUT Number
IF Number < 9:
PRINT "Single Digit"
ELSE IF Number < 99:
PRINT "Double Digit"
ELSE:
PRINT "Big" [cite: 4]
17. Write pseudocode for factorial of a number.
INPUT num
fact = 1
FOR i = num DOWNTO 1:
fact = fact * i
PRINT fact [cite: 4]
18. Describe the algorithm for checking whether a number is within a specific range.
INPUT Number
IF Number >= lower AND Number <= upper:
PRINT "Within range"
ELSE:
PRINT "Out of range" [cite: 4]
19. What improvements can be made to an algorithm that only accepts positive integers up
to 100?
Add robust error-handling loops to prompt users with warning messages and re-prompt until valid inputs within
the range are provided [cite: 4].
20. Difference between selection and repetition with examples.
• Selection: Chooses execution paths based on conditions (e.g., even/odd check) [cite: 4].
• Repetition: Executes statements repeatedly (e.g., calculating average of numbers) [cite: 4].
21. Describe the process of writing a flowchart for a given algorithm.
Translate each step into standard geometric shapes (ovals for start/stop, parallelograms for I/O, rectangles for
processes, diamonds for decisions) connected by directional arrows [cite: 4].
22. How can you improve an algorithm that fails for certain inputs?
Perform a dry run with failing inputs to locate logical flaws, then modify the algorithm by adding proper
conditional checks or validation steps [cite: 4].
23. Explain the importance of conditionals with an example.
Conditionals allow programs to adapt behavior rather than executing blindly (e.g., checking voting eligibility:
IF age >= 18) [cite: 4].
24. Discuss the significance of decision-making algorithms with a real-life example.
Allows automation to handle real-world variations (e.g., navigation apps recalculating routes during traffic
jams) [cite: 4].
25. What steps should be taken if an algorithm has multiple approaches?
Compare them based on time complexity (execution speed) and space complexity (memory usage) to select
the most efficient one [cite: 4].
26. Explain the importance of verifying an algorithm with an example.
Ensures correct outputs before coding (e.g., catching invalid minute totals like 70 minutes in time addition)
[cite: 4].
27. Describe the process of designing an algorithm to add hours and minutes.
Input time components, sum hours and minutes separately, check if minutes $\ge$ 60 to carry over an hour,
and print results [cite: 4].
28. Explain the three steps of problem solving using computers.
1. Analysing the Problem, 2. Developing an Algorithm, 3. Coding [cite: 4].
29. Explain verification with time addition example.
Dry-running test inputs (e.g., 4h 50m + 2h 20m) exposes formatting errors like "6h 70m", prompting logic
refinement [cite: 4].
30. Compare four prime checking algorithms. Which is best?
Methods range from checking all numbers up to $N$ (slow) to checking up to $\sqrt{N}$ or using prime lists
(efficient) [cite: 4].
31. Draw flowchart for positive/negative/zero check.
Start $ ightarrow$ Input $ ightarrow$ Check if >0 (Positive) $ ightarrow$ Check if <0 (Negative) $ ightarrow$
Else (Zero) $ ightarrow$ Stop [cite: 4].
32. Differentiate sequence and selection with examples.
Sequence runs straight (area calculation); selection branches on conditions (even/odd check) [cite: 4].
33. Explain decomposition with railway reservation example.
Breaking down a complex system into sub-problems like schedules, booking, infrastructure, and billing [cite:
4].
34. What are conditionals? Why required?
Evaluation statements yielding true/false values to guide program behavior based on conditions [cite: 4].
35. Write pseudocode to find largest of three numbers.
Compare three numbers using logical AND operators inside conditional blocks to find the maximum [cite: 4].
Section D: Detailed 5 Marks Questions
1. Write algorithm (pseudocode + flowchart) for GCD of two numbers.
Pseudocode:
INPUT a
INPUT b
WHILE b != 0:
SET temp = b
SET b = a MOD b
SET a = temp
PRINT a
Flowchart Description:
• Start: Terminator symbol indicating the start of the process [cite: 4].
• Input/Output: Parallelogram to input numbers a and b [cite: 4].
• Decision: Diamond box checking the condition b != 0 [cite: 4].
• Process (If True): Rectangle block executing Euclidean steps: temp = b, b = a MOD b, a = temp,
then looping back to the decision box [cite: 4].
• Input/Output (If False): Print final value of a as the Greatest Common Divisor [cite: 4].
• Stop: Terminator symbol ending the flowchart [cite: 4].
2. Explain the Characteristics of a good algorithm.
A properly designed algorithm must fulfill the following fundamental characteristics [cite: 4]:
• Precision: The steps are precisely stated and defined without any ambiguity [cite: 4].
• Uniqueness: The results of each step are uniquely defined and depend solely on the input and the result
of the preceding steps [cite: 4].
• Finiteness: The algorithm must always terminate or stop after a finite number of steps [cite: 4].
• Input: The algorithm receives specified inputs from the user or environment [cite: 4].
• Output: The algorithm produces the desired output corresponding to the input [cite: 4].
3. Write the pseudocode and draw the flowchart for calculating the area and perimeter of a
rectangle.
Pseudocode:
INPUT length
INPUT breadth
COMPUTE Area = length * breadth
PRINT Area
COMPUTE Perim = 2 * (length + breadth)
PRINT Perim
Flowchart Structure:
• Start terminal $ ightarrow$ Input box for length and breadth [cite: 4].
• Process box: Area = length * breadth [cite: 4].
• Input/Output box: Print Area [cite: 4].
• Process box: Perim = 2 * (length + breadth) [cite: 4].
• Input/Output box: Print Perim $ ightarrow$ End terminal [cite: 4].
4. Draw flowchart for sum of first N natural numbers.
Detailed Explanation & Flowchart Architecture:
• Start: Terminator symbol [cite: 4].
• Input: Read value N [cite: 4].
• Process: Initialize accumulation variables: set sum = 0 and counter i = 1 [cite: 4].
• Decision: Check condition i <= N [cite: 4].
◦ Yes Branch: Process box adds current counter to sum (sum = sum + i) and increments counter (i
= i + 1), then loops back to the decision check [cite: 4].
◦ No Branch: Proceeds to output the final computed sum [cite: 4].
• Output: Print sum $ ightarrow$ Stop terminal [cite: 4].
5. Write algorithm for numbers until 0 with verification.
Pseudocode:
SET count = 0
SET sum = 0
INPUT num
WHILE num != 0:
SET sum = sum + num
SET count = count + 1
INPUT num
IF count > 0:
COMPUTE average = sum / count
PRINT average
ELSE:
PRINT "No valid numbers entered"
Explanation: This algorithm continuously captures numbers until the sentinel value `0` is entered, keeping
track of both the running sum and element count for subsequent average verification [cite: 4].
6. Explain the steps involved in designing an algorithm for a coin-flipping game with detailed
conditionals.
Game Rules & Algorithm Design Steps:
• Objective: Two friends flip a coin 5 times; the first to win 3 flips wins the cake, where `1` represents Player
1 win and `2` represents Player 2 win [cite: 4].
• Initialization: Set score counters to zero (`P1_score = 0`, `P2_score = 0`) and round counter `round = 1`
[cite: 4].
• Repetition & Conditionals: Use a loop running up to 5 iterations:
WHILE round <= 5:
INPUT flip_result
IF flip_result == 1:
P1_score = P1_score + 1
ELSE IF flip_result == 2:
P2_score = P2_score + 1
IF P1_score == 3:
PRINT "Player 1 wins the cake!"
BREAK
ELSE IF P2_score == 3:
PRINT "Player 2 wins the cake!"
BREAK
round = round + 1
7. Write a detailed algorithm to print all multiples of 5 between 10 and 25.
SET num = 10
WHILE num <= 25:
PRINT num
SET num = num + 5
Explanation: The algorithm initializes a control variable at the lower boundary (10), prints it within a while
loop condition bounded by 25, and increments by 5 at each iteration [cite: 4].
8. Describe the steps involved in writing an algorithm for the total water bill calculation.
Step-by-Step Design:
• Step 1 (Input): Read the total consumption units and define fixed monthly meter charges (75) [cite: 4].
• Step 2 (Conditional Slabs): Use branching structures to evaluate consumption tiers:
◦ First 100 units charged at @ 5 per unit [cite: 4].
◦ Next 150 units (units 101 to 250) charged at @ 10 per unit [cite: 4].
◦ Consumption exceeding 250 units charged at @ 20 per unit [cite: 4].
• Step 3 (Aggregation): Add the calculated consumption bill to the fixed meter charge [cite: 4].
• Step 4 (Output): Print total payable water bill [cite: 4].
9. Describe the process of writing an algorithm to read the marks of three subjects and
calculate the percentage.
INPUT sub1
INPUT sub2
INPUT sub3
COMPUTE aggregate = sub1 + sub2 + sub3
COMPUTE percentage = (aggregate / 300) * 100
PRINT "Aggregate Marks:", aggregate
PRINT "Percentage:", percentage, "%"
Explanation: The algorithm captures marks across three separate academic subjects, computes their total
aggregate, calculates the percentage against a maximum score base of 300, and outputs both results [cite: 4].
10. Write algorithm for water bill with meter charge.
INPUT units
SET meter_charge = 75
IF units <= 100:
SET consumption_bill = units * 5
ELSE IF units <= 250:
SET consumption_bill = (100 * 5) + (units - 100) * 10
ELSE:
SET consumption_bill = (100 * 5) + (150 * 10) + (units - 250) * 20
SET total_bill = consumption_bill + meter_charge
PRINT "Total Water Bill:", total_bill
11. Find largest and smallest among four numbers.
INPUT a, b, c, d
SET largest = a
SET smallest = a
IF b > largest: largest = b
IF c > largest: largest = c
IF d > largest: largest = d
IF b < smallest: smallest = b
IF c < smallest: smallest = c
IF d < smallest: smallest = d
PRINT "Largest:", largest
PRINT "Smallest:", smallest
12. Write a detailed algorithm to classify numbers as "Single Digit," "Double Digit," or "Big."
INPUT Number
IF Number < 9:
PRINT "Single Digit"
ELSE IF Number < 99:
PRINT "Double Digit"
ELSE:
PRINT "Big"
13. Write a detailed pseudocode to calculate the factorial of a number.
INPUT num
SET fact = 1
IF num < 0:
PRINT "Factorial does not exist for negative numbers"
ELSE IF num == 0:
PRINT "Factorial is 1"
ELSE:
FOR i = num DOWNTO 1:
SET fact = fact * i
PRINT "Factorial is", fact
14. Draw flowchart for Armstrong number (3 digits).
Logic & Flowchart Architecture:
• Start $ ightarrow$ Input 3-digit number num $ ightarrow$ Copy to temp = num [cite: 4].
• Process digits iteratively using modulo/integer division:
◦ d1 = temp % 10, temp = temp // 10
◦ d2 = temp % 10, temp = temp // 10
◦ d3 = temp % 10
• Process sum: arm_sum = (d1**3) + (d2**3) + (d3**3) [cite: 4].
• Decision: Is arm_sum == num?
◦ Yes: Print "Armstrong Number" [cite: 4].
◦ No: Print "Not an Armstrong Number" $ ightarrow$ Stop [cite: 4].
15. Describe the process of writing an algorithm that accepts only positive integers up to
100.
Design Process:
WHILE True:
INPUT Number
IF (0 <= Number) AND (Number <= 100):
PRINT "Accepted:", Number
BREAK
ELSE:
PRINT "Invalid input! Please enter an integer between 0 and 100."
Significance: Incorporating input validation loops prevents erroneous out-of-bound values from causing
downstream runtime failures [cite: 4].
16. Explain the significance of iterative and branching steps in algorithm design with
examples.
Detailed Explanation:
• Branching (Selection): Allows programs to make decisions and shift execution paths based on true/false
conditions. Example: Checking voting eligibility (`IF age >= 18`) [cite: 4].
• Iterative (Repetition): Enables blocks of code to execute repeatedly under specific conditions, eliminating
massive code redundancy. Example: Processing test scores for an entire classroom using a loop [cite: 4].
17. Explain sequence, selection, repetition with flowcharts.
• Sequence: Instructions execute strictly one after another in linear succession. Represented by
consecutive rectangular process boxes connected by downward arrows [cite: 4].
• Selection: Flow splits into alternative pathways based on a condition's evaluation. Represented by a
diamond decision box branching into separate paths [cite: 4].
• Repetition: Statements execute cyclically while a condition remains true. Represented by a feedback
arrow looping back from a decision outcome to prior execution steps [cite: 4].
18. Compare flowcharts and pseudocode with advantages.
Comparison:
• Flowchart: A graphical representation using geometric shapes and directional flow arrows [cite: 4].
Advantage: Highly intuitive for visualizing overall control flow and logic layout at a glance [cite: 4].
• Pseudocode: A non-formal, textual description of logic written in human-readable language [cite: 4].
Advantage: Faster to write, easier to modify, and mirrors the structural organization of actual programming
code [cite: 4].
19. Explain the importance of flowcharts in problem-solving with a detailed example.
Flowcharts provide a standardized visual blueprint that maps out complex logic independently of programming
language syntax [cite: 4]. For example, troubleshooting a broken light bulb can be mapped out visually via
branching questions (`Is it switched on?` $ ightarrow$ `Is it burnt out?`), allowing designers to trace failure
paths before writing code [cite: 4].
20. Describe the algorithm for adding hours and minutes, including the necessary
conditionals.
INPUT hh1, mm1
INPUT hh2, mm2
SET hh_total = hh1 + hh2
SET mm_total = mm1 + mm2
IF mm_total >= 60:
SET hh_total = hh_total + (mm_total // 60)
SET mm_total = mm_total % 60
PRINT "Total Hours:", hh_total, "Total Minutes:", mm_total
21. Explain the importance of verifying algorithms with multiple examples.
Verifying algorithms with diverse test scenarios—including edge cases, boundary thresholds, and negative
values—ensures absolute correctness [cite: 4]. Testing with only a single standard input often masks hidden
logical bugs that cause software failure in production [cite: 4].
22. Discuss the different approaches to solving a problem using algorithms.
Different algorithmic approaches to the same problem are evaluated and compared using time complexity
(processing speed) and space complexity (memory utilization) to choose the optimal solution [cite: 4].
23. Explain the process of improving an algorithm that fails for certain inputs with a detailed
example.
When an algorithm fails (e.g., time addition outputting invalid minutes like 70), you perform a dry run with the
failing input to isolate the exact logical breakdown, then modify the algorithm by inserting proper conditional
conversion checks [cite: 4].
24. Explain the various steps involved in problem solving.
1. Analysing the Problem: Defining objectives, inputs, and outputs [cite: 4].
2. Developing an Algorithm: Devising a logical step-by-step plan [cite: 4].
3. Coding: Translating the algorithm into programming syntax [cite: 4].
4. Testing and Debugging: Validating output and eliminating errors [cite: 4].
25. Explain decomposition using Railway Reservation System.
Decomposition breaks a colossal problem into independent sub-problems [cite: 4]. For a Railway Reservation
System, this means separating modules for train schedules, ticket bookings/cancellations, infrastructure
security, catering services, and billing [cite: 4].
26. Write pseudocode for Dragons and Wizards game.
SET Dpoint = 0, Wpoint = 0
INPUT shape, value
IF (shape == "diamond") OR (shape == "club"):
SET Dpoint = Dpoint + 1
ELSE IF (shape == "heart") AND (value is number):
SET Wpoint = Wpoint + 1
ELSE IF (shape == "heart") AND (value is not number):
SET Dpoint = Dpoint + 1
ELSE:
SET Wpoint = Wpoint + 1
IF Dpoint > Wpoint:
PRINT "Dragon team is the winner"
ELSE:
PRINT "Wizard team is the winner"
27. Improve time addition algorithm with verification.
The improved algorithm uses integer division (`//`) and modulo (`%`) operators to flawlessly carry over hours
even when accumulated minutes exceed 120 or more [cite: 4].
28. Compare low-level and high-level languages.
Low-level languages (machine code/assembly) are hardware-dependent and difficult to write but execute
natively [cite: 4]. High-level languages (Python, C++) are portable and human-readable, requiring translation
compilers or interpreters [cite: 4].
29. Write algorithm for largest of three numbers.
INPUT num1, num2, num3
IF num1 >= num2 AND num1 >= num3:
PRINT num1
ELSE IF num2 >= num1 AND num2 >= num3:
PRINT num2
ELSE:
PRINT num3 [cite: 4]
30. Explain time & space complexity with prime example.
Time complexity measures execution speed, while space complexity measures memory usage [cite: 4]. For
prime checking, checking up to $\sqrt{N}$ optimizes time complexity compared to checking up to $N$ [cite: 4].