Modify the function to count the number of operations performedwhen the function executes in the worst case
Determine a detailed cost function for the function. Thisfunction should be written in theform wnx + yn + z
Identify all of the barometer operations for the function.
Write the O notation running time.
Requirements For each of the functions described in questions 1 to 7 you are to: 1. Modify the function to count the number of operations performed when the function executes in the worst case. See the section on counting operations below for more detail. 2. Determine a detailed cost function for the function. This function should be written in the form wn* + yn + z where w, x, y and z are real numbers and n is a variable referring to the size of the function's input. If necessary, you should adapt this format to include other terms such as log₂(n). 3. Identify all of the barometer operations for the function. 4. Write the O notation running time. There is a detailed example after the last question. Counting Operations Augment each function with an integer reference parameter to maintain a count of the number of operations. This reference parameter should always be the last parameter in the function's parameter list. When counting operations follow these rules - make sure you read them carefully (and follow them). 1. An executable statement (a line of code that ends in a semi-colon) or a condition (that controls an if statement or while loop) or a loop increment statement (like i++ in the third field of many for loops) counts as one (1) operation regardless of its complexity. This includes input or output instructions. Statements that include one or more function calls will count as more than one operation, as detailed by rule 2. Examples: x = 4; cout << "Hello world!\n"; int w = x + y + z; (x 0) { } pattern(n/2, 1); // Print i spaces cout << string(1,' '); // A loop to print n asterisks, each one followed by a space int ast = 0; while (ast
Modify the function to count the number of operations performed when the function executes in the worst case Determine a
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am