Skip to content

Conversation

@singhc7
Copy link
Contributor

@singhc7 singhc7 commented Jan 27, 2026

Description

This PR adds the Difference Array algorithm implementation to the existing prefixsum package.

The Difference Array is an auxiliary data structure that enables efficient range update operations. Unlike a standard array where updating a range $[L, R]$ takes $O(N)$ time, the Difference Array allows for range updates in $O(1)$ time complexity, with the final array reconstruction taking $O(N)$.

Key Features of Implementation:

  • Optimized Performance: Implements a branchless update method for constant-time operations.
  • Overflow Safety: Uses long[] internally to prevent integer overflow during intermediate range updates.
  • Comprehensive Testing: Includes a dedicated test class (DifferenceArrayTest.java) covering standard cases, edge cases (single element, full range), and stress tests (boundary conditions).
  • Documentation: Includes Javadoc with complexity analysis and a reference to Wikipedia as per contribution guidelines.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@singhc7 singhc7 force-pushed the feat/difference-array branch from 461ae11 to 97674e9 Compare January 27, 2026 19:57
@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.11%. Comparing base (2ea3873) to head (e83eb74).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7244      +/-   ##
============================================
+ Coverage     79.09%   79.11%   +0.01%     
- Complexity     6974     6985      +11     
============================================
  Files           783      784       +1     
  Lines         22950    22971      +21     
  Branches       4512     4515       +3     
============================================
+ Hits          18152    18173      +21     
  Misses         4077     4077              
  Partials        721      721              

☔ 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.

@singhc7 singhc7 force-pushed the feat/difference-array branch from 97674e9 to e83eb74 Compare January 27, 2026 20:47
@singhc7 singhc7 marked this pull request as ready for review January 27, 2026 20:51
Copy link
Member

@alxkm alxkm left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you for the contribution.

@alxkm alxkm merged commit dc3d64f into TheAlgorithms:master Jan 27, 2026
7 checks passed
@singhc7 singhc7 deleted the feat/difference-array branch January 27, 2026 21:30
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