Chapter 9: Sorting Review

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

True

On average, an item is just as likely to be found near the beginning of an array as near the end. >True >False

O(nlog2n), O(nlog2n)

The behavior of merge sort is ____ in the worst case and ____ in the average case. >O(nlog2n), O(nlog2n) >O(n2), O(n) >O(nlog2n), O(n2) >O(n2), O(nlog2n)

O(n^2), O(nlog2n)

The behavior of quick sort is ____ in the worst case and ____ in the average case. >O(nlog2n), O(nlog2n) >O(n2), O(n) >O(nlog2n), O(n2) >O(n2), O(nlog2n)

pivot

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

False

You are more likely to find an item by using a binary search than by using a linear search. >True >False

Merge

____ sort requires knowing where the middle element of the list is. >Merge >Bubble >Insertion >Selection

n(n - 1)/2

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

descending order

When an array is sorted from highest to lowest, it is said to be in >reverse order >forward order >ascending order >descending order >None of these

move the smallest element to the beginning of the unsorted list

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

1

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

one

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

list[0] and list[1]

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

Binary

A comparison tree is a(n) ____________________ tree.

binary, linear

A ________ search is more efficient than a ________ search. >character, string >integer, double >binary, linear >linear, binary >None of these

n/2

A sequential search of an n-element list takes ____ key comparisons on average to determine whether the search item is in the list. >0 >n/2 >n >n^2

sorted

Array elements must ________ before a binary search can be performed. >summed >set to zero >positive integers >sorted >None of these

from lowest value to highest value

Data that is to be sorted in ascending order is ordered >from lowest value to highest value >from highest value to lowest value >with a binary search algorithm >by identifying the middle value and going up and down from there >None of these

True

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

Big-O

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.

None of these

Regardless of the algorithm being used, a search through an array is always performed >from lowest to highest element >from highest to lowest element >beginning with the middle element >using a binary search algorithm >None of these

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

(first + last) / 2

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

False

A linear search can only be implemented with integer values. >True >False

sorting

Algorithms used to arrange random data in some order are ________ algorithms. >standard search >sorting >linear >binary search >None of these

int temp = num2; num2 = num1; num1 = temp;

Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables? >int temp = num1; num2 = num1; num1 = num2; >int temp = num2; num2 = num1; num1 = temp; >num1 = num2; num2 = num1; >int temp = num1; num2 = temp; temp = num2; num1 = temp; >None of these

list[6]...list[11]

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 ____. >list[0]...list[6] >list[0]...list[7] >list[5]...list[11] >list[6]...list[11]

3(n - 1)

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

False

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

False

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

Partition

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

the linear search

The ________ is adequate for searching through small arrays. >binary search >the linear search >unary search >bubble sort >None of these

selection, bubble

The ________ sort usually performs fewer exchanges than the ________ sort. >bubble, selection >binary, linear >selection, bubble >ANSI, ASCII >None of these

Binary

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

linear search

The following is the pseudocode for which type of algorithm? Set found to false Set position to -1 Set index to 0 While found is false and index < number of elements If list[index] is equal to search value found = true position = index End If Add 1 to index End While Return position >linear sort >linear search >binary search >selection sort >None of these

True

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

True

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


Set pelajaran terkait

Nursing 202 Immune System disorders - Module D

View Set

Exam 3 GI: IBD, Appendicitis, peritonitis, UC, crohns, diverticula.

View Set

Life insurance Premiums, Proceeds, and Beneficiaries. Life premiums and benefits.

View Set