CSI 1430 CH9 QUESTIONS

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

9.6.2: Using binary search to search a contact list. A contact list is searched for Bob.Assume the following contact list: Amy, Bob, Chris, Holly, Ray, Sarah, Zoe What is the second contact searched?

bob

9.2.2: Big O notation. Which of the following Big O notations is equivalent to O(12·N +6·N3 + 1000)? a-O(1000) b-O(N) c-O(N3)

c

9.2.3: Big O notation for composite functions. Determine the simplified Big O notation. 3·N · O(N2) a-O(N2) b-O(3·N2) c-O(N3)

c

9.2.5: Big O notation and growth rates. A selection sort has a _____ runtime complexity. (Quadratic) a-O(N) b-O(N log N) c-O(N2)

c

9.2.5: Big O notation and growth rates. O(N + N2) has a _____ runtime complexity. a-linear-quadratic b-exponential c-quadratic

c

9.3.2: Worst-case runtime analysis. What is the big-O notation for the worst-case runtime? for (i = 0; i < N; ++i) { if ((i % 2) == 0) { outVal[i] = inVals[i] * i; } } a-O(1) b-O(N2) c-O(N)

c

9.3.2: Worst-case runtime analysis. What is the big-O notation for the worst-case runtime? negCount = 0; for(i = 0; i < N; ++i) { if (numbers[i] < 0 ) { ++negCount; } } a-f(N) = 2 + 4N + 1 b-O(4N + 3) c-O(N)

c

9.3.6: Nested loops. Determine the big-O worst-case runtime for each algorithm. for (i = 0; i < N; ++i) { sum = 0; for (j = 0; j < N; ++j) { for (k = 0; k < N; ++k) { sum = sum + aVals[i][k] * bVals[k][j]; } cVals[i][j] = sum; } } a-O(N) b-O(N2) c-O(N3)

c

9.7.4: Nearly sorted lists. Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order {23 24 36 48 19 50 101} a-Unsorted b-Sorted c-Nearly sorted

c

9.2.2: Big O notation. Which of the following Big O notations is equivalent to O(734·N)? a-O(N) b-O(734) c-O(734·N2)

a

9.2.5: Big O notation and growth rates. O(5) has a _____ runtime complexity. a-constant b-linear c-exponential

a

9.3.2: Worst-case runtime analysis. What is the big-O notation for the best-case runtime? i = 0; belowMinSum = 0.0; belowMinCount = 0; while (i < N && numbers[i] <= maxVal) { belowMinCount = belowMinCount + 1; belowMinSum = numbers[i]; ++i; } avgBelow = belowMinSum / belowMinCount; a-O(1) b-O(N)

a

9.3.2: Worst-case runtime analysis. What is the big-O notation for the worst-case runtime? nVal = N; steps = 0; while (nVal > 0) { nVal = nVal / 2; steps = steps + 1; } a-O(log N) b-O(N2) c-O(N)

a

9.3.6: Nested loops. Determine the big-O worst-case runtime for each algorithm. for (i = 0; i < N; ++i) { for (j = i; j < N - 1; ++j) { cVals[i][j] = inVals[i] * j; } } a-O(N2) b-O(N3)

a

9.4.2: Sorted elements. The list is sorted into ascending order:{chopsticks forks knives spork} a-true b-false

a

9.4.2: Sorted elements. The list is sorted into ascending order:{great greater greatest} a-true b-false

a

9.4.2: Sorted elements. The list is sorted into descending order:{20 15 10 5 0} a-true b-false

a

9.4.2: Sorted elements. The list is sorted into descending order:{99.87 99.02 67.93 44.10} a-true b-false

a

9.4.2: Sorted elements. The list is sorted into descending order:{F D C B A} a-true b-false

a

9.7.4: Nearly sorted lists. Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order {15 19 21 24 2 3 6 11} a-Unsorted b-Sorted c-Nearly sorted

a

9.2.2: Big O notation. Which of the following Big O notations is equivalent to O(N+9999)? a-O(1) b-O(N) c-O(9999)

b

9.2.3: Big O notation for composite functions. Determine the simplified Big O notation. 10 + O(N2) a-O(10) b-O(N2) c-O(10 + N2)

b

9.2.3: Big O notation for composite functions. Determine the simplified Big O notation. 10 · O(N2) a-O(10) b-O(N2) c-O(10 · N2)

b

9.2.3: Big O notation for composite functions. Determine the simplified Big O notation. 2·N3 + O(N2) a-O(N2) b-O(N3) c-O(N2 + N3)

b

9.2.5: Big O notation and growth rates. A linear search has a _____ runtime complexity. a-O(log N) b-O(N) c-O(N2)

b

9.2.5: Big O notation and growth rates. O(N log N) has a _____ runtime complexity. a-constant b-log-linear c-logarithmic

b

9.3.2: Worst-case runtime analysis. Which function best represents the number of operations in the worst-case? i = 0; sum = 0; while (i < N) { sum = sum + numbers[i]; ++i; } a-f(N) = 3N + 2 b-f(N) = 3N + 3 c-f(N) = 2 + N (N + 1)

b

9.3.6: Nested loops. Determine the big-O worst-case runtime for each algorithm. for (i = 0; i < N; i = i + 2) { for (j = 0; j < N; j = j + 2) { cVals[i][j] = inVals[i] * j; } } a-O(N)-Linear b-O(N2)-Quadratic

b

