Chapter 4 Problem Solving
Chapter 4 Problem Solving
Introduction
Computerisation and Problem Solving: - Emphasizes the role of computers
in automating complex tasks. - Example: Online train ticket booking.
Problem Solving: - Process of identifying a problem, developing an algorithm,
and implementing it to create a computer program.
Role of Computers: - Require precise step-by-step instructions (algorithms)
from humans to solve problems effectively.
1
• Multiple algorithms may exist for a problem; the most suitable one
must be selected.
3. Coding:
• Converting the algorithm into a format understandable by the com-
puter using a programming language.
4. Testing and Debugging:
• Ensuring the program works correctly through various testing methods
and fixing any errors found.
Algorithm
Definition: - A finite sequence of steps to solve a problem or perform a task.
Importance: - Acts as a roadmap for writing programs, increasing reliability,
accuracy, and efficiency.
Representation of Algorithms
• Flowchart: Visual representation using standardized symbols.
2
Pseudocode
Pseudocode: - Human-readable description of algorithm steps.
Keywords: - INPUT, COMPUTE, PRINT, INCREMENT, DECREMENT, IF/ELSE, WHILE,
TRUE/FALSE.
3
Benefits of Pseudocode
• Represents the basic functionality of the intended program in human-
readable language.
• Safeguards against omitting any important steps.
• Non-programmers can easily review to ensure the proposed implementation
achieves the desired result.
Flow of Control
Sequence: - Steps are executed one after another in a linear fashion.
Selection: - Decision-making processes where different paths are taken based
on certain conditions.
Iteration: - Repeating certain steps a specified number of times or until a
condition is met.
4
PRINT "Number is Odd"
Example:
INPUT Age
IF Age < 13 THEN
PRINT "Child"
ELSE IF Age < 20 THEN
PRINT "Teenager"
ELSE
PRINT "Adult"
5
Flow of Control: Repetition
Example:
Step 1: SET count = 0, sum = 0
Step 2: WHILE count < 5 REPEAT steps 3 to 5
Step 3: INPUT a number to num
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: COMPUTE average = sum / 5
Step 7: PRINT average
Verifying Algorithms
• Correctness: Ensuring the correct solution for all input values.
• Testing: Running the algorithm with various inputs.
Comparing Algorithms
Efficiency: - Comparing algorithms based on their efficiency, including time
complexity (how fast an algorithm runs) and space complexity (how much
memory an algorithm uses).
Choosing the Best Algorithm: - Selecting the most suitable algorithm based
on the specific requirements and constraints of the problem.
6
Decomposition
Breaking Down Problems: - Dividing a complex problem into smaller, more
manageable sub-problems.
Solving Sub-problems: - Developing algorithms for each sub-problem and
then combining them to solve the overall problem.