•For the following algorithm, explain what it computes, state what the input size for analysis is, state what basic operations should be counted for analyzing it, state exactly how many operations are executed as a function of the input size, and state the efficiency class or classes to which it belongs. The built-in C++ swap function is extremely efficient, and you should count it as performing exactly two basic operations. 01 void foo(vector& array) 02 { size_t size - array.size(); for (size_t pass_indx = 0; pass_indx < size - 1; pass_indx++) { size_t min_position = pass_indx; for (size_t compare_indx = pass_indx + 1; compare_indx < size; compare_indx++) { if (array.at(compare_indx) < array.at (min_position)) { min_position - compare_indx; } } 03 04 05 06 07 08 09 10 11 12 13 if (min_position != pass_indx) { swap (array.at(pass_indx), array.at (min_position)); 17 18 19

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
• For the following algorithm, explain what it computes, state what the input size for analysis is, state what basic operations should be counted for analyzing
it, state exactly how many operations are executed as a function of the input size, and state the efficiency class or classes to which it belongs. The built-in
C++ swap function is extremely efficient, and you should count it as performing exactly two basic operations.
01 void foo(vector& array)
02 {
size_t size = array.size();
for (size_t pass_indx = 0; pass_indx < size - 1; pass_indx++)
{
size_t min_position = pass_indx;
for (size_t compare_indx = pass_indx + 1; compare_indx < size;
compare_indx++)
{
if (array.at (compare_indx) < array.at(min_position))
{
min_position = compare_indx;
}
}
03
04
05
06
07
08
09
10
11
12
13
14
15
16
if (min_position !- pass_indx)
17
swap (array.at(pass_indx), array.at (min_position));
18
19
}
21 }
20
Transcribed Image Text:• For the following algorithm, explain what it computes, state what the input size for analysis is, state what basic operations should be counted for analyzing it, state exactly how many operations are executed as a function of the input size, and state the efficiency class or classes to which it belongs. The built-in C++ swap function is extremely efficient, and you should count it as performing exactly two basic operations. 01 void foo(vector& array) 02 { size_t size = array.size(); for (size_t pass_indx = 0; pass_indx < size - 1; pass_indx++) { size_t min_position = pass_indx; for (size_t compare_indx = pass_indx + 1; compare_indx < size; compare_indx++) { if (array.at (compare_indx) < array.at(min_position)) { min_position = compare_indx; } } 03 04 05 06 07 08 09 10 11 12 13 14 15 16 if (min_position !- pass_indx) 17 swap (array.at(pass_indx), array.at (min_position)); 18 19 } 21 } 20
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education