Tagged articles

Fenwick tree

2 articles · Page 1 of 1
YiSu Grain
YiSu Grain
Oct 29, 2024 · Fundamentals

Why This Design Works and How a Fenwick Tree Simplifies Inversion Counting

The article explains what inversion pairs are, demonstrates a naïve O(n²) counting method, then introduces a smarter right‑to‑left approach using a Fenwick (Binary Indexed) tree with discretization to achieve efficient O(n log n) inversion counting, providing full Python implementations and step‑by‑step examples.

Binary Indexed TreeFenwick treePython
0 likes · 7 min read
Why This Design Works and How a Fenwick Tree Simplifies Inversion Counting
YiSu Grain
YiSu Grain
Oct 23, 2024 · Fundamentals

Understanding Fenwick Tree: A Step‑by‑Step Guide

This article explains how a Fenwick (Binary Indexed) Tree stores prefix sums using binary representations and the least‑significant‑bit trick, shows concrete examples for computing sums of sub‑arrays, and provides a full Python implementation with update and query operations.

Binary Indexed TreeData StructureFenwick tree
0 likes · 9 min read
Understanding Fenwick Tree: A Step‑by‑Step Guide