return end stableprocedure try (minteger)var wrintegerbegin if then for : to - do :wmr[ , ]if single[wstable( , ,rthen [ :wy[ :msingle[ :falsetry( + )single[ :true end end else write end end tryprocedure findstablemarriages (var stexts scanner)var mwrintegerbegin for : to - do for : to - do texts scan( )wmr[ , : irmw[mwmr[ , ]: end endfor : to - do single[ :truefor : to - do texts scan( )mwr[ , : irwm[wmwr[ , ]: end endtry( end findstablemarriages this algorithm is based on straightforward backtracking scheme its efficiency primarily depends on the sophistication of the solution tree pruning scheme somewhat fasterbut more complex and less transparent algorithm has been presented by mcvitie and wilson [ - and - ]who also have extended it to the case of sets (of men and womenof unequal size algorithms of the kind of the last two exampleswhich generate all possible solutions to problem (given certain constraints)are often used to select one or several of the solutions that are optimal in some sense in the present exampleone mightfor instancebe interested in the solution that on the average best satisfies the menor the womenor everyone notice that table indicates the sums of the ranks of all women in the preference lists of their husbandsand the sums of the ranks of all men in the preference lists of their wives these are the values rm sm < nrmwm, [mrw sm < nrwmx[ ],