Binary Indexed Tree / Fenwick Tree

树状数组(Binary Indexed Tree,也称为Fenwick Tree)作为一种高效的数据结构,主要用于区间查询和动态更新数据。

Fenwick Tree(芬威克树)得名于其发明者 Peter M. Fenwick(彼得·梅隆·芬威克),一位计算机科学家。他在1994年首次提出了这种数据结构,并以论文"A New Data Structure for Cumulative Frequency Tables" 的形式发表了这一成果。因为这种数据结构在处理累积频率表和其他区间查询问题上表现出了高效性,所以后来人们便以他的姓氏 Fenwick 来命名,以表彰他的贡献。

以下是论文摘要

A new method (the ‘binary indexed tree’) is presented for maintaining the cumulative frequencies which are needed to support dynamic arithmetic data compression. It is based on a decomposition of the cumulative frequencies into portions which parallel the binary representation of the index of the table element (or symbol). The perations to traverse the data structure are based on the binary coding of the index. In comparison with previous methods, the binary indexed tree is faster, using more compact data and simpler code. The access time for all operations is either constant or proportional to the logarithm of the table size. In conjunction with the compact data structure, this makes the new method particularly suitable for large symbol alphabets.