Skip to main content
This guide covers the broader computer-science notation stack in LaTeX: algorithms, graph notation, asymptotic complexity, and related mathematical symbols.
Looking for pseudocode? Use the focused LaTeX pseudocode guide for algorithm, algorithmicx, and algpseudocode examples.

Essential Algorithm Packages

example.tex

Basic Pseudocode

Simple Algorithm Structure

example.tex
Test this example live in your browser. Open a ready-to-compile LaTeX project with TeX Live 2026 preinstalled and zero local setup.Open starter article

Control Structures

For complete algorithmic, algorithmicx, and algpseudocode control-structure syntax—including numbered algorithm boxes (\begin{algorithm}), input/output lines (\Require and \Ensure), \State, \If/\ElsIf/\Else/\EndIf, \For/\EndFor, \While/\EndWhile, \Repeat/\Until, \Procedure/\Function, \Return, \Comment, and the algorithm2e alternative—see the dedicated LaTeX pseudocode guide.

Sorting Algorithms

Merge Sort

example.tex

Graph Algorithms

example.tex

Dijkstra’s Algorithm

example.tex

Complexity Analysis

Big O Notation

example.tex

Complexity Classes

example.tex

Data Structures

Binary Search Tree Operations

example.tex

Hash Table Operations

example.tex

Dynamic Programming

Longest Common Subsequence

example.tex

Mathematical Algorithms

Euclidean Algorithm

example.tex

Machine Learning Algorithms

Gradient Descent

example.tex

Parallel Algorithms

Parallel Merge Sort

example.tex

Recurrence Relations

Solving Recurrences

example.tex

Algorithm Analysis Proofs

Correctness Proofs

example.tex

Best Practices

Clear Variable Names

Use descriptive variable names and consistent notation

Proper Indentation

Use consistent indentation to show algorithm structure

Complexity Analysis

Always include time and space complexity analysis

Invariants and Proofs

Document loop invariants and correctness proofs

Common Algorithm Notation

Troubleshooting

Common issues:
  • Missing algorithm package: Install algorithm and algorithmicx
  • Line numbering: Use [1] option in algorithmic environment
  • Indentation problems: Check matching \If/\EndIf pairs
  • Symbol conflicts: Some symbols may conflict with math mode

Further Reading