Lec12 EEE13 2s1617
Lec12 EEE13 2s1617
Lec12 EEE13 2s1617
RECURSION
MOTIVATION
RECURSION
MOTIVATION
REQUIREMENTS
1. Base Case
2. Rules/Recursion Body
RECURSION
ANOTHER EXAMPLE
See fibonacci.cpp
RECURSIVE BACKTRACKING
EXAMPLE 1
See backtracking1.cpp
RECURSIVE BACKTRACKING
f(0)
f(1)
f(2)
f(3)
f(4)
f(5)
RECURSIVE BACKTRACKING
THOUGHT PROCESS
1. Think about what you want to generate
Imagine:
for()
for()
for()
…
What if you don’t know the number of strings in the vector?
RECURSIVE BACKTRACKING
A B C
D E
F G H
ALGORITHM ANALYSIS
IN GENERAL…
‣ How many times was the function called (# of Calls) *
Complexity of the function (Function Complexity)
‣ Time Complexity
> O(N) or O(N2)
ALGORITHM ANALYSIS
‣ Space complexity:
> O(N)
ALGORITHM ANALYSIS
‣ Time Complexity
> O(MN2)
ALGORITHM ANALYSIS
‣ Space complexity:
> O(N2)
ALGORITHM ANALYSIS
‣ Depth of Recursion
> O(N)
N is the size of the array
‣ Space complexity:
> O(N)
SEE YOU NEXT
WEEK :D