Designing reliable algorithms in unreliable memories