114
5
2.5
答案已完成可重現的技術覆核;非官方答案。查看原始試卷

Consider the following algorithm for sorting an array of N numbers. It starts from the 1st element of the array and compares it with the 2nd element. If the 1st element is greater than the 2nd, the two elements are swapped. Then, the 2nd element is compared with the 3rd element, and the two swapped if the 2nd element is greater. The process continues until the end of the array. The entire process is repeated for the first N-1 elements, N-2, ... and so on if the array is not yet sorted. What is the worst-case time complexity to sort an array of N numbers?