Skip to content
Computing Medium #fenwick#bit#prefix-sum

Fenwick (BIT): Implicit Range Sums

A single array encodes prefix sums via low-bit indexing. Range sums and updates in O(log n).

A free, animated fenwick (bit): implicit range sums you can read here or embed on any website, from Scrollchart.

Fenwick (BIT): Implicit Range Sums

Fenwick Tree (Binary Indexed Tree)BIT[i] covers span = i & -i; prefix query up to 6 visits 3 nodes; update at 3 visits 3 nodes

A Fenwick tree visualized as overlapping intervals indexed by lowest set bit. Update walks i += i & -i; query walks i -= i & -i. Tighter than segment tree for prefix-sum problems.

Good for

  • Competitive programming deep-dives on prefix-sum structures
  • Order-statistic and inversion-count explainers using BIT
  • Comparison articles contrasting Fenwick vs segment tree trade-offs

Source & accuracy

This fenwick (bit): implicit range sums is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

How a Fenwick tree (binary indexed tree) works

A Fenwick tree, also called a binary indexed tree (BIT), stores cumulative information in a single array so that prefix sums and point updates both run in O(log n) time. Each index i is responsible for a range of elements whose length equals the value of the lowest set bit of i, written i and (-i) in two's complement arithmetic. This low-bit decomposition is what lets the structure walk the array in logarithmic steps rather than linear ones.

To query a prefix sum up to index i, you repeatedly add the value at i and then strip its lowest set bit until you reach zero. To update an element, you move in the opposite direction, adding the low bit each step.

Where it is used

Fenwick trees are common in competitive programming and in systems needing frequent range-sum queries with updates, such as counting inversions, dynamic frequency tables, and order statistics. Compared with a segment tree, a BIT uses less memory and has shorter code, but it natively supports only invertible operations like sums; a segment tree is more flexible for operations like minimum or maximum. A range sum from l to r is computed as prefix(r) minus prefix(l-1).

Embed this diagram

Add this animated fenwick (bit): implicit range sums to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated fenwick (bit): implicit range sums for any website.
Who uses it
Developer blogs, CS educators.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="fenwick-tree" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Fenwick (BIT): Implicit Range Sums" for my website?
Scrollchart provides "Fenwick (BIT): Implicit Range Sums" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a fenwick (bit): implicit range sums in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.