AP CS Test Unit 7 Review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

How many times would the while loop execute if you first do int[] arr = {2, 10, 23, 31, 55, 86} and then call binarySearch(arr,55)? (A) 2 (B) 1 (C) 3

(A) 2

Under what condition will an insertion sort execute faster? (A) If the data is already sorted in ascending order (B) If the data is already sorted in descending order (C) It will always take the same amount of time to execute

(A) If the data is already sorted in ascending order

Which will cause the shortest execution of a sequential search looking for a value in an array of integers? (A) The value is the first one in the array (B) The value is in the middle of the array (C) The value is the last one in the array (D) The value isn't in the array

(A) The value is the first one in the array

Under what condition will an ascending insertion sort execute the slowest? (A) If the data is already sorted in ascending order (B) If the data is already sorted in descending order (C) It will always take the same amount of time to execute

(B) If the data is already sorted in descending order

Which will cause the shortest execution of a binary search looking for a value in an array of integers? (A) The value is the first one in the array (B) The value is in the middle of the array (C) The value is the last one in the array (D) The value isn't in the array

(B) The value is in the middle of the array

Which of the following conditions must be true in order to search for a value using binary search? I. The values in the array must be integers. II. The values in the array must be in sorted order. III. The array must not contain duplicate values. (A) I only (B) I and II (C) II only (D) II and III

(C) II only

Under what condition will a merge sort execute faster? (A) If the data is already sorted in ascending order (B) If the data is already sorted in descending order (C) It will always take the same amount of time to execute

(C) It will always take the same amount of time to execute

Under what condition will a selection sort execute faster? (A) If the data is already sorted in ascending order (B) If the data is already sorted in descending order (C) It will always take the same amount of time to execute

(C) It will always take the same amount of time to execute

Which sort contains a recursive call? (A) selection sort (B) insertion sort (C) merge sort

(C) merge sort

Which sort should be the fastest most of the time? (A) selection sort (B) insertion sort (C) merge sort

(C) merge sort

Which will cause the longest execution of a sequential search looking for a value in an array of integers? (A) The value is the first one in the array (B) The value is in the middle of the array (C) The value is the last one in the array (D) The value isn't in the array

(D) The value isn't in the array

A more efficient sort is ____________

O(n log n)

Sequential search

can be used to find a value in unsorted data. Starts at the first element in an array or list and looks through all the items one by one until it either finds the desired value and then it returns the index it found the value at or if it searches the entire array or list without finding the value it returns -1.

Binary search

examines the middle element and moves left if the desired element is less than the middle and right if the desired element is greater. Can only be used on data that has been sorted or sorted in order.

Time efficiency of O(n^2) means that as the size of the input increases, the running time ____________ exponentially

increases

Sorted section

initially empty, eventually entire array

Unsorted section

initially entire array, eventually empty

Insertion sort

pick any item and insert it into its proper place in a sorted sublist, repeat until all items have been inserted

Selection sort

select a value and put it in its final place into the list (switching the values)

Merge sort

separates into two parts and then sorts them

Sorting

the process of arranging a list of items in a particular order

Swapping

the process of exchanging two values. It requires three assignment statements temp = first, first = second, second = temp.


Ensembles d'études connexes

Quiz 2: Atoms, Molecules, Properties of Water and pH

View Set

American History Unit 2 (11th Grade)

View Set

Study.com Chapter 2,3, Health Care Delivery System

View Set

Biology Chapter 20 Homework + Module

View Set

31. 2 the central nervous system

View Set

Accounting For Managers Chapters 1-4 Multiple Choice

View Set

Test 2: Prebiotics, Probiotics and fermented foods in meal planning

View Set

201-Chapter 22: Care of Patients with Cancer

View Set