Introduction to Algorithms
In this lesson, we begin our journey into one of the most fundamental and powerful areas of computer science — Algorithms.
Before we talk about advanced techniques or complex problems, we must first understand what an algorithm really is and why it plays such a critical role in every software system.
Industry truth: Good algorithms scale products. Bad algorithms break them.
What Is an Algorithm?
An algorithm is a step-by-step procedure used to solve a problem or perform a task.
It is not tied to any programming language. An algorithm exists as pure logic — long before it becomes code.
Simply put:
An algorithm is a clear set of instructions that transforms input into output.
Input → Process → Output
Every algorithm follows the same basic structure:
- Input: The data we give to the algorithm
- Process: The steps performed on the data
- Output: The result produced
This pattern appears everywhere — from simple programs to complex AI systems.
Real-World Example
Imagine you want to find the smallest number from a list of exam scores:
Scores = [72, 88, 45, 91, 60]
Your brain naturally follows an algorithm:
- Start with the first number
- Compare it with the next
- Keep the smallest value found so far
That thinking process itself is an algorithm — even before writing any code.
A Simple Algorithm Example
Let us write a basic algorithm to find the minimum value from a list of numbers.
arr = [72, 88, 45, 91, 60]
min_value = arr[0]
for num in arr:
if num < min_value:
min_value = num
print(min_value)
This algorithm works by comparing each element and updating the minimum whenever a smaller value is found.
Why Algorithms Matter
Two programs can solve the same problem — but one may run in milliseconds while the other takes minutes.
The difference is not the computer. The difference is the algorithm.
Algorithms determine:
- Speed of execution
- Memory usage
- Scalability
- User experience
That is why companies test algorithmic thinking in interviews more than language syntax.
Algorithms vs Programs
Many beginners confuse algorithms with programs. They are not the same.
An algorithm is the logic. A program is the implementation.
The same algorithm can be written in:
- C
- Python
- Java
- Any language
But the core steps remain unchanged.
Key Characteristics of a Good Algorithm
A good algorithm should:
- Be clear and unambiguous
- Always terminate
- Produce correct output
- Be efficient in time and space
In later lessons, we will learn how to measure and optimize these properties.
Mini Practice
Think about this carefully:
- How would you find the largest number in a list?
- What steps would you follow?
Try to write the steps in plain English before thinking about code.
Exercises
Exercise 1:
What is the main purpose of an algorithm?
Exercise 2:
Can the same algorithm be written in multiple programming languages?
Exercise 3:
Why should algorithms always terminate?
Quick Quiz
Q1. What are the three basic components of an algorithm?
Q2. Is an algorithm dependent on a programming language?
In the next lesson, we will explore time and space complexity and learn why some algorithms are faster and more efficient than others.