CPS181 - Chapter 16 Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

A computational problem is _______.

A problem that can be solved using an algorithm.

A basic step is_____.

An operation that can be executed within a constant amount of time

A search for an item X in an array starts at the lower end of the array, and then looks for X by comparing array items to X in order of increasing subscript. Such a method is called ________.

Sequential search

Assuming a method int findMax(int array[ ], int last) that returns the subscript of the largest value in the portion of an array whose elements are at 0 through last (inclusive), a recursive method for sorting in ascending order a portion of an array between 0 and last, inclusive, can be written as follows: void rSort(int array[ ], int last) { if (last >= 1) { // Missing code } } If a method void swap(int array[ ], int pos1, int pos2) can be used to swap the contents of two array entries, then the logic for the missing code is ________.

int p = findMax(array, last); swap(array, p, last); rSort(array, last-1);

The selection sort algorithm works by ________.

repeatedly locating the smallest value in the unsorted portion of the array and moving it toward the lower end of the array

The insertion sort algorithm works by ________.

repeatedly taking the first value in the unsorted portion of the array and placing it at its proper place in the part of the array that is already sorted

The compareTo method of the Comparable interface ________.

returns a negative integer when the calling object is "less than" the object passed as the parameter

The worst-case complexity function is a good measure to use when ________.

we want a guarantee on the performance of an algorithm

When applied to an array a[] of integers, the pseudo code ________. Boolean sort = true int k = 0 While sort == true and k < a.length-1 If a[k] > a[k+1] Then sort = false End If k = k +1 End While

will determine if the array is arranged in ascending order

The addition of two integers ________.

Is a basic step if there is a fixed bound on the size of the integers

For a computational problem, the input size ________.

Is the amount of memory needed to store the input

The worst-case complexity function f(n) of an algorithm ________.

Is the maximum number of basic steps performed in solving a problem instance with input size n

On the average, performing a sequential search on an array of N elements will require ________.

N/2 comparisons

Binary Search is in the complexity class ________.

O(log n)

The bubble sort algorithm works by ________.

repeatedly comparing adjacent items and swapping them so smaller values come before larger value

The best method for searching an array that is not sorted is ________.

sequential search (i.e., sequential search)

The two criteria most often used to measure the efficiency of an algorithm are ________.

space and time

Consider the code static void doQuickSort(int array[ ], int start, int end) { int pivotPoint; if (start < end) { pivotPoint = partition(array, start, end); doQuickSort(array, start, pivot-1); doQuickSort(array, pivot+1, end); } } In this code, the value pivotPoint returned by partition ________.

is the position of the array element that is greater than each element of the first sublist, and less or equal to each element of the second sublist

A contiguous segment of an array is specified using two subscripts, lower and upper. Which expression gives the position of the element in the middle of the array segment?

lower + (upper - lower) / 2

Sequential Search is in the complexity class ________.

O(n)

If an array is known to be sorted, it can be searched very quickly by using ________.

Binary Search

A search for an item X in a portion of a sorted array works by repeatedly selecting the middle item and comparing it to X. If X is not found there, the search method selects either the portion of the array to the left of the middle item, or the portion of the array to the right of the middle item and continues the search. This method is called ________.

Binary search

If a[] is an array of integers, the pseudo code int k = 0 int m = 1 While m < a.length If a[m] < a[k] Then k = m End If m = m+1 End While describes a strategy for ________.

Determining the location of the smallest value in the array

If an algorithm makes two separate, unnested passes over an input of size n, the performance of the algorithm will be in the class ________.

O(n)

Linear time is the class of all complexity functions that are in ________.

O(n)

Assuming a method int findMax(int array[ ], int last) that returns the subscript of the largest value in the portion of an array whose elements are at 0 through last (inclusive), a method for sorting an array in ascending order can be written as follows: void sort(int array[ ]) { for (int last = array.length-1; last >=1; last --) { int maxPos = findMax(array, last); // Code is missing } } If a method void swap(int array[ ], int pos1, int pos2) can be used to swap the contents of two array entries, then the logic for the missing code is ________.

swap(array, maxPos, last);

The maximum number of comparisons that binary search will ever need to make on an array of N elements is ________.

the smallest integer k such that 2k is larger or equal to N


Kaugnay na mga set ng pag-aaral

Midterm 2: Multiple Choice Questions

View Set

Chapter 1: General California Life Insurance Law

View Set

CPCU 520 - Chapter 8 - Exploring Reinsurance quiz

View Set

CIPP/US, CIPP/US Practice Questions, CIPP/US, CIPP US

View Set

Statistics Final Study questions

View Set