Chapter 8 COP3363

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

search

A ________ algorithm is a method of locating a specific item of information in a larger collection of data.

binary, linear

A ________ search is more efficient than a ________ search.

middle

A binary search begins with the ________ element of an array.

sorted

Array elements must ________ before a binary search can be performed.

Bubble Sort

Compare 1st two elements ▪ If out of order, exchange them to put in order Move down one element, compare 2nd and 3rd elements, exchange if necessary. Continue until end of array.

from lowest value to highest value

Data that is to be sorted in ascending order is ordered

the linear search

The ________ is adequate for searching through small arrays.

selection, bubble

The ________ sort usually performs fewer exchanges than the ________ sort.

simplicity

The advantage of a linear search is its

20,000

Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ________ elements must be compared.

25/5=5

What is the output after the following code executes? int numerator = 5; int denominator = 25; int temp = 0; temp = numerator; numerator = denominator; denominator = temp; cout << numerator << "/" << denominator << " = "<< (numerator/denominator) << endl;

descending order

When an array is sorted from highest to lowest, it is said to be in

Search

_________ locate an item in a list of information

Sort

_________: arrange values into an order: - Alphabetical - Ascending numeric - Descending numeric

The swap function must use reference parameters.

The following function should swap the values contained in two integer variables, num1 and num2. What, if anything, is wrong with this function? void swap(int num1, int num2) { int temp = num2; num2 = num1; num1 = temp; }

bubble sort

The following is the pseudocode for which type of algorithm? For maxElement = each subscript in the array, from the last to the first For index = 0 To maxElement - 1 If array[index] > array[index + 1] swap array[index] with array[index + 1] End If End For End For

selection sort

The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 To size - 1 If array[index] < minValue minValue = array[index] minIndex = index End If End For swap array[minIndex] with array[start] End For

binary search

The following is the pseudocode for which type of algorithm? Set first to 0 Set last to the last subscript in the array Set found to false Set position to -1 While found is not true and first is less than or equal to last Set middle to the subscript halfway between array[first] and array[last] If array[middle] equals the desired value Set found to true Set position to middle Else If array[middle] is greater than the desired value Set last to middle - 1 Else Set first to middle + 1 End If End While Return position

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


Set pelajaran terkait

Chapter 3 Property Taxation and Assessment

View Set

Methods of Argument and Rhetorical Strategy

View Set

02.15.01 ( imperative) Translate German to English

View Set

California DMV Permit Test Study Guide

View Set

Chapter 14 Mutation, DNA Repair, and Cancer

View Set

Fill in the blank - Dental Anatomy book - tmj

View Set

Pharmacology: Lifespan Considerations. Chapter 3

View Set

Emergency Action Plans and Fire Protection

View Set

18.Story Point Estimations - Planning Poker

View Set