Bogart-81046bookApril 27, 200517:121COUNTING1.1BASIC COUNTINGPages 7 to 8Problem 1SolutionThe value ofiranges from 2 ton. Wheni=k, the variablejranges from 2 tok.Thus, there are at mostk−1 comparisons (because we stop ifj=2). Thus, the totalnumber of comparisons is1+2+ · · · +n−1=n(n−1)2.The algorithm will make this number of comparisons if the original ordering is thereverse of the sorted ordering.Problem 2SolutionNumber the five teams 1–5. Team 1 must play all four others. Team 2 will be in oneof these games but must play in three more games with Teams 3, 4, and 5. Team 3is in two of the games already mentioned and must still play Teams 4 and 5 fortwo more games. Team 4 must play Team 5, in addition to playing in three of thegames already mentioned. Thus, there are 4+3+2+1=10 games. Alternatively,there are five teams, each of which must play in four games, giving us 20 pairingsof two teams each. However, each game involves two of these pairings, so there are20/2=10 games.S1Preview Mode
This document has 145 pages. Sign in to access the full document!
