Step Count Method for Time Complexity
Step Count Method for Time Complexity
Recursive procedures need additional consideration in step-count analysis because each recursion level potentially alters the size of local variables, especially when these sizes are instance characteristic dependent. The recursive calls must account for storing new local variable instances, potentially increasing the step count significantly .
When invoking functions with value parameters in the step-count method, the step count must include the size of these value parameters if it depends on instance characteristics. The complexity increases when large parameter values are involved, impacting the overall step count. Additionally, if the function is recursive, the size of local variables dependent on instance characteristics must also be considered in the step count .
Space complexity in the step-count method is determined by the variable storage requirements independent of instance characteristics. For example, function sum1 calculates space needed for each integer and constant, leading to a calculation of 12 bytes, which is independent of the instance characteristics. In function sum2, if parameter 'a' is changed to reference, space complexity similarly becomes independent of instance characteristics .
Changing a parameter from value to reference in the step-count method affects space complexity because reference parameters only pass the address of the variable, not the entire data. This reduces the space needed within a function, as seen in the case of function sum2, where changing parameter 'a' from value to reference eliminates the dependency on instance characteristics for space complexity .
Recursion in the step-count method adds complexity as it requires calculating the size and cost of local variables for each recursive call. If local variables are dependent on instance characteristics, these factors must be included in the step-count calculation for recursive procedures and functions, necessitating deeper analysis of recursive execution paths and variable storage needs .
Expressions containing function calls in the step-count method have a step count that is the sum of the step counts for each function invocation. This is because invoking a function can significantly increase complexity, particularly with many-element value parameters requiring assignments to formal parameters .
For 'for' statements, the first execution has a step count equal to the sum of the expressions within the loop, especially if these expressions depend on instance characteristics. Further executions count as one step each. 'While' and 'until' statements consider the step count assignable to the controlling expression, calculated for each execution of the control part .
Non-executable statements like comments and declarative statements, which include constant, label, type, and variable declarations, have a step count of zero. Their cost is either non-existent or merged into related procedure/function costs, ensuring they do not impact time complexity calculations using the step-count method .
The step-count method provides a more accurate estimation of time complexity by accounting for the time spent on all parts of the program, including comments, declarative statements, assignments, iteration, and more, rather than only focusing on selected operations. This method considers the number of steps as a function of the instance characteristics, thus offering a comprehensive view of all potential executions in the program .
Conditional statements like 'if-then-else' and 'case' statements contribute to the step count by adding the complexity of evaluating conditions and executing corresponding actions. Each condition and statement pair in a 'case' statement gets a cost dependent on condition evaluation plus preceding conditions. In 'if-then-else', every part has its step count based on the expressions and statements involved .