summaryrefslogtreecommitdiff
path: root/datastructures/fenwickTree.cpp
diff options
context:
space:
mode:
authorJosh Tari <joshtari@yahoo.com>2016-09-16 11:28:09 +0200
committerGitHub <noreply@github.com>2016-09-16 11:28:09 +0200
commitf99e41c0a45ad2a9d7cf422fc0c65546c53da0b7 (patch)
tree6c9a3ad655c79d930d861b75197df6c8960700ab /datastructures/fenwickTree.cpp
parent6679f0299d4d1a36b4fcda2de8c9c7065c7c9ba5 (diff)
Update fenwickTree.cpp
Verschieben update an richtige Stelle
Diffstat (limited to 'datastructures/fenwickTree.cpp')
-rw-r--r--datastructures/fenwickTree.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/datastructures/fenwickTree.cpp b/datastructures/fenwickTree.cpp
index 3b54fc9..cd30329 100644
--- a/datastructures/fenwickTree.cpp
+++ b/datastructures/fenwickTree.cpp
@@ -1,6 +1,11 @@
vector<int> FT; //Fenwick-Tree
int n;
+//Adds val to index i. Time Complexity 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))
void buildFenwickTree(vector<int>& a) {
n = a.size();
@@ -14,9 +19,3 @@ int prefix_sum(int i) {
while(i > 0) { sum += FT[i]; i -= (i & (-i)); }
return sum;
}
-
-//Adds val to index i. Time Complexity O(log(n))
-void updateFT(int i, int val) {
- i++; while(i <= n) { FT[i] += val; i += (i & (-i)); }
-}
-