homework 4, O(h)