Programming Techniques Exluding OOP

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/3

flashcard set

Earn XP

Description and Tags

Made from Ada Comp. Sci. and PMT notes

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

4 Terms

1
New cards

Define recursion

A programming construct in which a subroutine calls itself during its execution

2
New cards

Advantages of recursion

  • Can represent certain problems with fewer lines of code, meaning that the function is:

    • Easier to read

    • Less prone to errors

  • Natural way to process certain data structures (such as trees) that are recursive by nature

3
New cards

Disadvantage of recursion

  • Harder to trace because you must keep track of multiple instances of the function.

  • Uses more memory because of the need to store multiple stack frames. If the call stack runs out of memory, there will be a stack overflow, and the program will crash.

  • Can be slower because of the need to manage stack operations.

4
New cards

Are parameter(s) passed by value or by reference in recursive subroutines, and why?

  • If the parameter is sent by value, it will be a copy of the parameter that is used so the parameter wont be overridden. This will produce the correct output.

  • If the parameter is passed by reference it would not produce the correct result as it would be overridden / because it is a pointer to the address of the variable.