Algorithms matter behind SciPy: FFT is O(n log n), sparse matvec is O(nnz), eigen solvers scale with matrix structure. The DSA track explains why naive Python loops fail on large scientific data.
Complexity snapshots
- Dense matrix multiply n×n → O(n³) naive, better with BLAS
- FFT length n → O(n log n)
- Sparse CSR matvec → O(nnz)
- Sorting for Spearman → O(n log n)
Vectorization link
NumPy ufuncs avoid Python per-element loops. SciPy calls compiled LAPACK/ARPACK—know when data size forces sparse or approximate methods.
Sparse vs dense choice
import numpy as np
import scipy.sparse as sp
n = 1000
dense = np.eye(n)
sparse = sp.eye(n, format='csr')
v = np.ones(n)
print('dense bytes ~', dense.nbytes)
print('sparse nnz', sparse.nnz)
Important interview questions and answers
- Q: When sparse wins?
A: nnz ≪ n²—graphs, grids, bag-of-words; dense eye(n) wastes memory. - Q: BLAS?
A: Optimized linear algebra behind @ and many scipy.linalg calls.
Self-check
- What is FFT time complexity?
- When is sparse storage preferable to dense?
Tip: Continue complexity intuition at DSA intro—FFT and sparse matvec are interview favorites.
Interview prep
- FFT complexity?
O(n log n).
- Sparse matvec?
O(nnz)—not O(n²).