The time bound for max is O(1). This is because, under the invariant, A[0] is always the maximum.

Implementation of remove to preserve the invariant: A[0] is the element to be removed. Say that A[n-1] is the last element in the heap. To restore the invariant, we set A[0] = A[n-1], then decrease n by 1, then "play the game" of comparing the root to its two children, moving the greater of the three to the parent position. If a child is greater, we play the game with the child, and so on down the tree until we reach a leaf. The heap invariant is then restored. The number of steps this takes is proportional to the longest path in the tree, which is O(log n).

Implementation of insert to preserve the invariant: We add the new element to the array as A[n], then increase n by 1. In order to restore the invariant, we have to "play the game" of comparing the new element against its parent and its parent's other child, if any. The larger element moves to the top of the three. We then repeat this process, working up the tree toward the root. As before, the number of steps is proportional to the longest path, so again we have O(log n).