9.3.6: Nested loops. Determine the big-O worst-case runtime for each algorithm. for (i = 0; i < N; i++) { for (j = 0; j < (N - 1); j++) { if (numbers[j + 1] < numbers[j]) { temp = numbers[j]; numbers[j] = numbers[j + 1]; numbers[j + 1] = temp; } } } a-O(N)-Linear b-O(N2)-Quadratic

b

9.3.6: Nested loops. Determine the big-O worst-case runtime for each algorithm. for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if (numbers[i] < numbers[j]) { ++eqPerms; } else { ++neqPerms; } } } a-O(N)-Linear b-O(N2)-Quadratic

b

9.4.2: Sorted elements. The list is sorted into ascending order:{3 9 44 18 76} a-true b-false

b

9.7.4: Nearly sorted lists. Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order {6 14 85 102 102 151} a-Unsorted b-Sorted c-Nearly sorted

b

9.1.2: Linear search algorithm execution. Given list: { 20 4 114 23 34 25 45 66 77 89 11 }. How many list elements will be compared to find 77 using linear search?

9

9.5.2: Selection sort algorithm execution. Assume selection sort's goal is to sort in ascending order. Given list {5 9 8 7 6} and i = 1, what will be the list after completing the second outer loop iteration? Use curly brackets in your answer.

{5 6 8 7 9}

9.7.2: Insertion sort algorithm execution. Assume insertion sort's goal is to sort in ascending order. Given list {10 20 6 14 7}, what will be the list after completing the second outer loop iteration (i = 2)? Use curly brackets in your answer.

{6 10 20 14 7}

9.5.2: Selection sort algorithm execution. Assume selection sort's goal is to sort in ascending order. Given list {9 8 7 6 5}, how many swaps will occur during the first pass of the outer loop (i = 0)?

1

9.7.6: Insertion sort algorithm execution for nearly sorted input. Assume insertion sort's goal is to sort in ascending order. Given list {10 11 12 13 14 5}, how many comparisons will be made during the third outer loop execution (i = 3)?

1

9.6.6: Linear and binary search efficiency. Suppose a sorted list of 1024 elements is searched with binary search. How many distinct list elements are compared against a search key that is less than all elements in the list? _____________elements

10

9.5.3: Selection sort runtime. How many times longer will sorting a list of 500 elements take compared to a list of 50 elements?

100

9.6.6: Linear and binary search efficiency. Suppose a list of 1024 elements is searched with linear search. How many distinct list elements are compared against a search key that is less than all elements in the list? _____________elements

1024

9.1.2: Linear search algorithm execution. Given list: { 20 4 114 23 34 25 45 66 77 89 11 }. How many list elements will be checked if the search key is not found using linear search?

11

9.7.2: Insertion sort algorithm execution. Assume insertion sort's goal is to sort in ascending order. Given list {20 14 85 3 9}, what value will be in the 0th element after the first pass over the outer loop (i = 1)?

14

9.1.3: Linear search runtime. Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the fastest possible runtime for linear search? (microsecond)

2

9.6.4: Binary search algorithm execution. Given list: ( 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ). How many list elements will be checked to find the value 77 using binary search?

2

9.1.3: Linear search runtime. Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the longest possible runtime for linear search?(microsecond)

20000

9.1.2: Linear search algorithm execution. Given list: { 20 4 114 23 34 25 45 66 77 89 11 }. How many list elements will be checked to find the value 114 using linear search?

3

9.6.4: Binary search algorithm execution. Given list: ( 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ). How many list elements will be checked to find the value 17 using binary search?

3

9.7.2: Insertion sort algorithm execution. Assume insertion sort's goal is to sort in ascending order. Given list {1 9 17 18 2}, how many swaps will occur during the outer loop execution (i = 4)?

3

9.5.3: Selection sort runtime. How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

4

9.7.3: Insertion sort runtime. Using the Big O runtime complexity, how many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

4

9.7.3: Insertion sort runtime. In the worst case, assuming each comparison takes 1 µs, how long will insertion sort algorithm take to sort a list of 10 elements? _________µs

45

9.5.3: Selection sort runtime. When sorting a list with 50 elements, indexSmallest will be assigned to a minimum of __?___ times.

49

9.5.2: Selection sort algorithm execution. Assume selection sort's goal is to sort in ascending order. Given list {9 8 7 6 5}, what value will be in the 0th element after the first pass over the outer loop (i = 0)?

5

9.6.4: Binary search algorithm execution. Given list: ( 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ). Given an array with 32 elements, how many list elements will be checked if the key is less than all elements in the list, using binary search?

5

9.7.6: Insertion sort algorithm execution for nearly sorted input. Assume insertion sort's goal is to sort in ascending order. Given list {10 11 12 13 14 7}, how many comparisons will be made during the final outer loop execution (i = 5)?

5

9.7.6: Insertion sort algorithm execution for nearly sorted input. Assume insertion sort's goal is to sort in ascending order. Given list {18 23 34 75 3}, how many total comparisons will insertion sort require?

7

9.6.2: Using binary search to search a contact list. A contact list is searched for Bob.Assume the following contact list: Amy, Bob, Chris, Holly, Ray, Sarah, Zoe What is the first contact searched?

holly


Kaugnay na mga set ng pag-aaral

CSCS- Testing and Data Evaluation

View Set

Ellentétpárok - Adjektive Gegenteil

View Set

Massage Practice | HLTH3821 | Quiz 1 testtest

View Set

Economics of Strategy: Chapter 10: Information & Valuation CreationWa

View Set

Study Guide SOL 6 Part 2: Roman Empire

View Set

Fluid and electrolytes and Arterial Blood Gases

View Set

NUR351- Quiz 2 Modules 5.01-5.06

View Set