1. Introduction to Algorithms
Definition
An algorithm is a step-by-step procedure or set of rules for solving a problem or performing a
task.
Key points:
● Input → Process → Output
● Must be clear, finite, and effective
Example:
Algorithm to find the maximum of two numbers:
1. Start
2. Read two numbers, A and B
3. If A > B, print A
4. Else, print B
5. End
2. Characteristics of a Good Algorithm
1. Correctness – produces the right result
2. Finiteness – terminates after a finite number of steps
3. Efficiency – uses minimal resources (time, memory)
4. Clarity – easy to understand and follow
5. Generality – works for all valid inputs
3. Pseudocode
Pseudocode is a human-readable description of an algorithm that uses plain language.
, Example – Sum of first n numbers:
Start
Read n
sum = 0
For i = 1 to n
sum = sum + i
EndFor
Print sum
End
● Pseudocode bridges the gap between algorithm and programming language
● Platform-independent, flexible, and widely used in exams
4. Flowcharts
A flowchart visually represents an algorithm using standard symbols:
● Oval: Start / End
● Parallelogram: Input / Output
● Rectangle: Process
● Diamond: Decision / Condition
Example – Even or Odd Number:
1. Start
2. Input number N
3. N mod 2 = 0? → Yes: Print “Even”
4. No → Print “Odd”
5. End
5. Basic Logic in Computer Science
Logic is fundamental for decision making and control flow in programming.
Boolean Logic
● True / False values
● Operators: AND, OR, NOT
● Truth tables illustrate operator outcomes