| Table of contents | |
| Flow of Control | |
| Verifying Algorithms | |
| Notes | |
| Comparison of Algorithms | |
| Coding | |
| Decomposition |
Computers are an integral part of daily life and help us perform tasks faster and with greater accuracy. For example, booking railway tickets online is possible because of computers and smartphones.
India has a vast and complex railway network, which makes railway reservations a challenging task. This process requires managing details of trains (types, berths, compartments, schedules) and handling many users attempting to book tickets at the same time.
Online reservation systems have made ticket booking convenient by allowing users to obtain tickets from anywhere at any time. The process of using computers and software to automate routine human tasks is called computerisation.
Problem solving is central to computer science because computers are tools used to solve a wide range of problems. However, computers cannot solve problems by themselves. They need precise, step-by-step instructions from humans. The success of any computer-based solution depends on how clearly the problem is defined, how well the solution (the algorithm) is designed, and how correctly that algorithm is implemented as a program in a programming language.
In short, problem solving with computers involves identifying a problem, creating an algorithm to solve it, and implementing the algorithm as a program.

Solving a practical problem often requires several steps. For instance, if a vehicle makes an unfamiliar noise while driving, the owner first identifies the source of the noise. If the owner cannot fix it, they take the vehicle to a mechanic, who analyses the problem, plans the repair, and carries out the fix. This real-life process illustrates that problem solving is multi-step and systematic.
Some problems are simple and can be solved quickly, while others are complex and need systematic analysis and careful implementation. Problem solving with a computer generally follows these main steps, which are explained in the following subsections.
Before attempting a solution, it is essential to understand the problem fully. If the problem is not clearly understood, the final program may not meet the intended objectives. Careful reading and analysis of the problem statement helps identify:
By analysing the problem, you determine the essential functionalities that your solution must provide.
An algorithm is a precise sequence of steps that, when followed, solves the problem or achieves the desired task. Before coding, design a clear algorithm in natural language or a representation such as pseudocode or a flowchart. Think of the algorithm as a recipe that specifies the exact steps to reach the goal.
Many everyday activities require following a fixed order of steps. Examples include:
A finite sequence of steps that leads to the desired output when followed correctly is called an algorithm. An algorithm has a definite start and end and consists of a finite number of precise steps.
Example: Find the Greatest Common Divisor (GCD) of 45 and 54
Note: The GCD is the largest number that divides both given numbers.
Step 1: List divisors of 45 and 54.
Divisors of 45 are: 1, 3, 5, 9, 15, 45
Divisors of 54 are: 1, 2, 3, 6, 9, 18, 27, 54
Step 2: Find the largest common divisor in both lists.
Common divisors: 1, 3, 9
Therefore, GCD(45, 54) = 9
After analysing a problem and determining the logical steps, these steps should be written down along with required inputs and desired outputs. Two common representations are flowcharts and pseudocode. Both should:
A flowchart is a diagram made of boxes, diamonds and other shapes connected by arrows. Each shape represents a step, and arrows show the sequence. Flowcharts use standard symbols for common operations.
Shapes or Symbols to Draw Flowcharts

Example: Algorithm to find the square of a number
First identify input, process and output.
Algorithm to find the square of a number:
The flowchart for this algorithm can be drawn using the standard symbols.

Flowchart to solve the problem of a non-functioning light bulb

Example: Write an algorithm to display the sum of two numbers entered by the user, using both pseudocode and flowchart.
Sol:
Pseudocode:
INPUT num1 INPUT num2 COMPUTE Result = num1 + num2 PRINT Result
The corresponding flowchart represents these steps in sequence.

Example: Write an algorithm to calculate area and perimeter of a rectangle, using both pseudocode and flowchart.
Sol:
Pseudocode:
INPUT length INPUT breadth COMPUTE Area = length × breadth PRINT Area COMPUTE Perim = 2 × (length + breadth) PRINT Perim
The flowchart for this algorithm visualises input, computation and output steps.

Benefits of Pseudocode

The flow of control is the order in which statements or operations are carried out in an algorithm or program. The three main types of flow are:
Steps are executed one after the other in linear order without deviation. This is the simplest form of control.
Execution branches according to conditions. A condition evaluates to true or false, and different actions are taken based on the result. Examples include choosing the best route based on traffic or checking voting eligibility.
In algorithms, conditional actions are typically written as:
IF <condition> THEN steps when condition is true ELSE steps when condition is false

In programming languages the else clause implements the "otherwise" behaviour.
Example 1: Checking whether a number is odd or even
Algorithm:
Pseudocode:
PRINT "Enter the Number" INPUT number IF number MOD 2 == 0 THEN PRINT "Number is Even" ELSE PRINT "Number is Odd"
Example 2: Categorising a person based on age
Pseudocode:
INPUT Age IF Age < 13 THEN PRINT "Child" ELSE IF Age < 20 THEN PRINT "Teenager" ELSE PRINT "Adult"
Repetition involves executing a set of instructions multiple times until a specified condition is met. Loops automate repetitive tasks.
Example: Finding the average of 5 numbers
Pseudocode:
Explanation: A counter keeps track of loop iterations. After each iteration increase the counter until it reaches the limit.
Example: Accept numbers until 0 is entered
Pseudocode:
Explanation: When the number of iterations is not known beforehand, a while loop checks the condition repeatedly until it becomes false.
Importance: Verification ensures that algorithms work correctly and produce expected results. Faulty algorithms can cause serious problems in critical systems such as banking, healthcare and aerospace.
Example: Verify the formula for the sum of first N natural numbers
Dry Run Method:
Importance of Input Selection:
Activity 4.5: Write an algorithm to calculate the area and perimeter of a rectangular shape given the length and breadth in feet and inches (for example, 5 ft 6 in). Consider inputs in mixed units and show conversion steps before computing area and perimeter.
Concept of Algorithm - Definition: A step-by-step set of instructions to solve a problem is called an algorithm.
Example: Addition of Time
Step 1: Input the values for T1
Step 2: Input the values for T2
Step 3: Calculate the total time
Step 4: Adjust if necessary
Step 5: Output the total time
Verification:
Importance of Verification:

For a given problem there can be multiple algorithms. Choosing the best algorithm requires comparing them in terms of efficiency and resource usage. Consider the problem of checking whether a number is prime. Here are four possible algorithms:
All methods determine primality, but they differ in efficiency. Method (i) is least efficient; method (iii) is much better; method (iv) can be very efficient if a list of prime divisors is available and memory allows it.
When a problem is complex, break it down into smaller, manageable sub-problems. This process is called decomposition. Solve each sub-problem independently and combine solutions to form the overall solution.
For example, a Railway Reservation System can be decomposed into sub-systems such as:
Decomposition allows teams to work in parallel on different components according to their expertise. It is applicable to many real-life problems such as:
51 docs|11 tests |
| 1. What are the key steps involved in problem-solving? | ![]() |
| 2. What is an algorithm and how is it represented? | ![]() |
| 3. How does flow control work in algorithms? | ![]() |
| 4. Why is it important to verify algorithms? | ![]() |
| 5. What is the significance of algorithm comparison in problem-solving? | ![]() |