MIT 6.00 Week 2 Flashcards
What guarantees that a loop will end?
A decrementing function
What characteristics are required of a decrementing function?
1) It maps a set of program variables to an integer.
2) It starts with a non-negative value.
3) It terminates when the value < 0.
4) It decreases each iteration.
What is “brute force” problem solving?
Exhaustive enumeration
Determining the range of values that an answer could be, and checking each value individually, in order, until you find the correct answer.
What is the syntax of a for loop in Python?
for variable in (something):
what is the syntax for the range function?
range(start, stop, increment)
start is inclusive
stop is non inclusive
What do we do when an exact answer cannot be ensured?
Use approximation.
Determine what answer will be close enough that we are satisfied, and search for an answer within that range.
What is a faster type of search than exhaustive enumeration, and how does it work?
Bisection Search:
1) Determine a range within the answer can be found
2) Test the middle of the range. If it is too high, make it the new upper bound. If it is too low, make it the new lower bound.
3) Test the answer that is the middle of the new range.
4) Repeat until the answer, or an acceptable approximation, is found.
What advantages does the use of functions provide?
1) Decomposition
2) Abstraction
What do we mean by decomposition?
Structure is created. The modules created by functions are self-contained and reusable.
What doe we mean by abstraction?
Details are suppressed when they are unimportant or distracting.
How do we create a function?
def functionName(parameter, parameter,...): Function Body
How do we get a value back from a function?
the return keyword
What happens if you do not use return in a function?
It will return the none data type
What is the term for calling on a function?
Invoking
What is the written description and explanation of a function called?
The specification
What should be included in specification?
The purpose/effect of the function, and the parameters it takes.
What is the term for the parameter found in the definition of a function?
The formal parameter
or
parameter
What is the term for a value passed into a function?
The actual parameter
or
argument
What is scope?
The matching of names to objects.