Skip to content

Conversation

@AliAlimohammadi
Copy link

Description

This PR adds the Smith-Waterman algorithm implementation to the dynamic_programming directory.

Algorithm Overview

The Smith-Waterman algorithm is a dynamic programming algorithm for determining similar regions between two sequences (nucleotide or protein sequences). It performs local sequence alignment and is particularly useful in bioinformatics.

Key Features:

  • Local alignment: Finds the best matching subsequence rather than aligning entire sequences
  • Dynamic programming: O(m×n) time complexity where m and n are sequence lengths
  • Configurable scoring: Supports custom match, mismatch, and gap penalties
  • Traceback functionality: Reconstructs the optimal alignment

Implementation Details:

  • score_function: Calculates alignment scores for character pairs
  • smith_waterman: Builds the scoring matrix using dynamic programming
  • traceback: Reconstructs the optimal alignment from the scoring matrix

Code Quality

The implementation follows TheAlgorithms/C-Plus-Plus standards:

  • ✅ Doxygen-style documentation
  • ✅ Namespace organization (dynamic_programming::smith_waterman)
  • ✅ Modern C++ practices (C++11 and above)
  • ✅ STL usage (no bits/stdc++.h)
  • ✅ Comprehensive self-tests (8 test cases)
  • ✅ Example usage in main function

Testing

The implementation includes 8 comprehensive test cases:

  • ✅ Simple exact match
  • ✅ Partial match
  • ✅ Traceback verification
  • ✅ No match scenario
  • ✅ Empty string handling
  • ✅ Sequences with gaps
  • ✅ Custom scoring parameters
  • ✅ Case sensitivity

All tests pass:

g++ -std=c++11 -O2 -Wall dynamic_programming/smith_waterman.cpp -o smith_waterman
./smith_waterman

Documentation

  • Detailed file-level Doxygen documentation
  • Function-level documentation with parameters and returns
  • Algorithm explanation with complexity analysis
  • References to original paper and Wikipedia

Checklist

  • Algorithm implementation is correct
  • All tests pass locally
  • Code follows C++ best practices
  • Uses standard library (no bits/stdc++.h)
  • Organized with namespace
  • Doxygen documentation complete
  • No compiler warnings
  • Added to appropriate directory (dynamic_programming)
  • Example usage provided

References

@AliAlimohammadi
Copy link
Author

@dynamitechetan, This PR is ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant