summaryrefslogtreecommitdiff
path: root/datastructures/fenwickTree.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2016-10-02 18:49:19 +0200
committerPaul Jungeblut <paul.jungeblut@gmail.com>2016-10-02 18:49:19 +0200
commit0ab75cddde1c959fe434c6554f1d3e1ed2719780 (patch)
tree9cf1d5f5a46ec60edf65c8a8b002ece7d89bf89e /datastructures/fenwickTree.cpp
parent3ef01f79baa2dd8c391e31c2a6fd02b97cdb75ec (diff)
Optical improvements of the datastructures section.
Diffstat (limited to 'datastructures/fenwickTree.cpp')
-rw-r--r--datastructures/fenwickTree.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/datastructures/fenwickTree.cpp b/datastructures/fenwickTree.cpp
index cd30329..86b1138 100644
--- a/datastructures/fenwickTree.cpp
+++ b/datastructures/fenwickTree.cpp
@@ -1,19 +1,19 @@
-vector<int> FT; //Fenwick-Tree
+vector<int> FT; // Fenwick-Tree
int n;
-//Adds val to index i. Time Complexity O(log(n))
+// Addiert val zum Element an Index i. O(log(n)).
void updateFT(int i, int val) {
i++; while(i <= n) { FT[i] += val; i += (i & (-i)); }
}
-//Build an Fenwick-Tree over an array a. Time Complexity: O(n*log(n))
+// Baut Baum auf. O(n*log(n)).
void buildFenwickTree(vector<int>& a) {
n = a.size();
FT.assign(n+1,0);
for(int i = 0; i < n; i++) updateFT(i,a[i]);
}
-//Prefix-Sum of intervall [0..i]. Time Complexity: O(log(n))
+// Präfix-Summe über das Intervall [0..i]. O(log(n)).
int prefix_sum(int i) {
int sum = 0; i++;
while(i > 0) { sum += FT[i]; i -= (i & (-i)); }