TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Fenwick Trees

42 点作者 siddcoder将近 10 年前

3 条评论

minaguib将近 10 年前
BTW, to reason a bit about this statement in a simpler fashion: &quot;any natural number “K” can be obtained from sum of other natural numbers (less than K), where these natural numbers are powers of 2&quot;<p>Think what you&#x27;re doing mentally when converting a binary number to decimal. For example: 101001<p>Each one of those 1s represents 2^position, all added together, so:<p><pre><code> 41 = 32 (100000 = 2^5) + 8 ( 1000 = 2^3) + 1 ( 1 = 2^0) </code></pre> Since any natural number can be represented in decimal and binary, the rule applies that each binary 1 is the value of 2^that position, all summed up.
评论 #10077696 未加载
jefftchan将近 10 年前
Great post! I found Fenwick trees particularly useful when I was implementing layout &#x2F; view recycling. The problem is that you need to keep track of a large number of vertically stacked elements with dynamic &amp; varying heights, and you need a way to efficiently get the prefix sum. Would be curious if anyone else has real life use cases of these.
评论 #10078045 未加载
upjat将近 10 年前
Awesome Post :) Very well written !!