fork download
  1. // Route Pattern Matcher — Complexity Notes
  2.  
  3. // R = registered routes
  4. // L = max segments per route
  5. // U = incoming URLs
  6. // S = total segments across routes
  7. // N = Trie nodes
  8. // V = segments in incoming URL
  9.  
  10. // S <= R*L; N <= S+1
  11.  
  12. // Brute force:
  13. // Per URL: O(R*L)
  14. // Total: O(U*R*L)
  15.  
  16. // Trie + DFS:
  17. // Build once: O(S)
  18. // Split URL: O(V)
  19. // DFS: O(N)
  20. // Per URL: O(N+V)
  21. // Total: O(S+U*(N+V))
  22. // Upper bound: O(S+U*(S+V))
  23. // Space: O(S+V), excluding output
  24.  
  25. // Follow-ups:
  26. // Named parameters: O(N+V) per URL
  27. // Literal precedence: O(N+V) per URL
  28. // HTTP methods: O(N_m+V) per URL
  29. // Multi-segment star: O(N*V) matching DFS, plus reconstruction
  30.  
  31. // Why Trie helps: shared prefixes are traversed once per URL rather than separately for every registered route. Favorable matching can approach O(V), but worst-case Big O may remain comparable to brute force.
Success #stdin #stdout 0.02s 5612KB
stdin
Standard input is empty
stdout
Standard output is empty