Chapter 6 Flashcards
Functions as abstraction mechanisms
-Abstraction- hides detail, allowing person to view many things as one thing
-Example of everyday tasks: doing my laundry
Functions eliminate__
redundancy
Functions hide__
complexity
- a function call expresses the idea of a process to the programmer w/o forcing him/her to wade through the complex code that realizes that idea
Functions Support ___ with Systematic Variations
- General Method: a method that solves a class of problems, not just one individual problem
- problem instances: individual problems that make up a class of problems
- Algorithms should be general enough to provide a solution to many problem instances
- A function should provide a general method with systematic variations
Functions support the ___
- Division of labor
- Each function should perform a single coherent task
- Example: Computing a summation
- Each of the tasks required by a system can be assigned to a function
- Including the tasks of managing or coordinating the use of other functions
Top-down design
- Starts with a global view of the entire problem and breaks the
problem into smaller, more manageable subproblems (problem decomposition) - As each subproblem is isolated, its solution is assigned to a function
- As functions are developed to solve subproblems, solution to overall problem is gradually filled out (stepwise refinement)
Structure chart
- a diagram that shows the relationship among a program’s
functions and the passage of data between them - Each box in the structure is labeled with a function name
*The main function at the top is where the design begins
*Lines connecting the boxes are labeled with data type names
*Arrows indicate the flow of data between them
recursive design
the process of decomposing a problem into subproblems of exactly the same form that can be solved by the same algorithm
recursive function
a function that calls itself
-To prevent function from repeating itself indefinitely, it must contain at least one selection statement
base case
the condition in a recursive algorithm that is tested to halt the recursive process
selection statement
examines base case to determine whether to stop or to continue with another recursive step.
recursive definition
-a set of statements in which at least one statement is defined in terms of itself.
-consists of equations that state what a value is for one or more
base cases and one or more recursive cases
infinite recursion
-in a running program, the state that occurs when a recursive method cannot reach a stopping state
-arises when programmer fails to specify base case or to
reduce size of problem in a way that terminates the recursive process
PVM reserves an area of memory for the ____
call stack
For each call of a function, the PVM must allocate on the call stack a _____
stack frame
A stack frame contains____
- Values of the arguments
- Return address for the particular function call
- Space for the function call’s return value