Replaced calcNumThresholdedNodes with iterator traversal