Session 02 Flashcards

1
Q

Recursion ?

A

A function that calls itself to solve smaller instances of a problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Key elements of recursive function ?

A
  1. Base Case (Stopping condition)
  2. Recursive Case (calling itself with a simpler subproblems)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Structure of recursive function ?

A
if n == 0: # Base case (termination)
    return 1
else: # Recursive case (repetition)
    return n * factorial(n-1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where recustion used?

A

Mathematical :
* Fibonacci Series
* Factorial Calculation

Searching :
* Binary Search

Sorting :
* Merge Sort
* Quick Sort

Graph & Tree traversals :
* DFS, in-order, pre-order, post-order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Real world applications of Recursion?

A
  1. AI - Decision trees & Pathfinding
  2. Game development - Procedural generation
  3. Computer graphics - Fractals and Recursive rendering
  4. Data Structures - Trees and Graphs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Adv & DisAdv of Recursion?

A

Advantages:
* Simplify code for complex problems
* Mirrors mathematical definitions
* Ideal for devide-and-conquer strategies

Disadvantages :
* Higher memory usage
* Risk of stack overflow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Difference between Recursion and Iteration?

A

Recursion :
* Termination - Base case
* Memory usage - High (stack frames)
* Performance - Slower
* Readability - Often simpler

Iteration :
* Termination - Condition check
* Memory usage - Low
* Performance - Faster
* Readability - Sometimes complex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Backtracking ?

A

A systematic trial-and-error approach that eliminates infeasable paths.

Used in :
* Solving puzzles
* Finding optimal paths

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why Backtracking is Efficient?

A
  • Avoids time wasting on impossible solutions.
  • Quickly eliminates paths that don’t meet the problem’s conditions, saving both time and computational resources.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Backtracking vs Bruteforce?

A

Backtracking :
* Explores possibilities only when necessary, pruning invalid choices early.
* More efficient as it avoids unnecessary exploration
* Will find the solution but tries to optimize the process
* Typically use less memory
* Examlpes:
1. N-Queens
2. Sudoku solver
3. Solving mazes

Brute Force :
* Explore every possibilities even those are clearly invalid
* Less efficient, since it doesn’t avoid any paths
* Will find a solution but could be slower
* May require more memory
* Examples :
1. Checking every possible passwords
2. Brute-forcing encryption
3. Searching unsorted data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Example Algorithms of Backtracking?

A
  • Binary Strings : generating all binary strings
  • Generating k-ary strings
  • The Knapsack problem
  • N-Queens problem
  • Generalized strings
  • Hamiltonian Cycles
  • Graph coloring problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Backtracking vs Recurision?

A

Recursion :
* Approach - Function call itself
* Purpose - Divide and conquer
* Examples -
1. Factorial
2. Fibonacci
3. Sorting

Backtracking :
* Approach - Tries different possibilities
* Purpose - Optimization
* Examples -
1. N-Queens
2. Sudolu solver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Backtracking & Recursion real world issues?

A

Recursion :
* Web crawler
* File system traversal

Backtracking :
* Password cracking
* Crossworld puzzle solver
* Image segmentation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly