Functions
<aside>
1️⃣ Subroutines that return a value
</aside>
Procedures
<aside>
1️⃣ Subroutines that don’t return a value
</aside>
Recursion
<aside>
🔁 A recursive function is one that calls itself until a base case is met.
</aside>
- Calls itself using a parameter
- Has a terminating/base condition
When are non-recursive algorithms better?
- When a data structure is fixed in size, like an array
- Non-recursion can reduce time-complexity in sorting algorithms if implemented efficiently
- Non-recursive solutions require less memory, thus reducing the demand on resources
- Non-recursive solutions are easier to write
Methods of passing
By reference
<aside>
💡 When the address is passed, rather than the actual data
</aside>
- Any change made within the subroutine will also affect the variable outside the subroutine (similar to a global variable)
✅ Avoids the larger amount of processing and storage associated with creating copies of the data, and allows desirable changes to be passed back into the main program
By value