Mô phỏng thuật toán Cây Fenwick (BIT)

Fenwick Tree (BIT) · Nhóm: Cấu trúc dữ liệu

Cây Fenwick (BIT) (Fenwick Tree (BIT)), nhóm Cấu trúc dữ liệu.

Mã Python

def update(tree, n, i, delta):
    while i <= n:
        tree[i] += delta
        i += i & (-i)

def query(tree, i):
    s = 0
    while i > 0:
        s += tree[i]
        i -= i & (-i)
    return s

Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.