refactor build_heap method to work in log(n) time