Problem Solving using Computer (Lesson)
Problem Solving using Computer
Programming is not just about writing syntax; it's about solving problems logically. Before touching the keyboard, we must define the strategy.
2.1 The Problem-Solving Life Cycle
- Requirement Analysis: Understand what the problem is.
- Algorithm Design: Plan the step-by-step solution.
- Flowcharting: Visualize the logic.
- Coding: Translate the logic into a programming language.
- Testing & Debugging: Find and fix errors.
2.2 Algorithms
An algorithm is a finite set of step-by-step instructions to solve a specific problem.
Characteristics of a Good Algorithm:
- Input: It should have zero or more inputs.
- Output: It must produce at least one output.
- Definiteness: Each step must be clear and unambiguous.
- Finiteness: It must stop after a finite number of steps.
- Effectiveness: Steps must be basic enough to be performed.
Example Algorithm: Add two numbers
- START
- Declare variables
A,B, andSUM. - Read values for
AandB. - Add
AandBand store the result inSUM(SUM = A + B). - Display
SUM. - STOP
2.3 Flowcharts
A flowchart is a graphical representation of an algorithm.
Standard Flowchart Symbols:
| Symbol | Name | Description |
|---|---|---|
| Terminal | Start or End of the program. | |
| Input/Output | Used for reading or writing data. | |
| Process | Arithmetic operations and data manipulation. | |
| Decision | Used for conditions (True/False). |
2.4 Pseudocode
Pseudocode (False Code) is an informal way of writing an algorithm using plain English mixed with programming logic markers like IF, THEN, ELSE, WHILE.
Example Pseudocode: Check if a number is Even or Odd
BEGIN
READ number
IF number % 2 == 0 THEN
PRINT "Number is Even"
ELSE
PRINT "Number is Odd"
ENDIF
END
Refer to the Lecture Slides for visual examples of complex flowcharts.