PIXELBANKv9.1.0
Menu

State Space Model vs Attention Complexity

State Space Models (SSMs) like Mamba offer an alternative to Transformers with linear complexity in sequence length.

Self-Attention complexity: O(N2â‹…D)O(N^2 \cdot D) - quadratic in sequence length NN

SSM (Mamba) complexity: O(Nâ‹…Dâ‹…S)O(N \cdot D \cdot S) - linear in sequence length

  • NN: Sequence length
  • DD: Hidden dimension
  • SS: State dimension (typically 16-64)

Task: Return the asymptotic complexity for both architectures as a tuple of strings.

This linear scaling enables Mamba to process much longer sequences (e.g., 1M tokens) that would be computationally infeasible for Transformers.

Example:

Input:
N=1000, D=512, S=16
Output:
("O(N*D*S)", "O(N^2*D)")
Reasoning:

SSM processes each token once with state updates: O(N×D×S). Attention computes all pairwise interactions: O(N²×D). For N=1000, SSM is ~60× more efficient.

Constraints:

  • NN (Sequence Length): 1≤N≤1061 \leq N \leq 10^6
  • DD (Hidden Dimension): 1≤D≤40961 \leq D \leq 4096
  • SS (State Dimension): 1≤S≤641 \leq S \leq 64
solution.py

Test Results

0/0
Run code to see test results.
State Space Model vs Attention Complexity - Medium | PixelBank