STANFORD CS106B - Programming Abstractions & Recursive Problem Solving
Cards in this deck
(25 cards)Preview terms and definitions before starting your study session.
for, while) until a condition is met. Recursion often leads to more elegant code for certain problems but can incur higher memory overhead due to function call stack.void solve(State current_state, Solution& result) {
if (is_base_case(current_state)) {
// Process/record solution
return;
}
for (Choice choice : possible_choices(current_state)) {
// 1. Choose: Make a choice
make_choice(current_state, choice);
// 2. Explore: Recurse with the new state
solve(current_state, result);
// 3. Unchoose: Backtrack (undo the choice)
unmake_choice(current_state, choice);
}
}choose/explore/unchoose pattern in backtracking.1. Choose: Make a decision or add an element to the current partial solution.
2. Explore: Recursively call the function to find solutions based on the current choice.
3. Unchoose: Undo the decision made in the "choose" step, restoring the state to what it was before the choice. This allows the algorithm to explore other possibilities.
1. Choose: Select a character from the remaining ones.
2. Explore: Add it to the prefix and recurse with the remaining string.
3. Unchoose: Remove the character from the prefix (implicitly done by passing copies or by explicit removal if modifying a shared structure). The base case is when no characters remain, and the prefix is a complete permutation.
Vector (dynamic array), Stack, Queue, Grid, Map (hash table/BST), Set, LinkedList, Binary Search Trees (BSTs), and potentially Graphs.Related Flashcard Sets
Explore similar study materials created by the community
MONASH MTH2010 - Multivariable Calculus & Vector Calculus
Master Monash MTH2010 with this high-yield flashcard deck, covering essential multivariable and vector calculus concepts. Dive deep into partial derivatives, multiple integrals, and fundamental theorems like Green's, Stokes', and Divergence Theorem for exam success.
SYDNEY CHEM1111 - Chemical Bonding, Thermochemistry & Chemical Equilibrium
Master core University of Sydney CHEM1111 chemistry topics including VSEPR theory, Hess's Law, Gibbs free energy, and chemical equilibrium. Ideal for high-yield first-year chemistry exam preparation.
GCP Associate Cloud Engineer - Cloud IAM, Compute Engine & Networking
Master Google Cloud IAM, Compute Engine, and Networking essentials for the Associate Cloud Engineer exam. This high-yield deck covers primitive/predefined/custom roles, VPC configurations, `gcloud` deployments, and GKE administration to ensure your exam success.
JLPT N4 - Intermediate Japanese Grammar, Particles & High-Frequency Kanji
Master essential JLPT N4 Japanese grammar, particles, and high-frequency kanji with this comprehensive flashcard deck. Bridge the gap to intermediate fluency by conquering key structures like conditionals, potential forms, and crucial compound vocabulary.