4.1: pseudocode