CH 18 CSCI

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

F

(T/F) During the second iteration of a selection sort, the smallest item is moved to the top of the list.

T

(T/F) During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted.

F

(T/F) If n = 1000, then to sort the list, selection sort makes about 50,000 key comparisons.

F

(T/F) In a binary search, first, the search item is compared with the last element of the list.

F

(T/F) In a bubble sort, the smaller elements move toward the bottom, and the larger elements move toward the top of the list.

T

(T/F) Suppose that L is a sorted list of size 1024, and we want to determine whether an item x is in L. From the binary search algorithm, it follows that every iteration of the while loop cuts the size of the search list by half.

T

(T/F) The binary search algorithm can be written iteratively or recursively.

T

(T/F) The selection sort algorithm finds the location of the smallest element in the unsorted portion of the list.

T

(T/F) The sequential search algorithm does not require that the list be sorted.

F

(T/F) The swap function of quick sort is written differently from the swap function for selection sort.

C

A sequential search of an n-element list takes ____ key comparisons if the item is not in the list. a. 0 c. n b. n/2 d. n2

B

A sequential search of an n-element list takes ____ key comparisons on average to determine whether the search item is in the list. a. 0 c. n b. n/2 d. n2

A

After the second iteration of bubble sort for a list of length n, the last ____ elements are sorted. a. two c. n-2 b. three d. n

C

Assume that list consists of the following elements. What is the result after bubble sort completes? int list[] = {2, 56, 34, 25, 73, 46, 89, 10, 5, 16}; a. 89 73 56 46 34 25 16 10 5 2 b. 2 56 34 25 5 16 89 46 73 c. 2 5 10 16 25 34 46 56 73 89 d. 2 10 16 25 34 46 56 73 89

A

Assuming the following list declaration, which element is at the position 0 after the first iteration of selection sort? int list[] = {16, 30, 24, 7, 62, 45, 5, 55} a. 5 c. 16 b. 7 d. 62

D

Consider the following list: int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search for 75, after the first comparison, the search is restricted to ____. a. list[0]...list[6] b. list[0]...list[7] c. list[5]...list[11] d. list[6]...list[11]

C

Consider the following list: int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search, the target is first compared with ____. a. 4 c. 39 b. 25 d. 95

B

For a list of length n, insertion sort makes ____ key comparisons, in the worst case. a. n(n - 1)/4 c. n2 b. n(n - 1)/2 d. n3

B

For a list of length n, selection sort makes ____ item assignments. a. n(n - 1)/2 c. 3(n) b. 3(n - 1) d. 4(n + 1)

D

If a list of eight elements is sorted using selection sort, the unsorted list is ____ after the second iteration. a. list[0] ... list[1] b. list[0] ... list[6] c. list[1] ... list[7] d. list[2] ... list[7]

C

If n = 1000, to sort the list, bubble sort makes about ____ item assignments. a. 10,000 b. 100,000 c. 250,000 d. 500,000

C

In a bubble sort for list of length n, the first step is to compare elements ____. a. list[0] and list[n] b. list[0] and list[n-1] c. list[0] and list[1] d. list[n-1] and list[n+1]

C

In the average case, sequential search typically searches ____. a. one quarter of the list b. one third of the list c. one half of the list d. the entire list

D

In the bubble sort algorithm, the following code accomplishes swapping values in elements at positions index and index + 1. a. list[index] = list[index + 1] list[index + 1] = list[index] b. list[index + 1] = list[index] list[index] = list[index + 1] c. list[index] = temp; list[index] = list[index + 1]; temp = list[index + 1]; d. temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;

A

The behavior of merge sort is ____ in the worst case and ____ in the average case. a. O(nlog2n), O(nlog2n) b. O(n^2), O(n) c. O(nlog2n), O(n^2) d. O(n^2), O(nlog2n)

D

The behavior of quick sort is ____ in the worst case and ____ in the average case. a. O(nlog2n), O(nlog2n) b. O(n^2), O(n) c. O(nlog2n), O(n^2) d. O(n^2), O(nlog2n)

C

The formula to find the index of the middle element of a list is ____. a. (mid + last)/2 b. (first + last) - 2 c. (first + last) / 2 d. (first + mid ) * 2

B

The sequential search algorithm uses a(n) ____ variable to track whether the item is found. a. int b. bool c. char d. double

C

We can trace the execution of a comparison-based algorithm by using a graph called a ____. a. pivot table b. partition table c. comparison tree d. merge tree

D

When moving array values for insertion sort, to move list[4] into list[2], first ____. a. move list[2] to list[3] b. delete list[2] c. move list[4] to list[3] d. copy list[4] into temp

C

When working with the unsorted portion of a list, the second step in a selection sort is to ____. a. divide the list into two parts b. move the smallest element to the top of the list (position 0) c. move the smallest element to the beginning of the unsorted list d. find the smallest element

C

Which of the following correctly states the quick sort algorithm? a. if (the list size is greater than 1) { a. Partition the list into four sublists. b. Quick sort sublist1. c. Quick sort sublist2. d. Quick sort sublist3. e. Quick sort sublist4. d. Combine the sorted lists. } b. a. Find the location of the smallest element. b. Move the smallest element to the beginning of the unsorted list. c. if (the list size is greater than 1) { a. Partition the list into two sublists, say lowerSublist and upperSublist. b. Quick sort lowerSublist. c. Quick sort upperSublist. d. Combine the sorted lowerSublist and sorted upperSublist. } d. if the list is of a size greater than 1 { a. Divide the list into two sublists. b. Merge sort the first sublist. c. Merge sort the second sublist. d. Merge the first sublist and the second sublist. }

B

With insertion sort, the variable firstOutOfOrder is initialized to ____, assuming n is the length of the list. a. 0 c. n - 1 b. 1 d. n

A

With the binary search algorithm, ____ key comparison(s) is/are made in the successful case—the last time through the loop. a. one c. n-2 b. two d. n

A

____ sort requires knowing where the middle element of the list is. a. Merge b. Bubble c. Insertion d. Selection


संबंधित स्टडी सेट्स

Course Point Psych Chapter 20 Practice Questions

View Set

Biology - Unit II Module 1 and 2

View Set

Chapter 18.3 Formed elements in the blood

View Set

Human Resources Management Final

View Set

Chemical Reactions and Stoichiometry

View Set

Life and Health - Chapter 4 Quiz - Life Policy Provisions and Options

View Set