what is pen and pencil algorithm