Skip to content

Added Freivalds' Algorithm for randomized matrix multiplication verification - #6340

Merged
siriak merged 2 commits into
TheAlgorithms:masterfrom
aditya-7562:freivalds-algorithm
Jul 4, 2025
Merged

Added Freivalds' Algorithm for randomized matrix multiplication verification#6340
siriak merged 2 commits into
TheAlgorithms:masterfrom
aditya-7562:freivalds-algorithm

Conversation

@aditya-7562

Copy link
Copy Markdown
Contributor

Summary

Added Freivalds' Algorithm under the randomized category as part of issue [#6219]

This algorithm offers a fast, probabilistic method to verify whether matrix multiplication A × B = C holds true, avoiding full recomputation of the product.


🧠 Randomized Algorithm Approach

  • Generate a random binary vector r
  • Perform matrix-vector multiplications and check if:
    A × (B × r) ≟ C × r
  • Repeat this process k times to reduce the probability of error
  • Probability of false positives becomes ≤ 1/2^k

⏱ Time Complexity

  • Per iteration: O(n²)
  • Total expected time: O(k × n²)
    (significantly faster than recomputing A × B, which is O(n³))

✅ Use Cases

  • Verifying matrix multiplication in:
    • Scientific computing workflows
    • Distributed computing systems
    • Cloud infrastructure and audit pipelines
  • Faster correctness checks in:
    • Numerical linear algebra
    • Cryptographic or zero-knowledge systems

📋 Checklist

  • I have read CONTRIBUTING.md
  • This pull request is entirely my work (no plagiarism)
  • All filenames follow PascalCase convention
  • All function and variable names follow Java naming conventions
  • Code has been formatted using:
    clang-format -i --style=file path/to/your/file.java

@codecov-commenter

codecov-commenter commented Jul 4, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.37%. Comparing base (712ada5) to head (e1af216).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6340      +/-   ##
============================================
+ Coverage     74.33%   74.37%   +0.04%     
- Complexity     5392     5403      +11     
============================================
  Files           679      680       +1     
  Lines         18820    18842      +22     
  Branches       3646     3656      +10     
============================================
+ Hits          13990    14014      +24     
+ Misses         4274     4273       -1     
+ Partials        556      555       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak
siriak merged commit 58ac54c into TheAlgorithms:master Jul 4, 2025
6 of 7 checks passed
@aditya-7562
aditya-7562 deleted the freivalds-algorithm branch July 4, 2025 13:49
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.

3 participants