Skip to content

feat: add Fenwick Tree implementation with tests - #1897

Open
tanjumul wants to merge 1 commit into
TheAlgorithms:masterfrom
tanjumul:add-fenwick-tree
Open

feat: add Fenwick Tree implementation with tests#1897
tanjumul wants to merge 1 commit into
TheAlgorithms:masterfrom
tanjumul:add-fenwick-tree

Conversation

@tanjumul

Copy link
Copy Markdown

Open in Gitpod know more

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example: User个人资料.js is allowed but userprofile.js,Userprofile.js,user-个人资料.js,user个人资料.js are not
  • All new algorithms have a URL in their comments that points to 维基pedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Summary

This PR adds a Fenwick Tree (Binary Indexed Tree) implementation to the Data-Structures/Tree directory and the test files as well.

Features

  • Point updates in O(log n)
  • Prefix sum queries in O(log n)
  • Range sum queries in O(log n)
  • Build tree from existing array
  • Get/Set operations

Testing

  • Comprehensive unit tests included
  • Edge cases covered (empty tree, single element, negative values)

@tanjumul
tanjumul requested a review from appgurueu as a code owner May 15, 2026 14:07
@codecov-commenter

codecov-commenter commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.95%. Comparing base (5c39e87) to head (e4a046e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1897      +/-   ##
==========================================
+ Coverage   85.91%   85.95%   +0.03%     
==========================================
  Files         379      380       +1     
  Lines       19778    19834      +56     
  分支     3016     3028      +12     
==========================================
+ Hits        16993    17049      +56     
  Misses       2785     2785              

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

🚀 新建 features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

标签

None yet

项目

None yet

Development

Successfully merging this pull request may close these issues.

2 participants