算法导论第三版答案
SolutiontoExercise2.2-2
SELECTION-SORT.A/
nDA:length
forjD1ton 1
smallestDj
foriDjC1ton
ifA i <A smallest
smallestDi
exchangeA j withA smallest
Thealgorithmmaintainstheloopinvariantthatatthestartofeachiterationoftheouterforloop,thesubarrayA 1::j 1 consistsofthej 1smallestelementsinthearrayA 1::n ,andthissubarrayisinsortedorder.Afterthe rstn 1elements,thesubarrayA 1::n 1 containsthesmallestn 1elements,sorted,andthereforeelementA n mustbethelargestelement.
Therunningtimeofthealgorithmis .n2/forallcases.
你可能喜欢
- 计算机导论第三版答案
- 算法导论第三版
- 算法导论第二版答案
- 算法导论第三章答案
- 计算机导论复习题答案2页
- 计算机导论复习题答案13页
- 计算机导论第二版答案16页
- 大一计算机导论答案[1]14页
- 计算机导论(第三版)复习2页
- 计算机导论第三版第一章29页
- 算法导论第三版课后答案 2-25章64页
- 算法导论第三版新增27章中文版46页
- 算法导论第三版新增27章中文版46页
- 算法导论第三版新增27章中文版46页
- 算法导论第三版答案70页
- 算法导论第三版52页