← 回題庫

卷別

資料結構

選擇

國立中央大學 2026 · 考試 · 第 39 題

The following piece of code is a version of Insertion Sort Algorithm that works on data stored in an array. Please read the following code and find which description given in (A) to (E) is WRONG or the least accurate statement?

 1  void insertionSort1(int arr[], int n) {
 2      for(int i=0; i<n; ++i) {
 3          int key=arr[i];
 4          int j=i-1;
 5          while(j>=0 && arr[j]>key){
 6              arr[j+1]=arr[j];
 7              j=j-1;
 8          }
 9          arr[j+1]=key;
10      }
11  }
  • (A)
    It is in-place.
  • (B)
    It is stable.
  • (C)
    Computation complexity is O(n²)
  • (D)
    The number of comparisons can be reduced with binary search.
  • (E)
    The sequential search of insertion locations can be improved if a linked list is implemented.

標準解析

AI 生成