The following is the main part of insertion sort pseudocode: for i := 1 to n-1 insert a[i] into sorted sublist {a[0],...,a[i-1]} so that the sortedness is still kept. end for Select the most correct solution: Consider the list of ten integers below: 16, 5, 2, 11, 10, 8, 12, 3, 8, 6 What is the list after the FIRST TWO steps of insertion sort? (sorting from smallest to largest).
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "2, 5, 16, 11, 10, 8, 12, 3, 8, 6". Sắp xếp chèn giữ một đoạn đầu đã có thứ tự rồi mỗi bước lấy phần tử kế tiếp chèn vào đúng chỗ trong đoạn đó, các phần tử phía sau không bị động tới. Bước thứ nhất lấy 5 chèn vào đoạn chỉ có 16, cho 5, 16; bước thứ hai lấy 2 chèn vào đoạn 5, 16, cho 2, 5, 16, nên bảy phần tử cuối vẫn y nguyên như lúc đầu. Dãy "2, 3, 16, 11, 10, 8, 12, 5, 8, 6" là trạng thái sau hai lượt sắp xếp chọn, tức đổi chỗ 2 với 16 rồi đổi chỗ 3 với 5, vì thế 5 bị bắn về chỗ của 3. Dãy "2, 3, 5, 11, 10, 8, 12, 16, 8, 6" là sau ba lượt sắp xếp chọn, đã đưa cả 2, 3, 5 về đầu và đẩy 16 vào giữa mảng, đi xa hơn hẳn hai bước được hỏi. Dãy "2, 5, 11, 10, 8, 12, 3, 8, 6, 16" mang 16 ra hẳn cuối mảng, đó là dấu vết của một lượt nổi bọt, còn phép chèn không hề dồn phần tử lớn nhất về cuối chỉ sau hai bước.
Cùng phần 6
The following is the main part of selection sort pseudocode:
for i := 0 to n-2 // large loop
find a[k], where a[k] = min {a[i], a[i+1],...,a[n-1]}
if k # i then swap a[i] with a[k]
end for
Consider the list of ten integers below:
7, 5, 11, 12, 3, 10, 2, 4, 8, 6
What is the list after the FIRST TWO iterations of the large loop in a selection sort? (sorting from smallest to largest).Có lời giảiCâu hỏiSelect the most correct statement about the complexity of mergesortCó lời giảiCâu hỏiPartitioning is a technique used in quicksort. The following is a partition pseudocode for sorting from smallest to largest:
partition the array a from index low to index up
x := a[low], i=low, j=up
do
increase i and stop at i, where a[i]>x
decrease j and stop at j, where a[j]<=x
if(i<j) swap a[i] with a[j]
while(i<j)
swap a[low] with a[j]
Consider the list of eight integers (n=8) below:
15, 13, 18, 19, 17, 12, 16, 14
What is the list after it is partitioned with low = 0 and up = n-1?Có lời giảiCâu hỏiCả 20 câu của chủ đề20 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây