Hi I need help with this questions relating to c++ Thank you and have a great day!
Posted: Sun May 15, 2022 1:49 pm
Hi I need help with this questions relating to c++
Thank you and have a great day!
Question 1 1 pts Suppose you are collecting performance data for the selection sort shown below, and you collect elapsed times and graph those times. What trend would you expect the graph to show? void selection_sort(int a[], int size) { int next; for (next = 0; next < size - 1; next++) { int before = time(); int min_pos = min_position(a, next, size - 1); int after = time(); cout << (after - before) << endl; if (min_pos != next) { swap(a[min_pos), a[next]); } } } Constant time Linear Log Quadratic
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 4 1 pts = Suppose the time for an algorithm on an array of size n is T(n) = an2 + bn + c. What type of algorithm is it? Linear Triangle Quadratic Log
Question 5 1 pts Suppose an algorithm cuts the amount of work in half at each step, such as processing half an array, then half of that half, etc... What type of algorithm is it? Linear Triangle Quadratic Log
Thank you and have a great day!
Question 1 1 pts Suppose you are collecting performance data for the selection sort shown below, and you collect elapsed times and graph those times. What trend would you expect the graph to show? void selection_sort(int a[], int size) { int next; for (next = 0; next < size - 1; next++) { int before = time(); int min_pos = min_position(a, next, size - 1); int after = time(); cout << (after - before) << endl; if (min_pos != next) { swap(a[min_pos), a[next]); } } } Constant time Linear Log Quadratic
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 4 1 pts = Suppose the time for an algorithm on an array of size n is T(n) = an2 + bn + c. What type of algorithm is it? Linear Triangle Quadratic Log
Question 5 1 pts Suppose an algorithm cuts the amount of work in half at each step, such as processing half an array, then half of that half, etc... What type of algorithm is it? Linear Triangle Quadratic Log