简体   繁体   中英

Why is insertion sort "decrease and conquer" whereas selection sort is "brute force"?

Why are insertion sort algorithms also not considered brute force algorithms? Don't they systematically look through every value of the array as well? I undertand that selection sort has a worst best-case time complexity, but I'm still not fully understanding the differentiation between a brute-force algorithm and a decrease-and-conquer algorithm. Sorry if this is a stupid question. Thanks!

Both insertion and selection sort might be called “decrease and conquer” because at every step of outer loop they treat smaller and smaller part of array.

Formally speaking, in these sorts loop invariant condition is that the subarray A[0 to i-1] is always sorted .

I have not met “brute force” term in application to sorting algorithms, it looks like nonsense. Brute force algorithms usually check all possible variants and choose the best one. It is possible to generate all permutations of an array or list and choose sorted one - this kind of sortinh might be called "stupid sort" or something like .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM