The eighth chapter of data structure sorting job (corrected)

True or False

1-1
performs heap sort on N records, and the extra space required is O(N).

T F

Textbook P254: Heap sorting requires only a record size of auxiliary storage space for exchange, so the space complexity is O(1)

1-2
Simple selection and sorting of N records, the number of comparisons and the number of moves are O(N​^2​​) and O(N) respectively.

T F

Textbook P247;

1-3
Quickly sort N records. In the worst case, the time complexity is O(NlogN).

T F

Quickly sort N records. In the worst case, the time complexity is O(N^2);
textbook P246;

1-4
Hill sorting is a stable algorithm.

T F

Textbook P241; There is
no test site for Hill Sorting, so skip;

1-5
uses bubble sorting to sort N different data from big to small. When the elements are basically in order, the number of exchanges of elements must be the most.

T F

Textbook P243: It depends on whether "order" is positive or reverse;

1-6
To find the largest 3 values ​​from 50 key values, selection sort is faster than heap sort.

T F

doubt? ?
Textbook P267;

Multiple choice

2-1
Among the following sorting algorithms, which algorithm may appear: Before the start of the last pass, all elements are not in their final positions? (Suppose the number of elements to be arranged N>2)

A. Bubble sort
B. Insertion sort
C. Heap sort
D. Quick sort

2-2
If the data element sequence {11,12,13,7,8,9,23,4,5} is the result of the second sorting obtained by one of the following sorting methods, then the sorting algorithm can only be :

A. Bubble sort
B. Selection sort
C. Insertion sort
D. Merge sort

2-3
Sort a set of data {2,12,16,88,5,10}, if the first three rounds of sorting results are as follows: The first round of sorting results: 2,12,16,5,10,88 Second Sorting result of trip: 2, 12, 5, 10, 16, 88 Sorting result of third trip: 2, 5, 10, 12, 16, 88 The sorting method used may be:

A. Bubble sort
B. Hill sort
C. Merge sort
D. Cardinal sort

When the bubble sort is sorted from small to large, the largest number is first moved backward;

2-4 Among the
following four sorting algorithms, the stable algorithm is:

A. Heap sort
B. Hill sort
C. Merge sort
D. Quick sort

Textbook P267;
Insert picture description here

2-5
The bubble algorithm is used to sort N different data from large to small. In which case, the number of elements must be exchanged the most?

A. Arranged from small to large
B. Arranged from large to small
C. The elements are disordered
D. The elements are basically ordered

2-6
For bubble sorting of 7 numbers, the number of comparisons required is:

A.7
B.14
C.21
D.49

6+5+4+3+2+1=21;
Textbook P243: KCN = n(n-1)/2 = 7*(7-1)/2 = 21;

In the 2-7
sorting method, the method of taking out elements from the unsorted sequence and comparing them with the elements in the sorted sequence and putting them in the correct position in the sorted sequence is called:

A. Insertion sort
B. Selection sort
C. Quick sort
D. Merge sort

2-8
For a non-decreasing ordered sequence containing 10 elements , the direct insertion sort is used to arrange the non-increasing sequence, and the possible number of comparisons and the number of moves are:

A.100, 100
B.100, 54
C.54, 63
D.45, 44

Textbook P237-238: Non-decreasing ordered sequence = positive sequence, non-increasing sequence! = reverse order;
direct insertion sort:
worst case: the
number of comparisons KCN = (n+2)(n-1)/2 = (10+2 )(10-1)/2 = 12 *
9/2 = 54; number of moves RMN = (n+4)(n-1)/2 = 14 * 9/2 = 63;
best case:
number of comparisons: n -1 = 9;
number of moves: 0;
so the number should be between the two? ? ?


The sort code of 2-9 group records is {46, 79, 56, 38, 40, 84 }, then the initial heap established by the heap sort method is:

A.79,46,56,38,40,80
B.84,79,56,46,40,38
C.84,56,79,40,46,38
D.84,79,56,38,40,46

Refer to textbook P252 Example 8.6: Start screening from the last non-terminal node;
Insert picture description here

2-10
{12,9,11,8,7,4,5,13,23} Which of the following methods is the result of the second sorting?

A. Merge sort
B. Heap sort
C. Insertion sort
D. Cardinality sort

2-11
Quickly sort N records. In the worst case, the time complexity is:

AO (N)
BO (NlogN)
C.O(N^​2)
DO (N ^ 2logN)

Textbook P246;


The sort code of 2-12 group records is {46,79,56,38,40,84}, and the first division result obtained by using quick sort (based on the object at the leftmost position) is:

A.{38,46,79,56,40,84}
B.{38,79,56,46,40,84}
C.{38,46,56,79,40,84}
D.{40,38,46,56,79,84}

Textbook P244;
Steps:
Insert picture description here
Quick sort:Insert picture description here
Insert picture description here

2-13
uses simple selection sorting for N elements, the number of comparisons and the number of moves are:

A.O(N^​2​​), O(N)
BO (N), O (logN)
CO (logN), O (N ^ 2)
DO (NlogN), O (NlogN)

Textbook P247;

2-14
For a simple selection sort of 10 numbers, the number of times the elements need to be exchanged in the worst case is:

A.9
B.36
C.45
D.100

Textbook P246: In the worst case, elements are exchanged in each pass. Since there are n-1 passes for sorting, the maximum number of exchanges of elements is n-1 = 10-1 = 9 times;

2-16
To perform heap sort on N records, the additional space required is:

AO (1)
BO (logN)
CO (N)
DO (NlogN)

Textbook P254;

2-18
If the data element sequence {12, 13, 8, 11, 5, 16, 2, 9} is the result of the first sorting using one of the following sorting methods, the sorting algorithm can only be:

A. Quick sort
B. Select sort
C. Heap sort
D. Merge sort

Don't understand...

2-19
Given the keyword sequence {431, 56, 57, 46, 28, 7, 331, 33, 24, 63 }, which one of the following options is based on the second order (LSD) chain cardinality sorting for one assignment And the collected results?

A.→331→431→33→63→24→56→46→57→7→28
B.→56→28→431→331→33→24→46→57→63→7
C.→431→331→33→63→24→56→46→57→7→28
D.→57→46→28→7→33→24→63→56→431→331

There is no test center for cardinal sorting, so skip;

2-20
Sort the sequence {2, 12, 16, 88, 5, 10, 34 }. If the results of the first two passes are as follows:
after the first pass: 2, 12, 16, 10, 5, 34, 88
after the second pass: 2, 5, 10, 12, 16, 34, 88
is possible The sorting algorithm is:

A. Bubble sort
B. Quick sort
C. Merge sort
D. Insert sort

2-21
sort the sequence {2, 12, 16, 88, 5, 10, 34 }. If the results of the first two passes are as follows:
after the first pass: 2, 12, 16, 10, 5, 34, 88
after the second pass: 2, 5, 10, 12, 16, 34, 88
is possible The sorting algorithm is:

A. Bubble sort
B. Merge sort
C. Insert sort
D. Quick sort

2-22
sort the sequence {2, 12, 16, 88, 5, 10, 34 }. If the results of the first two passes are as follows:
after the first pass: 2, 12, 16, 10, 5, 34, 88
after the second pass: 2, 5, 10, 12, 16, 34, 88
is possible The sorting algorithm is:

A. Bubble sort
B. Merge sort
C. Quick sort
D. Insertion sort

2-23 The
data sequence {3, 1, 4, 11, 9, 16, 7, 28} can only be the two-pass sorting result of which of the following sorting algorithms?

A. Bubble sort
B. Quick sort
C. Insertion sort
D. Heap sort

2-24
There is an ordered sequence of 1000 elements. If another element is inserted in binary insertion sort, the maximum number of comparisons is:

A.1000
B.999
C.500
D.10

2^9 = 512;
log(1000) + 1 = 9 + 1 = 10;

2-25 When
choosing a sorting algorithm, in addition to the space-time efficiency of the algorithm, the following factors also need to be considered:
I. The scale
of the data II, the data storage method
III, the stability of the algorithm
IV, the initial state of the data

A. 仅 III
B. 仅 I 、 II
C. 仅 II 、 III 、 IV
DI 、 II 、 III 、 IV

During the
sorting process of 2-26 , processing all elements whose final positions have not been determined once is called a "pass". In the following sequence, the result of the second pass of quick sort cannot be:

A.5, 2, 16, 12, 28, 60, 32, 72
B.2, 16, 5, 28, 12, 60, 32, 72
C.2, 12, 16, 5, 28, 32, 72, 60
D.5, 2, 12, 28, 16, 32, 72, 60

First find the first middle element, satisfy that the left is smaller than him, and the right is bigger than him. The second pass is to look at the two halves of the first element, and then look for whether there is a middle element in the subsequence that satisfies the left Both are smaller than him, and the one on the right is bigger than him;

2-27
When sorting an array with most elements in order, direct insertion sort is more efficient than simple selection sort . The reasons are:
(I). There are fewer comparisons between elements in the process of direct insertion sort
(II ). Less auxiliary space is required during the direct insertion sorting process
(III). The number of movement of elements during the direct insertion sorting process is less

A. 仅 I
B. Only III
C. Only I, II
DI, II and III

Textbook P238:
(I). In the best case, compare once;
(II). The direct insertion method only needs one record auxiliary space r[0], so the space complexity is O(1);
(III). The most In good circumstances, do not move;
Textbook P247: Simple selection and sorting:
(I). No matter what the situation, the number of comparisons is n(n-1)/2;
(II). Only when two records are exchanged, an auxiliary is needed Space, so the space complexity is O(1);
(III). In the best case, no movement;
so (I). Right; (II). Same, wrong; (III). Same, wrong;

Guess you like

Origin blog.csdn.net/Jessieeeeeee/article/details/107307114