Design and Analysis of Algorithms (DAA): DNA Pattern Matching using Naive and Knuth-Morris-Pratt (KMP)
A Design and Analysis of Algorithms (DAA) project implementing Naive Pattern Matching and Knuth-Morris-Pratt (KMP) algorithms for efficient DNA sequence analysis. The project includes a C++ console application, an interactive web-based visualization dashboard, and execution time benchmarking for algorithm comparison.
This project demonstrates efficient string pattern matching techniques used in DNA sequence analysis. It compares the performance of the Naive Pattern Matching algorithm with the Knuth-Morris-Pratt (KMP) algorithm.
The project consists of:
- C++ console application
- Interactive web dashboard
- DNA sequence validation
- Random DNA sequence generation
- Pattern occurrence detection
- Performance benchmarking
- Execution time comparison
This project was developed as part of the Design and Analysis of Algorithms (DAA) course.
- β DNA sequence validation (A, C, G, T only)
- β Naive Pattern Matching
- β Knuth-Morris-Pratt (KMP) Algorithm
- β Find all pattern occurrences
- β Random DNA sequence generation
- β Performance benchmarking
- β Execution time comparison
- β Interactive console menu
- β Interactive Web Dashboard
- β Algorithm visualization
- β Performance comparison graph
- β Modular C++ implementation
- Implements both Naive and KMP algorithms.
- Compares execution time of both algorithms.
- Demonstrates practical Design and Analysis of Algorithms concepts.
- Interactive visualization using HTML, CSS and JavaScript.
- Suitable for DAA laboratory and interview preparation.
DNA-Pattern-Matching/
β
βββ CPP/
β βββ main.cpp
β
βββ web/
β βββ index_modern_dna_strict.html
β
βββ screenshots/
β βββ menu.png
β βββ pattern-matching.png
β βββ benchmark.png
β βββ web-dashboard.png
β
βββ README.md
βββ LICENSE
βββ .gitignore
The Naive algorithm compares the pattern with every possible position in the DNA sequence.
| Case | Complexity |
|---|---|
| Best | O(n) |
| Average | O(n Γ m) |
| Worst | O(n Γ m) |
KMP preprocesses the pattern using the Longest Prefix Suffix (LPS) array to avoid unnecessary comparisons.
| Phase | Complexity |
|---|---|
| LPS Construction | O(m) |
| Pattern Search | O(n) |
| Overall | O(n + m) |
| Algorithm | Best Case | Average Case | Worst Case |
|---|---|---|---|
| Naive | O(n) | O(n Γ m) | O(n Γ m) |
| KMP | O(n + m) | O(n + m) | O(n + m) |
- C++
- HTML5
- CSS3
- JavaScript
- Standard Template Library (STL)
- Chrono Library
- MT19937 Random Number Generator
============================================
DNA SEQUENCE PATTERN MATCHING PROJECT
============================================
1. Match a pattern in a DNA sequence
2. Run performance benchmark (Naive vs KMP)
3. Exit
DNA Text
ACGTACGTACGTACGT
Pattern
CGTA
Matches Found : 3
Starting Indices :
1
5
9
Text Length : 100000
Pattern Length : 20
Naive Algorithm
Matches : 2
Time : 3.18 ms
-------------------------
KMP Algorithm
Matches : 2
Time : 0.74 ms
This project helped in understanding:
- Design and Analysis of Algorithms
- String Matching Algorithms
- Naive Pattern Matching
- Knuth-Morris-Pratt (KMP)
- Longest Prefix Suffix (LPS)
- Time Complexity Analysis
- DNA Sequence Processing
- Performance Benchmarking
- Modern C++ Programming
- Boyer-Moore Algorithm
- Rabin-Karp Algorithm
- LPS Array Visualization
- Character Comparison Counter
- FASTA File Support
- CSV Report Export
- Performance Charts
- Qt Desktop GUI
- DNA Mutation Detection
g++ CPP/main.cpp -o dna./dnag++ CPP/main.cpp -o dna.exe
dna.exe- Bioinformatics
- DNA Sequence Analysis
- Genome Research
- Pattern Matching
- String Searching
- Algorithm Analysis
- Computational Biology
- Computer Science Education
- Design and Analysis of Algorithms
- DAA
- DNA Pattern Matching
- String Matching
- Naive Algorithm
- Knuth-Morris-Pratt
- KMP
- LPS
- Bioinformatics
- C++
- HTML
- JavaScript
- Algorithm Visualization
- Performance Benchmarking
Ziyaurrahman
B.Tech in Artificial Intelligence & Data Science
Arya College of Engineering & IT, Jaipur
GitHub: https://github.com/ziyaur-12
If you found this project helpful, consider giving it a β on GitHub.