Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

fenwick-tree

Fenwick tree vs Segment tree

April 8, 2024 by Tarik

I read this on Quora. Hope you find it useful. There are things that a segment tree can do but a BIT cannot : A BIT essentially works with cumulative quantities. When the cumulative quantity for interval [i..j] is required, it is found as the difference between cumulative quantities for [1…j] and [1…i-1]. This works … Read more

Categories algorithm Tags algorithm, fenwick-tree, segment-tree, tree Leave a comment

Is it possible to build a Fenwick tree in O(n)?

December 5, 2023 by Tarik

[EDIT: I had things “upside-down” — fixed now!] Yes. Loop through the n array items in increasing index order, always adding the sum only to the next smallest index that it should be added to, instead of to all of them: for i = 1 to n: j = i + (i & -i) # … Read more

Categories algorithm Tags algorithm, fenwick-tree Leave a comment

What does (number & -number) mean in bit programming? [duplicate]

March 7, 2023 by Tarik

Let me assume that negative value is represented using two’s complement. In this case, -i can be calculated as (~i)+1 (flip bits, then add 1). For example, let me consider i = 44. Then, in binary, i = 0000 0000 0000 0000 0000 0000 0010 1100 ~i = 1111 1111 1111 1111 1111 1111 1101 … Read more

Categories c++ Tags bit, bitwise-and, c++, fenwick-tree Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa