pseudocode for BPM algorithm