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) { if (exp & 1) { ret = base; } exp >>= 1; base base base; return ret; } // pow Notes 1. The operation count is related to the binary representation of the exponent. If you are unable to find a precise, closed form, cost function then give a good upper bound. 2. The & (bitwise AND) and >>= (right shift assignment) are bitwise operators. If you are unfamiliar with these please look them up (Google).
Example This function computes the sum of squares of its array parameter. int sumsquares (int arr[], int n) { int i = 0; int sun = 0; } while (1
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