Topic 2

Cards (89)

  • What is the purpose of simplifying a problem in programming?
    To represent it in an understandable way
  • What is the first construct used in structured programming?
    Sequence
  • How is code executed in a sequence construct?
    Line-by-line from top to bottom
  • What is the purpose of branching in programming?
    To run code if a condition is met
  • What is another term for branching?
    Selection
  • What does iteration allow in programming?
    To execute code multiple times
  • What types of loops are used in iteration?
    FOR, WHILE, REPEAT UNTIL
  • What is count-controlled iteration?
    Iteration repeated a specific number of times
  • How would you write a count-controlled loop in Python?
    for i in range(0,10):
  • What is condition-controlled iteration?
    Iteration continues until a condition is met
  • How would you write a condition-controlled loop in pseudocode?
    while i <= 20:
  • What is recursion in programming?
    A subroutine calls itself during execution
  • What is the stopping condition in recursion?
    The condition at which recursion stops
  • How does recursion compare to iteration?
    Produces the same result but is different
  • What is an advantage of using recursion?
    Fewer lines of code, less prone to errors
  • Why is it essential to define recursive subroutines clearly?
    To reach a stopping condition after finite calls
  • What is a common example of a recursive function?
    Factorial function
  • What happens each time a recursive function calls itself?
    A new stack frame is created
  • What is stored in a stack frame?
    Parameters, local variables, return addresses
  • What does it mean for a subroutine to unwind?
    Information is popped off the call stack
  • What is a disadvantage of recursion?
    Inefficient use of memory
  • What is a stack overflow?
    When the call stack runs out of memory
  • What is tail recursion?
    A more efficient form of recursion
  • Why is recursion difficult to trace?
    Due to multiple function calls
  • What does scope refer to in programming?
    The section of code where a variable is available
  • What are local variables?
    Variables accessible only within their block
  • Why are local variables considered good practice?
    They ensure subroutines are self-contained
  • What are global variables?
    Variables accessible across the whole program
  • What is a disadvantage of global variables?
    They can be unintentionally overwritten
  • What happens if a local variable has the same name as a global variable?
    The local variable takes precedence
  • What is modular programming?
    A technique to split programs into modules
  • What is the benefit of modular design?
    Makes problems easier to understand and manage
  • What is the top-down approach in programming?
    Breaking down problems into sub-problems
  • What is stepwise refinement?
    Breaking down problems into smaller tasks
  • What are subroutines?
    Named blocks of code performing specific tasks
  • What is the difference between procedures and functions?
    Functions must return a value, procedures do not
  • How can procedures return values?
    They can return multiple values
  • What is an example of a function?
    Function isEven(number) returns True or False
  • What happens when parameters are passed by value?
    A copy of the value is passed
  • What does passing by reference mean?
    The address of the parameter is given