Zybooks Chapter 16 Searching and Sorting Algorithms Participation Activity Questions

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

O(N^2)

A selection sort has a _____ runtime complexity. O(N) O(N log N) O(N^2)

11 µs

Answer the following questions assuming each comparison takes 1 µs. Given a list of 1024 elements, what is the runtime for linear search if the search key is greater than all elements in the list?

1024 µs

Answer the following questions assuming each comparison takes 1 µs. Given a list of 1024 elements, what is the runtime for linear search if the search key is less than all elements in the list?

1

Assume insertion sort's goal is to sort in ascending order. Given list [10, 11, 12, 13, 14, 15], how many comparisons will be made during the third outer loop execution (i = 3)?

14

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)?

3

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)?

5

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)?

[6, 10, 20, 14, 7]

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 brackets in your answer, e.g. "[1, 2, 3]".

7

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?

3

Assume quicksort always chooses a pivot that divides the elements into two equal parts. How many partitioning levels are required for a list of eight elements?

10240

Assume quicksort always chooses a pivot that divides the elements into two equal parts. How many total comparisons are required to sort a list of 1024 elements?

10

Assume quicksort always chooses a pivot that divides the elements into two equal parts. How many partitioning "levels" are required for a list of 1024 elements?

[2]

Assume quicksort always chooses the smallest element as the pivot. Given numbers = [7, 4, 2, 25, 19], i = 0, and k = 4, what are the contents of the low partition? Use brackets in your answer. Ex: "[1, 2, 3]".

1023

Assume quicksort always chooses the smallest element as the pivot. How many partitioning "levels" are required for a list of 1024 elements?

4

Assume quicksort always chooses the smallest element as the pivot. How many partitioning "levels" are required for a list of five elements?

1047552

Assume quicksort always chooses the smallest element as the pivot. How many total comparisons are required to sort a list of 1024 elements?

5

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, 6, 8, 7, 9]

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 brackets in your answer, e.g., "[1, 2, 3]".

1

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)?

True

A for loop of the form for num in numbers: that does not have nested loops or function calls, and does not modify num in the loop will always have a complexity of O(N). True False

O(N)

A linear search has a _____ runtime complexity. O(log N) O(N) O(N^2)

f(N) = 2N + 1

Which function best represents the number of operations in the worst case? sum = 0 for num in numbers: sum = sum + num f(N) = 2N f(N) = 2N + 1 f(N) = 2 + N (N + 1)

O(N^3)

Which of the following Big O notations is equivalent to O(12·N +6·N^3 + 1000)? O(1000) O(N) O(N3)

O(N)

Which of the following Big O notations is equivalent to O(734·N)? O(N) O(734) O(734·N2)

O(N)

Which of the following Big O notations is equivalent to O(N+9999)? O(1) O(N) O(9999)

20000 µs

Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the longest possible runtime for linear search?

3

numbers = [1, 2, 3, 4, 5], i = 0, k = 4 pivot = _____

5

Given list: [ 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ]. Given a list with 32 elements, how many list elements will be checked if the key is less than all elements in the list, using binary search?

3

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?

2

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?

True

The complexity of the algorithm below is O(1). for i in range(24): if time_hour < 6: toll_schedule[i] = 1.55 elif time_hour < 10: toll_schedule[i] = 4.65 elif time_hour < 18: toll_schedule[i] = 2.35 else: toll_schedule[i] = 1.55 True False

True

The complexity of the algorithm below is O(1). if time_hour < 6: toll_amount = 1.55 elif time_hour < 10: toll_amount = 4.65 elif time_hour < 18: toll_amount = 2.35 else: toll_amount = 1.55 True False

True

The list is sorted into ascending order:['chopsticks', 'forks', 'knives', 'spork'] True False

True

The list is sorted into ascending order:['great', 'greater', 'greatest'] True False

False

The list is sorted into ascending order:[3, 9, 44, 18, 76] True False

True

The list is sorted into descending order:['F', 'D', 'C', 'B', 'A'] True False

True

The list is sorted into descending order:[20, 15, 10, 5, 0] True False

True

The list is sorted into descending order:[99.87, 99.02, 67.93, 44.10] True False

O(N^2)

10 + O(N^2) O(10) O(N^2) O(10 + N^2)

O(N^2)

10 · O(N^2) O(10) O(N^2) O(10 · N^2)

Holly

A contact list is searched for Bob. Assume the following contact list: [ Amy, Bob, Chris, Holly, Ray, Sarah, Zoe ]. Who is the first contact searched?

Bob

A contact list is searched for Bob. Assume the following contact list: [ Amy, Bob, Chris, Holly, Ray, Sarah, Zoe ]. Who is the second contact searched?

O(N^3)

2·N^3 + O(N^2) O(N^2) O(N^3) O(N^2 + N^3)

O(N^3)

