Author: Pedro Villa Navarro
Language & Standard: ISO C++17 (-Wall -Wextra -Wpedantic -O3)
This repository contains the C++ implementations, validation suites, and empirical performance studies developed for the Algorithms and Data Structures II (Algoritmos y Estructuras de Datos II) coursework. It explores three fundamental algorithmic paradigms from both a theoretical complexity perspective and an empirical, hardware-aware execution perspective:
-
Module 01 — Divide & Conquer vs. Direct Sliding Window:
-
Problem: Maximum substring ASCII difference over strings of length
$n$ ($n \le 1.92 \times 10^6$ ) with window length$m$ . - Focus: Mathematical recurrence analysis ($\Theta(n)$), differential fuzz testing across 1,000 randomized inputs, and microarchitectural comparison of recursive Divide & Conquer against a single-pass sequential Sliding Window.
-
Problem: Maximum substring ASCII difference over strings of length
-
Module 02 — Greedy Algorithms & Backtracking:
-
Greedy (
arD.cpp): Unit-time task scheduling with deadlines and profits (Aircraft Landing Scheduling), achieving$O(A \log A + A \cdot \min(Ut, A))$ time via matroid greedy-choice optimality. -
Backtracking (
backE.cpp): Exact combinatorial solver for the NP-hard Maximum Diversity Problem (Heavy $m$-Subgraph), implementing an iterative state-space decision tree with incremental objective evaluation and cardinality pruning.
-
Greedy (
A central takeaway of Module 01 is the empirical divergence between two algorithms that share the exact same asymptotic time complexity
| Input Size ( |
Window ( |
Direct Sliding Window (ms) | Divide & Conquer (ms) | Speedup Factor |
|---|---|---|---|---|
Although the Divide & Conquer recurrence
-
Zero Call-Stack Overhead: Avoids
$O(n/m)$ recursive function calls, stack-frame allocations, and register spills. -
Strict Sequential Locality: Performs a single linear pass over contiguous memory (
std::vector<int>), maximizing L1 data cache hit rates and hardware stride prefetcher efficiency without re-scanning boundary regions ([puntoMedio - m + 1, puntoMedio + m)).
aed2-algorithms-cpp/
├── Makefile # GNU Make build & automated test suite
├── CMakeLists.txt # Cross-platform CMake configuration
├── 01-divide-and-conquer/
│ ├── README.md # Complexity proofs, recurrences & benchmark plots
│ ├── src/
│ │ ├── dyv.cpp # Recursive Divide & Conquer solver
│ │ ├── resolucionDirecta.cpp # Linear O(n) Sliding Window solver
│ │ └── generadorChar.cpp # Random test case generator
│ ├── scripts/
│ │ ├── exec.sh # Single-run execution comparison script
│ │ └── execValidacion.sh # 1,000-run differential fuzzing harness
│ └── benchmark/
│ ├── dyvTiempo.cpp # POSIX gettimeofday() instrumented D&C solver
│ ├── resolucionDirectaTiempo.cpp # POSIX gettimeofday() instrumented Direct solver
│ ├── generadorCharTiempo.cpp # Parameterized benchmark input generator
│ ├── execTiempo.sh # 50-size x 20-iteration benchmark automation
│ └── data/
│ ├── ejemploTiemposSalida.txt # Raw experimental dataset (50 input sizes)
│ └── tiempos_grafica.svg # Empirical execution time plot (SVG)
└── 02-greedy-and-backtracking/
├── README.md # Theoretical analysis of Greedy & Backtracking
├── greedy/
│ ├── src/arD.cpp # Greedy Aircraft Landing Scheduler
│ └── benchmark/
│ ├── vorazDtiempos.cpp # Instrumented Greedy benchmark
│ └── execVorazDtiempos.sh # Greedy scaling benchmark script
└── backtracking/
├── src/backE.cpp # Iterative Backtracking solver (Max Diversity)
└── benchmark/
├── backEtiempos.cpp # Instrumented Backtracking benchmark
└── execBackEtiempos.sh # Exponential scaling benchmark (n = 2..24)
# Compile all solvers, generators, and benchmarks with -std=c++17 -O3 -Wall -Wextra -Wpedantic
make all
# Run the automated verification suite (differential & functional tests)
make test
# Clean build artifacts
make cleancmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build- Marta Tomás (@MartaTR13)
- Pedro Villa (@pedro-villa)