Network Security
Intrusion Detection (Snort, Suricata)
Intrusion Detection (Snort, Suricata)
Problem: String Pattern Matching, Trie, Sliding Window
Security Tools: Snort, Suricata, Zeek (formerly Bro), Cisco FirepowerHow it’s used:- Signature matching: Trie for fast pattern detection in packet payloads
- Snort: Aho-Corasick algorithm (multi-pattern trie) for rule matching
- Suricata: Multi-threaded pattern matching at 10Gbps+
- Zeek: DFA-based pattern matching for protocol analysis
- Multiple patterns: Check 100K signatures simultaneously
- Fast: O(m) vs O(n*m) for naive matching
- Real-time: Process 10Gbps with <1ms latency
- Snort: Deployed on millions of endpoints
- Suricata: Processes billions of packets per day in enterprise SOCs
- Pattern database: 50K-100K signatures updated daily
DDoS Detection & Mitigation
DDoS Detection & Mitigation
Problem: Sliding Window, Top K Elements, Bloom Filter
Security Tools: Cloudflare Magic Transit, AWS Shield, Arbor NetworksHow it’s used:- Rate limiting: Sliding window tracks requests per IP
- Top attackers: Min heap finds top K source IPs
- Bloom filter: Quickly check if IP is in blocklist (1% false positive vs 100x memory)
- Anomaly detection: Sliding window statistics for traffic spikes
- Cloudflare: Mitigates 100M+ requests/second during attacks
- AWS Shield: Automatically detects volumetric attacks >1Tbps
- Algorithm: Sliding window + bloom filter processes line-rate traffic
- Temporal patterns: Attacks show sustained high request rates
- Adaptive: Window size adjusts based on baseline traffic
- Efficient: O(1) amortized per request with proper cleanup
Firewall Rule Processing
Firewall Rule Processing
Problem: Trie (IP prefixes), Binary Search, Interval Trees
Security Tools: iptables, pfSense, Cisco ASA, Palo Alto NetworksHow it’s used:- IP matching: Trie for CIDR blocks (192.168.0.0/16)
- Port ranges: Interval tree for port 1000-2000
- Rule ordering: Binary search for rule priority
- iptables: Linear chain traversal optimized with hash tables
- CIDR notation: 192.168.1.0/24 = binary prefix
- Longest match: Most specific rule wins
- Fast: O(32) for IPv4, O(128) for IPv6
- Enterprise firewalls: 10K-100K rules
- iptables: Can handle 1M+ packets/second
- Palo Alto: Hardware-accelerated trie lookup
TLS/SSL Certificate Validation
TLS/SSL Certificate Validation
Problem: Tree Traversal, Path Finding
Security Tools: OpenSSL, Browser cert stores, Let’s EncryptHow it’s used:- Certificate chain: Tree traversal from leaf to root CA
- Path validation: DFS to verify trust path
- Revocation check: Hash map (O(1)) or binary search through CRL
- Chrome/Firefox: Certificate Transparency logs (Merkle trees)
- Chrome: Validates billions of certificates per day
- Let’s Encrypt: Issues 3M+ certificates per day
- Certificate Transparency: Merkle tree for audit logs
- Trust chain: Hierarchical CA structure
- Verification: Must validate every link in chain
- Revocation: Check CRL/OCSP (hash table lookup)
Application Security
SQL Injection Detection
SQL Injection Detection
Problem: String Parsing, FSM (Finite State Machine)
Security Tools: ModSecurity, OWASP Core Rule Set, Web Application FirewallsHow it’s used:- Pattern detection: State machine for SQL syntax
- Tokenization: Parse user input for SQL keywords
- ModSecurity: Regex + state machine for injection detection
- AWS WAF: Pre-compiled patterns for common SQLi attacks
- Context-aware: Distinguish data from code
- FSM: Efficient pattern matching in real-time
- Low false positives: Better than simple regex
Cross-Site Scripting (XSS) Prevention
Cross-Site Scripting (XSS) Prevention
Problem: String Parsing, Trie, FSM
Security Tools: DOMPurify, OWASP Java Encoder, Content Security PolicyHow it’s used:- HTML sanitization: Parse and filter dangerous tags/attributes
- DOMPurify: AST (Abstract Syntax Tree) traversal
- CSP: Trie-based domain whitelist matching
- Output encoding: State machine for context-aware escaping
- HTML structure: Nested tags = tree
- Context-aware: Different rules for different contexts
- Safe: Whitelist approach (only allow known-safe elements)
Session Management & Token Validation
Session Management & Token Validation
Problem: Hash Map, LRU Cache, Bloom Filter
Security Tools: JWT libraries, Redis session stores, API gatewaysHow it’s used:- Session lookup: Hash map for O(1) session ID → user data
- Token blacklist: Bloom filter for revoked JWTs
- Session expiry: Min heap for TTL-based cleanup
- Rate limiting: LRU cache for recent API keys
- Hash map: Fast session lookup (millions per second)
- Bloom filter: Space-efficient blacklist (1% false positive OK)
- Heap: Efficient expiry cleanup (only check oldest)
- Redis: Handles 100K+ session ops/second
- Auth0: Validates millions of JWTs per day
Password Strength & Breach Detection
Password Strength & Breach Detection
Problem: Hash Map, Bloom Filter, Trie
Security Tools: Have I Been Pwned, zxcvbn, password managersHow it’s used:- Common passwords: Bloom filter for 10M+ leaked passwords
- Have I Been Pwned: Prefix hash table (k-anonymity)
- Complexity checker: State machine for password rules
- Dictionary attack: Trie of common words to reject
- HIBP: 600M+ passwords, 10 billion checks since 2017
- Bloom filter: 10MB vs 10GB for hash table
Log Analysis & SIEM
Security Log Aggregation (Splunk, ELK)
Security Log Aggregation (Splunk, ELK)
Problem: Merge K Sorted Lists, Heap, Hash Map
Security Tools: Splunk, Elasticsearch, Datadog, Sumo LogicHow it’s used:- Log ingestion: Merge K sorted log streams from different sources
- Time-series merging: Min heap for chronological ordering
- Splunk: Distributed search across petabytes using merge
- Elasticsearch: Aggregations using bucket sort and heaps
- Splunk: Processes 100TB+ logs per day in large SOCs
- Elasticsearch: Billions of log entries, subsecond queries
- Algorithm: O(N log K) where N=total logs, K=sources
Anomaly Detection & Pattern Recognition
Anomaly Detection & Pattern Recognition
Problem: Sliding Window, Statistical Algorithms, Hash Map
Security Tools: Splunk UBA, Elastic SIEM, Microsoft SentinelHow it’s used:- Baseline learning: Sliding window calculates normal behavior
- Outlier detection: Statistical deviation using window stats
- Failed login tracking: Hash map counts per user in time window
- Beaconing detection: FFT (similar to sliding window) for periodic traffic
- Temporal context: Attacks happen over time
- Adaptive: Baselines adjust to normal changes
- Efficient: O(1) amortized per event
Threat Hunting & IoC Matching
Threat Hunting & IoC Matching
Problem: Trie, Hash Map, Bloom Filter
Security Tools: YARA, Sigma rules, MISP, OpenIOCHow it’s used:- IoC database: Hash map for fast IP/domain/hash lookups
- YARA rules: Trie + regex for malware signature matching
- Threat feeds: Bloom filter for millions of IoCs
- MISP: Graph database for threat correlation
- MISP: 100M+ threat indicators
- VirusTotal: Scans 1M+ files per day
- Bloom filter: 99% accuracy, 10x space savings
Incident Timeline Reconstruction
Incident Timeline Reconstruction
Problem: Topological Sort, Graph Algorithms
Security Tools: TimeSketch, Timelines, forensic toolsHow it’s used:- Event correlation: Graph of events with causal relationships
- Timeline construction: Topological sort of events
- Root cause analysis: BFS/DFS from initial compromise
- Attack path: Shortest path from entry to objective
Vulnerability Management
Vulnerability Scanning & Prioritization
Vulnerability Scanning & Prioritization
Problem: Graph Algorithms, Top K Elements, Heap
Security Tools: Nessus, OpenVAS, Qualys, Rapid7How it’s used:- Dependency graphs: Identify vulnerable libraries (DFS/BFS)
- Risk scoring: Min heap for top K critical vulnerabilities
- Patch priority: Topological sort for dependency-aware patching
- Attack surface: Graph traversal to find exploitable paths
- Nessus: Scans millions of hosts per day
- GitHub Dependabot: Analyzes dependency graphs for millions of repos
Penetration Testing & Exploitation
Penetration Testing & Exploitation
Problem: Graph Algorithms, BFS/DFS, Path Finding
Security Tools: Metasploit, Cobalt Strike, BloodHoundHow it’s used:- BloodHound: Graph database of AD relationships (shortest path to Domain Admin)
- Lateral movement: BFS to find paths between hosts
- Privilege escalation: Graph traversal for permission chains
- Metasploit: Decision tree for exploit selection
- Complex relationships: AD = graph with users, groups, computers
- Shortest path: Most efficient attack path
- BloodHound: Makes visible what took weeks to discover
Malware Analysis
Static Analysis & Signature Detection
Static Analysis & Signature Detection
Problem: String Matching, Trie, Hash Map
Security Tools: ClamAV, YARA, VirusTotal, IDA ProHow it’s used:- Signature database: Trie of known malware patterns
- Hash matching: Hash map for known malware hashes (SHA256)
- ClamAV: Aho-Corasick for multi-pattern matching
- Binary diffing: Longest common subsequence (LCS)
- ClamAV: 8M+ signatures, scans at 100MB/s
- VirusTotal: 70+ antivirus engines, 1M+ scans/day
Behavioral Analysis & Sandboxing
Behavioral Analysis & Sandboxing
Problem: Graph Algorithms, State Machine, DFS
Security Tools: Cuckoo Sandbox, Joe Sandbox, ANY.RUNHow it’s used:- System call graph: DFS to track malware behavior
- Process tree: Tree traversal for parent-child relationships
- Network traffic: Graph of connections (C2 detection)
- State machine: Model expected vs actual behavior
- Process tree visualization (tree traversal)
- Network graph (IP connections)
- Behavior signatures (pattern matching)
Cloud Security
IAM Policy Evaluation (AWS, Azure, GCP)
IAM Policy Evaluation (AWS, Azure, GCP)
Problem: Graph Algorithms, DFS, Set Operations
Security Tools: AWS IAM Policy Simulator, Azure RBAC, GCP IAMHow it’s used:- Permission evaluation: Graph traversal through role hierarchy
- Policy conflicts: Set intersection/union for allow/deny
- AWS IAM: DFS through groups, roles, policies
- Least privilege: Graph analysis to find excessive permissions
- AWS Access Analyzer: Graph analysis for overly permissive policies
- Azure RBAC: Role hierarchy traversal
- GCP IAM Recommender: ML + graph analysis for least privilege
Container Security Scanning
Container Security Scanning
Problem: Graph Algorithms (dependency), Hash Map, Trie
Security Tools: Trivy, Clair, Anchore, SnykHow it’s used:- Layer scanning: Hash map for known vulnerable packages
- Dependency graph: DFS to find all dependencies
- Trivy: Fast vulnerability scanning using binary search in CVE database
- Image layers: Merkle tree (hash tree) for integrity
- Docker Hub: Scans millions of images
- Trivy: Scans in seconds using optimized lookups
- CVE database: 200K+ vulnerabilities
Key Takeaways
Algorithms Protect Everything
- IDS/IPS → String matching: Snort uses tries (Aho-Corasick) for 100K+ signatures
- DDoS defense → Sliding window: Cloudflare blocks 100M+ req/sec
- Log analysis → K-way merge: Splunk merges petabytes from distributed sources
- IAM evaluation → Graph traversal: AWS IAM uses DFS through role hierarchy
- Malware detection → Pattern matching: ClamAV scans at 100MB/s using tries
- Interview: Clean input, academic setting
- Production: Noisy data, adversarial input, performance-critical
Why Security Needs These Algorithms
- Real-time processing: Network traffic at 10Gbps+ (need O(1) or O(log n))
- Massive datasets: Billions of logs, millions of threats (need efficient search)
- Adversarial input: Attackers craft worst-case inputs (need robust algorithms)
- Low false positives: Hash maps + bloom filters (99%+ accuracy)
- Resource constraints: Edge devices, IoT (need memory-efficient structures)
- Bloom filters: 1% false positive OK if saves 100x memory
- Sliding windows: Accept some inaccuracy for real-time performance
- Sampling: Check 1% of packets if full inspection impossible
Security-Specific Optimizations
- Tries: Network security (Snort, firewalls, DNS)
- Bloom filters: Threat intelligence (millions of IoCs)
- Sliding windows: DDoS, anomaly detection, rate limiting
- Heaps: Top K threats, risk scoring, log aggregation
- Graphs: IAM policies, attack paths, incident response
- Hash maps: Session management, cache, lookups
- Tries > Hash maps: When prefix matching matters (IPs, domains)
- Bloom filters > Sets: When false positives acceptable, memory limited
- Sliding windows > Full history: Real-time with bounded memory
Interview Preparation Tips
For Security Engineer Roles
For Security Engineer Roles
- Two Sum: “Like session ID lookup in authentication systems”
- Sliding Window: “Similar to DDoS rate limiting and anomaly detection”
- Trie: “Used in Snort for signature matching and firewall IP lookups”
- Graph algorithms: “Applied in IAM policy evaluation and attack path analysis”
- “How does your security team use algorithms for threat detection?”
- “What data structures power your SIEM?”
- “How do you handle real-time log analysis at scale?”
Common Security Interview Questions
Common Security Interview Questions
- Rate limiting: Implement token bucket using sliding window
- IDS signature matching: Build multi-pattern trie (Aho-Corasick)
- Log merging: Merge K sorted log streams from different sources
- Anomaly detection: Detect outliers using sliding window statistics
- Attack path finding: Shortest path in privilege escalation graph
- Password breach check: Implement Have I Been Pwned lookup
- Session management: Design LRU cache with expiration
- Snort source code - See Aho-Corasick in production
- BloodHound - Graph algorithms for security
- ClamAV - Signature matching engine
- Security blogs: Cloudflare, Trail of Bits, Google Project Zero