Content area

Abstract

Fenwick trees, also known as binary indexed trees are a clever solution to the problem of maintaining a sequence of values while allowing both updates and range queries in sublinear time. Their implementation is concise and efficient—but also somewhat baffling, consisting largely of nonobvious bitwise operations on indices. We begin with segment trees, a much more straightforward, easy-to-verify, purely functional solution to the problem, and use equational reasoning to explain the implementation of Fenwick trees as an optimized variant, making use of a Haskell EDSL for operations on infinite two’s complement binary numbers.

Details

Subject
Title
You could have invented Fenwick trees
Author
Yorgey, Brent 1   VIAFID ORCID Logo 

 Hendrix College, 1600 Washington Ave, Conway, AR 72032, USA (e-mail: [email protected]
Publication title
Volume
35
Publication year
2025
Publication date
Jan 2025
Section
Functional Pearl
Publisher
Cambridge University Press
Place of publication
Cambridge
Country of publication
United Kingdom
ISSN
09567968
e-ISSN
14697653
Source type
Scholarly Journal
Language of publication
English
Document type
Journal Article
Publication history
 
 
Online publication date
2025-01-17
Milestone dates
2023-12-23 (Received); 2024-07-11 (Revised); 2024-11-05 (Accepted)
Publication history
 
 
   First posting date
17 Jan 2025
ProQuest document ID
3156319946
Document URL
https://www.proquest.com/scholarly-journals/you-could-have-invented-fenwick-trees/docview/3156319946/se-2?accountid=208611
Copyright
© The Author(s), 2025. Published by Cambridge University Press. This work is licensed under the Creative Commons Attribution License This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited. (the “License”). Notwithstanding the ProQuest Terms and Conditions, you may use this content in accordance with the terms of the License.
Last updated
2025-01-17
Database
ProQuest One Academic