This repository was developed to analyze and compare the efficiency of different string processing algorithms, focusing on pattern matching and text search techniques.
The project combines both theoretical analysis and practical implementation, providing detailed performance comparisons between algorithms through experimental benchmarks and mathematical analysis.
The following string matching algorithms are implemented and available for testing:
- Brute Force
- Knuth–Morris–Pratt (KMP)
- Boyer–Moore–Horspool (BMH)
- Shift–And
Each algorithm can be selected at runtime for direct comparison in execution time and matching accuracy.
/
|-- /build/ # Stores compiled object files (.o)
|-- /input/ # Input files containing text and pattern sequences
|-- /output/ # Output files with matching results and execution times
|-- /src/ # Source code files (.h and .c)
|-- /doc/ # Project documentation (doc.pdf)
|-- Makefile # Build configuration and automation script
|-- README.md # Project documentation and usage guide
The /doc directory contains the document doc.pdf, which presents the complete theoretical and technical analysis of the project.
The report includes:
-
Introduction
-
Code Structure and Data Handling
-
String Processing Algorithms
- Brute Force
- Knuth–Morris–Pratt (KMP)
- Boyer–Moore–Horspool (BMH)
- Shift–And
-
Result Generation and Output Files
-
Mathematical Analysis of Algorithms
-
Software Testing and Performance Comparison
-
Conclusion
-
References
To build the project, run the following command from the repository root:
makeThis command compiles all source files and generates the executable tp3 in the project root.
Run the program with:
./sma <input-file> <algorithm>-
<input-file>— The input file name (located in the/input/directory). It must follow the format:N M <N musical notes separated by spaces> <M pattern notes separated by spaces> ... 0 0Example:
16 4 D G A B C D G G G C D E F# G C C G G C D 12 2 C C# D D# E F F# G G# A A# B C D 0 0
-
<algorithm>— Specifies the search algorithm to be used:Value Algorithm 1Brute Force 2Knuth–Morris–Pratt (KMP) 3Boyer–Moore–Horspool (BMH) 4Shift–And
./tp3 input.txt 1The program generates its output in the /output/ directory.
For each test case:
S <position>→ The pattern was found starting at position<position>.N→ The pattern was not found in the text.
Contains timing information (in microseconds) for all test cases executed with the chosen algorithm. New benchmark results are appended, preserving previous data.
Example:
Algorithm CPU usage: 0.000012s
Algorithm Time spent: 0.000014s
Brute Force CPU usage: 0.000018s
Brute Force Time spent: 0.000019s
KMP CPU usage: 0.000018s
KMP Time spent: 0.000019s
BMH CPU usage: 0.000000s
BMH Time spent: 0.000014s
Shift–And CPU usage: 0.000015s
Shift–And Time spent: 0.000016sTo remove all compiled files and the executable, use:
make cleanThis deletes all files in /build/ and removes the tp3 executable from the root directory.
- Operating System: Linux (recommended)
- The project uses Unix-specific commands and libraries, which may require adaptation to run on Windows (e.g., changes in the
Makefileand library dependencies).
This project was developed for educational purposes as part of a course in Algorithm Analysis and Design.
Authors:
- Caio Augusto Reis
- Kariny Mylena Abrahão