1/13
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
Sequence
Code is executed line by line from top to bottom
Branching (selection)
A block of code is run if a condition is met (IF statements)
Iteration
A block of code is repeatedly ran for a certain number of times or until a condition is met (FOR/WHILE loops)
Recursion
When a function calls itself during its execution until a stopping condition is met
Advantages of recursion
Less lines of code = less likely to have errors
Good for divide and conquer problems
Disadvantages of recursion
Uses more memory than iteration
If not a stopping condition stack overflows may occur
Harder to understand for developers
Advantages of iteration
More efficient in time and memory than recursion
No risk of stack overflows
Easier to understand for developers
Disadvantages of iteration
Some algorithms are harder to write iteratively (divide and conquer and tree traversal)
Code can come overly complex for longer algorithms
Local variable
Variable that is declared in a function/procedure and can only be accessed in that function
Global variable
Variable that is declared outside any function and can be accessed anywhere in the program
Benefits of using procedures and functions
Less memory used
Can be reused multiple times
Makes programming more manageable splitting it into sections
Difference between function and procedure
A function returns a value whereas a procedure doesn’t
How are parameters used into a subroutine
Passed by value - treated like a local variable and discarded at the end
Passed by reference - address of the parameter is given, the value can be updated
IDE
Integrated development environment - software that allows programmers to write, test and debug code