BTE320 Chapter 18

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Let f and g be real-valued functions. Assume that f and g are nonnegative, that is, for all real numbers n, f (n) 0 and g(n) 0. We say that f (n) is ____________________ of g(n), written f (n) = O(g(n)), if there exist positive constants c and n0 such that f (n) cg(n) for all n n0 .

ANSWER: Big-O

Let f be a function of n. By the term ____________________, we mean the study of the function f as n becomes larger and larger without bound.

ANSWER: asymptotic

A comparison tree is a(n) ____________________ tree.

ANSWER: binary

The ____________________ search algorithm is the optimal worst-case algorithm for solving search problems by using the comparison method.

ANSWER: binary

To construct a search algorithm of the order less than log2n, it cannot be ____________________ based.

ANSWER: comparison

38. For a list of length n, the bubble sort makes exactly ____________________ key comparisons.

ANSWER: n(n-1)/2

In a quick sort, all of the sorting work is done by the function ____________________.

ANSWER: partition

A sequence of branches in a comparison tree is called a(n) ____________________.

ANSWER: path

The first step in the quick sort partition algorithm is to determine the ____________________ and swap it with the first element in the list.

ANSWER: pivot

The top node of a comparison tree is call the ____________________ node.

ANSWER: root

If n = 1000, then to sort the list, selection sort makes about 50,000 key comparisons. a. True b. False

False

In a binary search, first, the search item is compared with the last element of the list. a. True b. False

False

In a bubble sort, the smaller elements move toward the bottom, and the larger elements move toward the top of the list. a. True b. False

False

The swap function of quick sort is written differently from the swap function for selection sort. a. True b. False

False

During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted. a. True b. False

True

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. a. True b. False

True

The binary search algorithm can be written iteratively or recursively. a. True b. False

True

The selection sort algorithm finds the location of the smallest element in the unsorted portion of the list. a. True b. False

True

The sequential search algorithm does not require that the list be sorted. a. True b. False

True

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 b. 7 c. 16 d. 62

a. 5

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

a. Merge

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)

a. O(nlog2n), O(nlog2n)

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

a. one

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

a. two

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

b. 1

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

b. 3(n - 1)

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

b. bool

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

b. n(n - 1)/2

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 b. n/2 c. n d. n^2

b. n/2

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

c. (first + last) / 2

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

c. 2 5 10 16 25 34 46 56 73 89

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. 250,000

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 b. 25 c. 39 d. 95

c. 39

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

c. comparison tree

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. }

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. }

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. list[0] and list[1]

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. move the smallest element to the beginning of the unsorted list

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

c. n

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

c. one half of the list

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)

d. O(n^2), O(nlog2n)

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

d. copy list[4] into temp

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]

d. list[6]...list[11]

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;

d. temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;


Set pelajaran terkait

Pharmacology Chapter 29, Fluids and Electrolytes

View Set

Unit 9 Exam - Resource/Factor Markets

View Set