updown algorithm