I read that Fibonacci heap keeps a global node counter, but I can't see why. I even found an implementation that had the counter but didn't use it at all.
Asked
Active
Viewed 83 times
1 Answers
1
It's to make queries of the form "how many elements are in the heap?" take time O(1). Without caching this information, this query would take time O(n), since each tree would have to be traversed to count up how many nodes it contains. This is similar to why some linked list implementations keep a counter tracking the number of nodes.
Hope this helps!

templatetypedef
- 362,284
- 104
- 897
- 1,065