You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/data_structures/fenwick.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -7,18 +7,18 @@ e_maxx_link: fenwick_tree
7
7
# Fenwick Tree
8
8
9
9
Let $f$ be some group operation (a binary associative function over a set with an identity element and inverse elements) and $A$ be an array of integers of length $N$.
10
-
Denote $f$'s infix notation as $\*$; that is, $f(x,y) = x\*y$ for arbitrary integers $x,y$.
10
+
Denote $f$'s infix notation as $*$; that is, $f(x,y) = x*y$ for arbitrary integers $x,y$.
11
11
(Since this is associative, we will omit parentheses for order of application of $f$ when using infix notation.)
12
12
13
13
The Fenwick tree is a data structure which:
14
14
15
-
* calculates the value of function $f$ in the given range $[l, r]$ $\left(\text{i.e. }A_l \* A_{l+1} \* \dots \* A_r)\right)$ in $O(\log N)$ time
15
+
* calculates the value of function $f$ in the given range $[l, r]$ $\left(\text{i.e. }A_l * A_{l+1} * \dots * A_r)\right)$ in $O(\log N)$ time
16
16
* updates the value of an element of $A$ in $O(\log N)$ time
17
17
* requires $O(N)$ memory (the same amount required for $A$)
18
18
* is easy to use and code, especially in the case of multidimensional arrays
19
19
20
20
The most common application of a Fenwick tree is _calculating the sum of a range_.
21
-
For example, using addition over the set of integers as the group operation, i.e. $f(x,y) = x + y$: the binary operation, $\*$, is $+$ in this case, so $A_l \* A_{l+1} \* \dots \* A_r = A_l + A_{l+1} + \dots + A_{r}$.
21
+
For example, using addition over the set of integers as the group operation, i.e. $f(x,y) = x + y$: the binary operation, $*$, is $+$ in this case, so $A_l * A_{l+1} * \dots * A_r = A_l + A_{l+1} + \dots + A_{r}$.
22
22
(In terms of $f$, this would be $f(A_l, f(A_{l+1}, f(f(\dots, \dots),A_r)))$, or any other equivalent way to write this using associativity.)
23
23
24
24
The Fenwick tree is also called a **Binary Indexed Tree** (BIT).
0 commit comments