2.2.1 Programming Techniques Flashcards
what is the difference between global and local variables
Global variables can be accessed from the entire program
Local variables have a limited scope where they can only be accessed from the module of code they were defined in
what is the difference of passing in a parameter byval and byref
by value means that a coy of the data is given to the subroutine meaning anychanges to the data made inside the subroutine dont change the value passed in
by ref gives the address of the data to the subroutine meaning any changes to the data update the address as its changed
what are the two ways to pass parameters into a subroutine
by reference and by value
define a recursive algorithm
a recursive algorithm is a function which calls itself from within the function
name the pros of a recursive algorithm
Certain problems are more suited to a recursive solution
problems can be more elegantly solved
can reduce the size of the problem on every recursive call
more natural to read
quicker to write
name the cons of recursion
uses more memory
can run out of stack space
difficult to debug
harder to trace
example of a time recursion is idea
factorial
fibbonnacci
tree traversal