A finite, step-by-step sequence of well-defined instructions or rules designed to perform a specific computation, solve a problem, or process data. In AI, algorithms are the mathematical engines that learn patterns from data.
An algorithm is simply a recipe.
If you want to bake a cake, the recipe tells you: 1) Preheat oven, 2) Mix flour and sugar, 3) Add eggs, 4) Bake for 30 minutes. If you follow the steps exactly, you get a cake.
In computer science, an algorithm is a recipe for the computer. It tells the computer exactly what steps to take, in what order, to transform an input (like a list of numbers) into a desired output (like those same numbers sorted from smallest to largest). Machine Learning algorithms are just highly complex recipes designed to find patterns in data rather than follow rigid, pre-written rules.
Algorithms are the foundational building blocks of all computer science, not just AI. However, in the context of AI, we distinguish between two broad types:
1. Traditional (Deterministic) Algorithms:
2. Machine Learning Algorithms:
Key Properties of a Good Algorithm:
While business leaders rarely write algorithms, understanding them is crucial for strategic decision-making:
Why It Matters:
The “Black Box” Challenge: As algorithms have evolved from simple linear regression to deep neural networks with billions of parameters, they have become less interpretable. Businesses must balance the high accuracy of complex algorithms with the need for explainability, especially in regulated industries.
A GPS navigation system. The traditional algorithm (Dijkstra’s) calculates the absolute shortest path on a static map. The modern ML algorithm (like in Google Maps) takes that base algorithm and layers on real-time, probabilistic data: historical traffic patterns, current accidents, and even the time of day, to predict the fastest route, not just the shortest.
# Traditional Algorithm: Binary Search (O(log n) efficiency)
def binary_search(arr, target):
"""Finds the index of a target value in a sorted list."""
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid # Target found
elif arr[mid] < target:
left = mid + 1 # Search right half
else:
right = mid - 1 # Search left half
return -1 # Target not found
# ML Algorithm: Linear Regression (Learning a pattern)
from sklearn.linear_model import LinearRegression
import numpy as np
# Data: Years of experience (X) and Salary (y)
X = np.array([[1], [2], [3], [4], [5]])
y = np.array([50000, 60000, 70000, 80000, 90000])
# The algorithm "learns" the relationship (y = mx + b)
model = LinearRegression()
model.fit(X, y) # This is the algorithmic learning step
print(f"Learned pattern: Salary = {model.coef_[0]} * Experience + {model.intercept_}")
# Output: Learned pattern: Salary = 10000.0 * Experience + 40000.0