Understanding Algorithms
A Comprehensive Guide to Computational Logic
1. What is an Algorithm?
An algorithm is a step-by-step procedure or a set of rules to be followed in calculations or other
problem-solving operations, especially by a computer. Think of it as a recipe: you have inputs
(ingredients), a process (cooking steps), and an output (the finished meal).
Key Characteristics:
• Finiteness: It must eventually come to an end.
• Definiteness: Each step must be precisely defined.
• Input/Output: It must take zero or more inputs and produce at least one output.
• Effectiveness: Each step must be basic enough to be carried out.
2. How Algorithms Work
Algorithms process data through logical structures. The most common structures include:
• Sequence: Executing steps one after another.
• Selection (If-Then-Else): Making decisions based on conditions.
• Iteration (Loops): Repeating steps until a condition is met.
3. Measuring Efficiency: Big O Notation
In computer science, we don't just care if an algorithm works; we care how fast it works as the
data grows. This is measured using Big O Notation.
Notation Name Example
O(1) Constant Time Accessing an array element by index.
O(log n) Logarithmic Time Binary Search.
O(n) Linear Time Searching an unsorted list.
O(n²) Quadratic Time Nested loops (e.g., Bubble Sort).
4. Common Types of Algorithms
Sorting Algorithms
Arranging data in a particular order (e.g., alphabetical or numerical). Examples: Quick Sort,
Merge Sort.
Search Algorithms
Finding a specific item within a data structure. Examples: Linear Search, Binary Search.
Recursive Algorithms
Algorithms that call themselves with smaller input values to solve a problem.
Technical Reference Guide | Computational Foundations