Question 2 1 pts Suppose you are collecting performance data for the selection sort shown below, and you collect elapsed
Posted: Sun May 15, 2022 2:00 pm
Question 2 1 pts Suppose you are collecting performance data for the selection sort shown below, and you collect elapsed times as shown and graph those times. What trend would you expect the graph to show? 1); void selection_sort(int a[], int size) { int next; for (next = 0; next < size - 1; next++) int min_pos = min_position(a, next, size - if (min_pos != next) { int before = time(); swap(a[min_pos], a[next]); int after = time(); cout << (after - before) << endl; } } } Constant time Linear Log Quadratic
Question 3 1 pts Suppose you want to write an algorithm to find the most frequent element in a vector. The brute force method takes O(n?) time, examining every element and counting the number of occurences for that value. Optimizing the algorithm to not re-examine already tested parts of the vector reduces it to O(n²/2), because each value requires searching one fewer elements. What is that pattern called? Linear Triangle Quadratic Log
Question 3 1 pts Suppose you want to write an algorithm to find the most frequent element in a vector. The brute force method takes O(n?) time, examining every element and counting the number of occurences for that value. Optimizing the algorithm to not re-examine already tested parts of the vector reduces it to O(n²/2), because each value requires searching one fewer elements. What is that pattern called? Linear Triangle Quadratic Log