Algorithms | Apple | AssemblyLanguage | BASH | Bash Cookbook | C-Programmming | CommonLisp | Computer Security | CuisSmalltalk | Databases | Emacs | Exploitation | Firewalls | Fortran | Functional Programming | Git | GNUSmalltalk | Haskell | Social Engineering | Javascript | Julia | Linux | Machine Learning | Metasploit |Machine Learning | Networking | Operating Systems | Open Data Science | Odin | Picolisp | Pharo Smalltalk | Purescript | Python | Racket | Scheme | Unity | vim | V | Web Development | Windows WSL | Zig
Algorithms
Algorithms
Here is the truth about algorithms: they are recipes, and the interesting question is not “does it work?” but “how does the cost grow when the input gets bigger?” Once you start seeing growth rates, a lot of software design stops being guesswork.
What it is, in plain words
An algorithm is a precise, finite procedure for turning inputs into outputs. A data structure is a way of organising data so that certain algorithms become cheap. The two are inseparable: the right structure turns an impossible algorithm into a trivial one.
Computer science classifies algorithms by the kind of job they do:
- Searching – find a thing (linear scan, binary search, hash lookup).
- Sorting – put things in order (quicksort, mergesort, heapsort, counting sort).
- Graphs – walk networks (BFS, DFS, Dijkstra, A*).
- Strings – match, parse, compress.
- Numerics – linear algebra, random numbers, optimisation.
- Distributed – consensus, replication, MapReduce-style fan-out.
And it classifies their cost with big-O notation: constant, logarithmic, linear, “linearithmic”, quadratic, and so on. The notation describes how the running time (or memory) grows as the input size grows – ignoring constant factors and focusing on the shape.
Why it matters
Choosing list versus hash table versus B-tree is an algorithm decision, whether you write the code yourself or pick a library. Databases, games, compilers, network routers and machine learning frameworks are all piles of algorithms. Knowing the basic ones means you recognise when a program is doing something that could be , and you stop being intimidated by the word “algorithm” itself.
An everyday analogy: finding a word in a dictionary
Looking through every page from the start is a linear search – . Opening to the middle, deciding “before or after?”, and repeating is binary search – . For a thousand-page dictionary that’s about ten steps instead of hundreds. Same data, different algorithm, wildly different effort. A hash table is like a librarian who has already put every word on a numbered shelf by a formula – if you know the formula.
flowchart LR I[Input size n] --> A1["O(1) hash lookup"] I --> A2["O(log n) binary search"] I --> A3["O(n) linear scan"] I --> A4["O(n log n) good sorting"] I --> A5["O(n²) nested loops"]
A hands-on example
Binary search in Python (on a sorted list):
def binary_search(a, target):
lo, hi = 0, len(a) - 1
while lo <= hi:
mid = (lo + hi) // 2
if a[mid] == target: return mid
if a[mid] < target: lo = mid + 1
else: hi = mid - 1
return -1
print(binary_search([1, 3, 4, 7, 9, 11], 7)) # 3
A linear congruential generator – the classic cheap pseudo-random number algorithm (good for demos, not for cryptography):
def lcg(seed, a=1664525, c=1013904223, m=2**32):
"""X_{n+1} = (a·X_n + c) mod m"""
x = seed
while True:
x = (a * x + c) % m
yield x
from itertools import islice
print(list(islice(lcg(42), 5)))
Big-O in the wild – these Python costs are worth memorising:
| Operation | Cost |
|---|---|
dict / set lookup, insert | average |
list index | |
list append | amortised |
list insert at front | |
sorting (list.sort) | |
checking x in list |
A map of the territory
When people say “learn algorithms” they usually mean this core:
- Arrays, linked lists, stacks, queues
- Hash tables
- Trees (BSTs, heaps) and graphs
- Sorting and searching
- Recursion and dynamic programming
- Bit tricks and string algorithms
- A taste of NP-completeness – why some problems have no known fast algorithm
You don’t need to invent quicksort. You need to know it exists, what it costs, and when your code has accidentally reinvented bubble sort on a million rows.
Common misconceptions
- “The fastest algorithm is the best.” Fastest on what size? What hardware? Prefer simple over clever with a huge constant until profiling says otherwise.
- “Big-O is the running time.” It’s a growth class. can beat for small .
- “Hash tables are always O(1).” Average case, with a good hash and load factor. Worst case is ; adversarial inputs are a real security issue.
- “Algorithms = competitive programming.” That’s one gym. Production algorithms also include caches, Bloom filters, LSM trees and consensus protocols.
- “Random number generators produce true randomness.” LCGs and most PRNGs are deterministic and predictable. Use
secrets//dev/urandomfor security.
Connections
- Data Structures and Algorithms – deeper notes.
- Computer Science – the wider field.
- NumPy and Fortran – numerical algorithms in practice.
- PicoLisp – where lists and recursion feel natural.
- Lambda Calculus – algorithms as pure functions.
Numerical
Randomizing Data
The Linear Congruential Generator
Xn+1 = (A.Xn+1 + B).Mod(M)
Where A, B and M are constants. This will generate a sequence of numbers that appear to be random.
Linked Lists Arrays Stacks and Queues Sorting Searching Hash Tables Recursion Trees Network Based String Distributed
