Recursion and Programming

Cards (30)

  • What is a global variable?
    Visible throughout a program
  • What is a local variable?
    Visible only in its module
  • Why are global variables sometimes used?
    To access the same value from various parts
  • Why is it good practice to avoid global variables?
    They increase program complexity and conflicts
  • What does branching/selection do in programming?
    Decides which code is run
  • What is iteration in programming?
    Repeatedly runs the same code
  • What is sequence in programming?
    Instructions performed one after another
  • What are the differences between a procedure and a function?
    • A function returns a single value.
    • A procedure does not return a value.
    • A function is part of an expression.
    • A procedure is an instruction/statement.
  • What happens when a procedure is called?
    The code in the procedure executes
  • What is parameter passing by value?
    Uses a local copy of the data
  • What is parameter passing by reference?
    Memory location of data is sent
  • What are the habits for writing good functions?
    • No longer than a single page of code.
    • Variable identifiers must conform to a standard.
    • Each function must have a single entry point.
    • Variables must not be set up outside the function's scope.
  • What is a stack in programming?
    LIFO data structure
  • What is a queue in programming?
    FIFO data structure
  • How does a stack operate?
    Data is popped/pushed from the top
  • How does a queue operate?
    Data is dequeued from the front
  • What is an array?
    Fixed size data structure
  • What is a list in programming?
    Dynamic size data structure
  • What is a tuple?
    Immutable data structure with multiple types
  • What is a linked list?
    Ordered set of data elements linked together
  • What is a tree in programming?
    Hierarchical structure with nodes
  • What is the root node in a tree?
    The topmost node in the hierarchy
  • What are leaf nodes in a tree?
    Nodes without any lower nodes
  • How do you search a binary tree?
    Check root, then left or right subtree
  • What is a recursive algorithm?
    One that calls itself
  • What is the factorial of 5?
    120120
  • What is the base case in recursion?
    Condition that stops the recursion
  • What is the advantage of iteration over recursion?
    Uses fewer variables and memory
  • Why does recursion use more memory than iteration?
    Each call stores state on the stack
  • What are the advantages of recursion over iteration?
    • Expresses problems naturally.
    • Simplifies complex problems.
    • Easier to implement for certain algorithms.