3·N · O(N^2) O(N^2) O(3·N^2) O(N^3)

Sorted

Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. [6, 14, 85, 102, 102, 151] Unsorted Sorted Nearly sorted

Unsorted

Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. [15, 19, 21, 24, 2, 3, 6, 11] Unsorted Sorted Nearly sorted

Nearly sorted

Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. [23, 24, 36, 48, 19, 50, 101] Unsorted Sorted Nearly sorted

O(N^2)

Determine the big-O worst-case runtime for each algorithm. For each algorithm, N = len(numbers). for i in range(N): for j in range(N): if numbers[i] < numbers[j]: eq_perms = eq_perms + 1 else: neq_perms = neq_perms + 1 O(N) O(N^2)

O(N^2)

Determine the big-O worst-case runtime for each algorithm. For each algorithm, N = len(numbers). for i in range(0, N, 2): for j in range(0, N, 2): c_vals[i][j] = in_vals[i] * j O(N) O(N^2)

O(N^2)

Determine the big-O worst-case runtime for each algorithm. For each algorithm, N = len(numbers). for i in range(N): for j in range(N - 1): if numbers[j + 1] < numbers[j]: temp = numbers[j] numbers[j] = numbers[j + 1] numbers[j + 1] = temp O(N) O(N^2)

O(N^2)

Determine the big-O worst-case runtime for each algorithm. For each algorithm, N = len(numbers). for i in range(N): for j in range(i, N - 1): c_vals[i][j] = in_vals[i] * j O(N^2) O(N^3)

O(N^3)

Determine the big-O worst-case runtime for each algorithm. For each algorithm, N = len(numbers). for i in range(N): sum = 0 for j in range(N): for k in range(N): sum = sum + a_vals[i][k] * b_vals[k][j] c_vals[i][j] = sum O(N) O(N^2) O(N^3)

2 µs

Given a list of 10,000 elements, and each comparison takes 2 µs, what is the fastest possible runtime for linear search?

500

How many elements will the temporary merge list have for merging two partitions with 250 elements each?

11

How many recursive partitioning levels are required for a list of 2048 elements?

3

How many recursive partitioning levels are required for a list of eight elements?

4

How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

100

How many times longer will sorting a list of 500 elements take compared to a list of 50 elements?

45 µs

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

[1, 2, 3]

Numbers = [1, 2, 3, 4, 5], i = 0, k = 4 Left partition = _____

[4, 5]

Numbers = [1, 2, 3, 4, 5], i = 0, k = 4 Right partition = _____

2

Numbers = [1, 2, 3, 4, 5], i = 0, k = 4 j = _____

[23, 8]

Numbers = [34, 78, 14, 23, 8, 35], i = 3, k = 5 Left partition = _____

[35]

Numbers = [34, 78, 14, 23, 8, 35], i = 3, k = 5 Right partition = _____

4

Numbers = [34, 78, 14, 23, 8, 35], i = 3, k = 5 j = _____

constant

O(5) has a _____ runtime complexity. constant linear exponential

quadratic

O(N + N^2) has a _____ runtime complexity. linear-quadratic exponential quadratic

log-linear

O(N log N) has a _____ runtime complexity. constant log-linear logarithmic

4

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?

O(1)

What is the big-O notation for the best-case runtime? below_min_sum = 0.0 below_min_count = 0 i = 0 while (i < len(numbers)) and (numbers[i] <= max_val): below_min_count = below_min_count + 1 below_min_sum = numbers[i] i = i + 1 avg_below = below_min_sum / below_min_count O(1) O(N)

O(N)

What is the big-O notation for the worst-case runtime? for i in range(N): if i % 2 == 0: out_val[i] = in_vals[i] * i O(1) O(N/2) O(N)

O(log N)

What is the big-O notation for the worst-case runtime? n_val = N steps = 0 while n_val > 0: n_val = n_val // 2 steps = steps + 1 O(log N) O(N/2) O(N)

O(N)

What is the big-O notation for the worst-case runtime? neg_count = 0 for num in numbers: if num < 0: neg_count = neg_count + 1 f(N) = 1 + 3N O(3N + 1) O(N)

49

When sorting a list with 50 elements, index_smallest will be assigned a minimum of _____ times.

O(log N)

log2 N O(log2 N) O(log N) O(N)

2

numbers = [1, 2, 3, 4, 5], i = 0, k = 4 midpoint = _____

11

numbers = [200, 11, 38, 9], i = 0, k = 3 pivot = _____

1

numbers = [200, 11, 38, 9], i = 0, k = 3 midpoint = _____

5

numbers = [55, 7, 81, 26, 0, 34, 68, 125], i = 3, k = 7 midpoint = _____

34

numbers = [55, 7, 81, 26, 0, 34, 68, 125], i = 3, k = 7 pivot = _____


संबंधित स्टडी सेट्स

MCAT CARS Question Types and Strategies

View Set