IGCSE Computer Science (0478) - Programming & Algorithms Notes
1. Introduction to Programming & Algorithms
What is an Algorithm?
An algorithm is a step-by-step set of instructions to solve a specific problem. Algorithms
must be clear, precise, and efficient, ensuring they achieve the intended outcome correctly.
Characteristics of a Good Algorithm:
- Unambiguous: Each step must be clear and well-defined.
- Correctness: It should produce the correct output for valid inputs.
- Efficiency: It should use minimal resources (time and memory).
- Finiteness: It should terminate after a finite number of steps.
- Generalization: It should work for all valid inputs.
Example: An algorithm to make tea:
1. Boil water.
2. Add tea leaves or a tea bag.
3. Pour in the boiled water.
4. Add sugar/milk as needed.
5. Stir and serve.
What is Programming?
Programming is the process of writing instructions (code) to solve problems using a
programming language like Python, Java, or C++. It involves:
- Defining the problem
- Designing an algorithm
- Implementing the algorithm in a programming language
- Testing and debugging the program
- Maintaining and improving the program
8. Programming Concepts
8.1 Data Types
Integer: Whole numbers (e.g., 5, 100, -3)
Float: Decimal numbers (e.g., 3.14, 2.5)
String: Text data (e.g., 'Hello', 'Python')
Boolean: Logical values (True, False)
8.2 Input and Output
Example Input:
name = input("Enter your name: ")
Example Output:
print("Hello,", name)
8.3 Arithmetic Operators
Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%)
Example:
sum = 5 + 3
print(sum) # Output: 8
8.16 Abnormal, Normal, and Extreme Data
Normal Data: Valid inputs that the program is expected to handle correctly.
Abnormal Data: Invalid inputs, such as entering text instead of numbers.
Extreme Data: Values at the boundary of valid input (e.g., largest or smallest possible
values).
Example:
age = int(input("Enter your age: "))
if age < 0 or age > 120:
print("Invalid age entered.")
else:
print("Valid input.")