Developing Algorithms - AP Computer Science Principles

  1. Find the result of the algorithm: Input: 3, Output: x2x^2.
    9. Substituting x=3x=3 into x2x^2 gives 32=93^2 = 9.
  2. Which data structure is used in a breadth-first search algorithm?
    Queue. FIFO structure explores nodes level by level in graphs.
  3. What does the acronym LIFO stand for in data structures?
    Last In, First Out. Stack behavior where most recent item is removed first.
  4. Find the output of the algorithm: Input: 4, Output: x3x^3.
    64. Substituting x=4x=4 into x3x^3 gives 43=644^3 = 64.
  5. What is the purpose of using flowcharts in algorithm design?
    To visually represent the sequence of steps in an algorithm. Shows decision points, loops, and flow direction graphically.
  6. Which search algorithm operates efficiently on sorted arrays?
    Binary search. Halves search space each iteration, requiring sorted input.
  7. What does 'pseudocode' refer to in algorithm development?
    A high-level description of an algorithm using plain language. Uses structured English to outline algorithm logic before coding.
  8. Identify the main components of a typical algorithm.
    Input, process, output. The basic flow: receive data, manipulate it, produce results.
  9. What is the primary use of a hash table in algorithms?
    Efficiently store and retrieve data. Provides constant-time average access using hash functions.
  10. Which data structure is used in depth-first search algorithms?
    Stack. LIFO structure enables deep exploration before backtracking.
  11. What is the space complexity of an algorithm?
    The amount of memory used by the algorithm. Measures additional memory required beyond input storage.
  12. Identify the sorting algorithm with the best average-case performance.
    Heapsort, Mergesort, or Quicksort. All three achieve O(nlog⁡n)O(n \log n) average performance consistently.
  13. Identify the algorithm that sorts by repeatedly dividing the array.
    Merge sort. Divide-and-conquer approach splits arrays until single elements.
  14. Which structure helps in making decisions in an algorithm?
    Conditional statements (e.g., if-else). Allows algorithms to branch based on true/false conditions.
  15. What is a heuristic in algorithm design?
    A technique to find solutions faster when classic methods fail. Approximation method when optimal solutions are computationally expensive.
  16. What is the big-O notation for the worst-case scenario of bubble sort?
    O(n2)O(n^2). Requires n(n−1)/2n(n-1)/2 comparisons when array is reverse sorted.
  17. What is the base case in a recursive algorithm?
    A condition that stops the recursion. Prevents infinite recursion by providing an exit condition.
  18. Identify the algorithm used for finding the minimum spanning tree.
    Prim's or Kruskal's algorithm. Finds minimum cost to connect all vertices in graph.
  19. Which sorting algorithm is not based on comparisons?
    Counting sort. Counts frequency of elements rather than comparing values.
  20. Find the big-O notation for the worst-case of linear search.
    O(n)O(n). Must check every element when target is last or absent.
  21. What is the primary characteristic of a greedy algorithm?
    It makes the locally optimal choice at each step. Chooses the best immediate option without considering future consequences.
  22. Which algorithmic concept involves repeating a process?
    Iteration. Loops and repetition structures implement iterative processes.
  23. What is the main advantage of using recursion in algorithms?
    Simplifies the code for problems that have a recursive structure. Natural fit for tree traversals and mathematical expressions.
  24. What is the purpose of a loop in an algorithm?
    To repeat a block of code multiple times. Enables efficient processing of collections and repetitive tasks.
  25. Which algorithm strategy uses a divide-and-conquer approach?
    Merge sort. Recursively splits problems into smaller, manageable subproblems.
  26. What is an invariant in the context of algorithms?
    A condition that remains true throughout the execution. Property that helps prove algorithm correctness and termination.
  27. What is the purpose of a sentinel value in algorithms?
    To denote the end of a data structure. Special marker value indicating boundary or termination condition.
  28. Which type of loop guarantees execution at least once?
    Do-while loop. Condition checked after execution, ensuring one iteration minimum.
  29. What is dynamic programming in algorithms?
    A method for solving complex problems by breaking them down. Stores solutions to subproblems to avoid redundant calculations.
  30. What is recursion in the context of algorithms?
    A process where a function calls itself. Breaks complex problems into smaller, similar subproblems.
  31. What is the time complexity of the insertion sort in the best case?
    O(n)O(n). Already sorted arrays require minimal comparisons and shifts.
  32. Identify the algorithm that uses a queue to explore nodes in a graph.
    Breadth-first search. Queue ensures level-by-level exploration of graph nodes.
  33. Which data structure follows the LIFO principle?
    Stack. Used for function calls, undo operations, and backtracking.
  34. What is the time complexity of the quicksort algorithm in the average case?
    O(n log⁡n)O(n \, \log n). Divides array and partitions around pivot efficiently on average.
  35. What is the definition of an algorithm?
    A step-by-step procedure for solving a problem. Algorithms are systematic solutions with clear steps to solve problems.
  36. Identify the algorithm that finds the shortest path in a weighted graph.
    Dijkstra's algorithm. Uses priority queue to find minimum distances from source.
  37. Identify the algorithm that sorts by repeatedly finding the minimum.
    Selection sort. Finds smallest element and swaps to correct position repeatedly.
  38. Identify the algorithm that builds a sorted array one item at a time.
    Insertion sort. Inserts each new element into its correct sorted position.
  39. What is the role of a break statement in a loop?
    To terminate the loop prematurely. Exits loop immediately when specific condition is met.
  40. What is the big-O notation for the best-case scenario of binary search?
    O(1)O(1). Best case occurs when target is the middle element immediately.

Study these flashcards