updates tree and heap