← Back to Games

⚔️ N × N Battlefield

Visualize nested loops and understand O(N²) complexity!

🎮 Battle Grid
0 / 0 cells visited
5
N (Grid Size)
0
Total Operations
Complexity
💻 Loop Code

📚 Understanding Nested Loop Complexity

When you nest loops, the complexities multiply:

  • O(N²): Two nested loops (i and j both go 0→N) = N × N operations
  • O(N³): Three nested loops = N × N × N operations
  • O(N log N): Loop where inner loop halves each time (like merge sort)
  • O(N × M): Two loops with different bounds

Example: For N=5, O(N²) = 25 operations. For N=100, O(N²) = 10,000 operations!

⚙️ Configuration
O(N²)
Double Loop
O(N³)
Triple Loop
O(N log N)
Halving Inner
O(N²/2)
Triangle (j≤i)
Current: (-, -)
📊 Statistics

For N = 5:

• O(N²) = 25 ops

• O(N³) = 125 ops

• O(N log N) ≈ 12 ops

• O(N²/2) = 15 ops