201 DSA Chapter 1 Introduction in Recursion and Complexity of Algorithms
201 DSA Chapter 1 Introduction in Recursion and Complexity of Algorithms
on DSA
Dept. Computer
Science
Recursion
Data Structures and Algorithms Ngày 5 tháng 1 năm 2022 Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Dept. Computer Science
Complexity of
Faculty of Computer Science and Engineering Algorithms
Algorithm Efficiency
Ho Chi Minh University of Technology, VNU-HCM Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
1 DSA: Basic concepts Science
algorithms Recursion
Recursion and the basic
Properties of recursion components of recursive
algorithms
Complexity of
3 Complexity of Algorithms Algorithms
Algorithm Efficiency
Algorithm Efficiency Asymptotic Analysis
Problems and common
Asymptotic Analysis complexities
P and NP Problems
Problems and common complexities
P and NP Problems
Basic concepts on DSA.2
Basic concepts
Sources of Materials on DSA
Dept. Computer
Science
Recursion
source code from the following sources: Recursion and the basic
components of recursive
• The old presentation for course Data Structures and algorithms
Properties of recursion
Algorithms edited by other members in our Designing recursive algorithms
Complexity of
Approach with C++ (first edition, 2001) written Algorithms
by Richard F. Gilberg and Behrouz A. Forouzan Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
L.O.1 Determine the complexity of simple algorithms
(polynomial time - nested loop - no recursive)
L.O.1.1 Give definition of Big-O notation
L.O.1.2 Determine complexity of simple polynomial algorithms
DSA: Basic concepts
L.O.2 Manipulate basic data structures such as list, tree and graph Some concepts on data
Algorithm
L.O.2.1 Describe and present basic data structures such as: array, Pseudocode
L.O.3 Implement basic sorting and searching algorithms Recursion and backtracking
Recursion implementation in
L.O.3.1 Illustrate how searching algorithms work on data structures: C/C++
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Data
Data is information that has been translated into a form
that is more convenient to calculate, analyze.
DSA: Basic concepts
Some concepts on data
Example Algorithm
Pseudocode
• Discrete data can only take certain values (like whole Asymptotic Analysis
Problems and common
numbers) complexities
P and NP Problems
• Continuous data can take any value (within a range)
Dept. Computer
Science
Recursion
Recursion and the basic
Example components of recursive
algorithms
character \0, ..., ‘A’, ‘B’, ..., <, >, ... Asymptotic Analysis
Problems and common
‘a’, ‘b’, ..., ∼ complexities
P and NP Problems
Dept. Computer
Science
1 2 3 5 8 13 21 34 Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Definition Recursion
Recursion and the basic
together with the operations that are meaningful for the Properties of recursion
Designing recursive algorithms
Complexity of
1 Declaration of data Algorithms
Algorithm Efficiency
2 Declaration of operations Asymptotic Analysis
Problems and common
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
Dept. Computer
Science
Interface
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
Implementation C/C++
Complexity of
Algorithms
• Array Algorithm Efficiency
Asymptotic Analysis
• Linked list
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
What is an algorithm?
DSA: Basic concepts
The logical steps to solve a problem. Some concepts on data
Algorithm
Pseudocode
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
What is a program? Designing recursive algorithms
Recursion and backtracking
Complexity of
(Niklaus Wirth) Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
instructions using basic Problems and common
relaxed syntax being easy control structures (sequen-
complexities
P and NP Problems
to read tial, conditional, iterative)
Dept. Computer
Science
Algorithm Header
• Name
• Parameters and their types
• Purpose: what the algorithm does DSA: Basic concepts
Some concepts on data
Dept. Computer
Science
Algorithm average
Pre nothing
Post the average of the input numbers is printed
DSA: Basic concepts
1 i=0 Some concepts on data
2 sum = 0 Algorithm
Pseudocode
Dept. Computer
Science
components of Recursion
Recursion and the basic
components of recursive
algorithms
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Definition
Recursion is a repetitive process in which an algorithm
calls itself.
• Direct : A → A DSA: Basic concepts
Some concepts on data
• Indirect : A → B → A Algorithm
Pseudocode
Recursion
Complexity of
Algorithms
Dept. Computer
Science
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Hình: Factorial (3) Recursively Algorithm Efficiency
Dept. Computer
Science
Recursion
5 i=1 Recursion and the basic
components of recursive
6 factoN = 1 algorithms
Properties of recursion
9 i=i+1 Complexity of
Algorithms
10 end Algorithm Efficiency
Dept. Computer
Science
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
labelformat=empty
Hình: Calling a Recursive Algorithm (source: Data Structure - A Basic concepts on DSA.23
Basic concepts
on DSA
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
sub-problem Pseudocode
Recursion
Recursion and the basic
components of recursive
Complexity of
Dept. Computer
Science
Designing recursive
Some concepts on data
Algorithm
Pseudocode
Recursion
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
1 Determine the base case (stopping case). Recursion and the basic
components of recursive
algorithms
Properties of recursion
Complexity of
3 Combine the base case and the general Algorithms
Algorithm Efficiency
Dept. Computer
Science
implementation. Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
26 8 19 93 Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
26 8 19 93 Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
1 Algorithm printReverse(list)
2 Prints a linked list in reverse. DSA: Basic concepts
Some concepts on data
3 Pre: list has been built Algorithm
Pseudocode
4 Post: list printed in reverse
Recursion
Recursion and the basic
components of recursive
5 if list is null then algorithms
Properties of recursion
6 return Designing recursive algorithms
Recursion and backtracking
7 end Recursion implementation in
C/C++
8 printReverse (list -> next) Complexity of
9 print (list -> data) Algorithms
Algorithm Efficiency
10 End printReverse Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Definition
DSA: Basic concepts
" a if b = 0 Some concepts on data
Algorithm
gcd(a, b) = b if a = 0 Pseudocode
Dept. Computer
Science
1 Algorithm gcd(a, b)
2 Calculates greatest common divisor using the Euclidean
algorithm. DSA: Basic concepts
Recursion
Recursion and the basic
8 if a = 0 then C/C++
Complexity of
9 return b Algorithms
Dept. Computer
Science
Definition Algorithm
Pseudocode
0 if n = 0
"
Recursion
F ibo(n) = 1 if n = 1 Recursion and the basic
components of recursive
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Fibo(n)
DSA: Basic concepts
Some concepts on data
Algorithm
Pseudocode
Complexity of
Algorithms
Fibo(n-3) + Fibo(n-4) Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Fibo(4) 3
Recursion
Recursion and the basic
Dept. Computer
Science
1 Algorithm Fibo(n)
DSA: Basic concepts
2 Calculates the nth Fibonacci number. Some concepts on data
Algorithm
3 Pre: n is postive integer Pseudocode
Dept. Computer
Science
Dept. Computer
Science
Move disks from Source to Destination using Auxiliary:
1 Only one disk could be moved at a time.
2 A larger disk must never be stacked above a smaller
one. DSA: Basic concepts
Some concepts on data
3 Only one auxiliary needle could be used for the Algorithm
Pseudocode
intermediate storage of disks. Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
1 Algorithms
2 Algorithm Efficiency
Asymptotic Analysis
Dept. Computer
Science
2 Recursion
Recursion and the basic
3 1 components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
Recursion
Recursion and the basic
3 2 1 components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
1 Recursion
Recursion and the basic
3 2 components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
1 Recursion
Recursion and the basic
2 3 components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
Recursion
Recursion and the basic
1 2 3 components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
2 Recursion
Recursion and the basic
1 3 components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
2 Recursion
Recursion and the basic
3 components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
move(3,
A, C, B)
Recursion
Recursion and the basic
move(2, move(1, move(2, components of recursive
A, B, C) A, C, B) B, C, A) algorithms
Properties of recursion
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Dept. Computer
Science
move(n, A, C, B)
DSA: Basic concepts
Some concepts on data
Algorithm
Pseudocode
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Complexity Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Dept. Computer
Science
Complexity
T (n) = 1 + 2T (n − 1)
DSA: Basic concepts
=> T (n) = 1 + 2 + 22 + ... + 2n−1 Some concepts on data
Algorithm
Recursion
=> T (n) = O(2n ) Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Dept. Computer
Science
1 Algorithm move(val disks <integer>, val source
<character>, val destination <character>, val
auxiliary <character>)
2 Move disks from source to destination. DSA: Basic concepts
Some concepts on data
3 Pre: disks is the number of disks to be moved Algorithm
Recursion
5 print("Towers: ", disks, source, destination, auxiliary) Recursion and the basic
components of recursive
6 if disks = 1 then algorithms
Properties of recursion
7 print ("Move from", source, "to", destination) Designing recursive algorithms
Recursion and backtracking
8 else Recursion implementation in
C/C++
9 move(disks - 1, source, auxiliary, destination) Complexity of
10 move(1, source, destination, auxiliary) Algorithms
Algorithm Efficiency
13 return
14 End move
Basic concepts on DSA.50
Basic concepts
on DSA
Dept. Computer
Science
Recursion and
Some concepts on data
Algorithm
Pseudocode
Recursion
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Definition
DSA: Basic concepts
A process to go back to previous steps to try unexplored Some concepts on data
Algorithm
alternatives. Pseudocode
Recursion
Recursion and the basic
components of recursive
backtracking.jpg algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
Hình: Goal seeking C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
1 Algorithm putQueen(ref board <array>,
val r <integer>)
2 Place remaining queens safely from a row DSA: Basic concepts
Recursion
3 Pre: board is nxn array representing a Recursion and the basic
components of recursive
algorithms
Complexity of
Algorithms
5 Post: all the remaining queens are safely Algorithm Efficiency
Asymptotic Analysis
6 else Recursion
Recursion and the basic
Complexity of
10 end Algorithms
Algorithm Efficiency
end
Asymptotic Analysis
11 Problems and common
complexities
13 End putQueen
Basic concepts on DSA.55
Basic concepts
Eight Queens Problem on DSA
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
implementation in Recursion
Recursion and the basic
components of recursive
algorithms
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
c o u t << "The␣ " << num << " t h ␣ F i b o n a c c i ␣ number Properties of recursion
Designing recursive algorithms
} Complexity of
Algorithms
Algorithm Efficiency
Dept. Computer
Science
#i n c l u d e <i o s t r e a m >
u s i n g namespace s t d ;
Recursion
i n t main ( ) { Recursion and the basic
components of recursive
algorithms
i n t numDisks ; Properties of recursion
Designing recursive algorithms
c o u t << " P l e a s e ␣ e n t e r ␣ number ␣ o f ␣ d i s k s : ␣ " ; Recursion and backtracking
Dept. Computer
Science
v o i d move ( i n t n , char s o u r c e ,
char d e s t i n a t i o n , char a u x i l i a r y ) {
static int step = 0; DSA: Basic concepts
Some concepts on data
Algorithm
i f ( n == 1 ) Pseudocode
c o u t << " S t e p ␣ " << ++s t e p << " : ␣Move␣ from ␣ " Recursion
<< s o u r c e << " ␣ t o ␣ " << d e s t i n a t i o n << e n d l Recursion
; and the basic
components of recursive
else { algorithms
Properties of recursion
move ( n −1, s o u r c e , a u x i l i a r y , d e s t i n a t i o n ) ; Designing recursive algorithms
Recursion and backtracking
move ( 1 , s o u r c e , d e s t i n a t i o n , a u x i l i a r y ) ; Recursion implementation in
move ( n − 1 , a u x i l i a r y , d e s t i n a t i o n , s o u r c e ) ; C/C++
Complexity of
} Algorithms
return ; Algorithm Efficiency
Asymptotic Analysis
} Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Dept. Computer
Science
Complexity of
Algorithms
• Thus in this course the better algorithm is Algorithm Efficiency
Asymptotic Analysis
the one which runs faster (has smaller Problems and common
complexities
P and NP Problems
time complexity).
Basic concepts on DSA.63
Basic concepts
How to Calculate Running time on DSA
Recursion
grows with the input size f (n). Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
9000
Recursion and backtracking
8000
Recursion implementation in
7000 C/C++
6000 Complexity of
Time (ms)
5000 Algorithms
4000 Algorithm Efficiency
Asymptotic Analysis
3000
Problems and common
2000 complexities
P and NP Problems
1000
0
0 20 40 60 80 100
Input Size
Basic concepts on DSA.64
Basic concepts
How to Calculate Running Time on DSA
Dept. Computer
Science
Dept. Computer
Science
Recursion
often difficult to determine Recursion and the basic
components of recursive
algorithms
Dept. Computer
Science
Recursion
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
7000 Algorithm
algorithm Pseudocode
6000
Time (ms)
• Run the program with 5000
Recursion
Recursion and the basic
Dept. Computer
Science
Recursion
running time on other inputs not included Recursion and the basic
components of recursive
algorithms
Dept. Computer
Recursion
inputs C/C++
Complexity of
Algorithms
hardware/software environment
Basic concepts on DSA.70
Basic concepts
Primitive Operations on DSA
Dept. Computer
Science
• For theoretical analysis, we will
count primitive or basic
operations, which are simple DSA: Basic concepts
Some concepts on data
Algorithm
Recursion
•
Algorithm Efficiency
Dept. Computer
Science
Recursion
Recursion and the basic
currentMax = a [0] // 2 components of recursive
algorithms
i = 1 // 2 Properties of recursion
Designing recursive algorithms
while ( i < n ) // n Recursion and backtracking
if ( currentMax < a [ i ]) // 2n -2 Recursion implementation in
C/C++
currentMax = a [ i ] // 2n -2
Complexity of
i = i + 1 // 2n -2 Algorithms
return currentMax // 1 Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
operation Pseudocode
Recursion
• b = Time taken by the slowest primitive Recursion and the basic
components of recursive
operation algorithms
Properties of recursion
Complexity of
Algorithms
• Hence, the running time f(n) is bounded Algorithm Efficiency
Asymptotic Analysis
Dept. Computer
Science
Recursion
• Thus we focus on the big-picture which is Recursion and the basic
components of recursive
algorithms
Dept. Computer
Science
The number of times the body of the loop is replicated is DSA: Basic concepts
n. Some concepts on data
Algorithm
Pseudocode
f(n) = n Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
for ( i = 0; i < n ; i += 2) C/C++
The number of times the body of the loop is replicated is Algorithm Efficiency
Asymptotic Analysis
f(n) = n/2
Basic concepts on DSA.75
Basic concepts
Logarithmic Loops on DSA
Dept. Computer
Science
Multiply loops
i = 1
while ( i <= n )
application code DSA: Basic concepts
i = i x 2 Some concepts on data
Algorithm
Pseudocode
Recursion
Divide loops Recursion and the basic
components of recursive
algorithms
Properties of recursion
i = n Designing recursive algorithms
i = i / 2 Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
The number of times the body of the loop is replicated is Problems and common
complexities
P and NP Problems
f(n) = log2 n
Dept. Computer
Science
i = 1 Pseudocode
Dept. Computer
Science
Example
Dept. Computer
Science
Example
Dept. Computer
Science
• Examples Algorithm
Pseudocode
Recursion
• 103 n + 105 is a linear function Recursion and the basic
components of recursive
Complexity of
factors to focus on the essential part Algorithms
Algorithm Efficiency
Dept. Computer
Science
Recursion
measurement of an algorithm’s Recursion and the basic
components of recursive
algorithms
Complexity of
Algorithms
change the function’s magnitude are Algorithm Efficiency
Asymptotic Analysis
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
• Big-Oh: O(.) Recursion and the basic
components of recursive
algorithms
• Big-Omega: Ω(.)
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
• The big-Oh notation allows us to Recursion and the basic
components of recursive
algorithms
Complexity of
Dept. Computer
Science
Complexity of
• Why? Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Example
f (n) = c.n ⇒ f (n) = O(n)
f (n) = n(n + 1)/2 = n2 /2 + n/2 ⇒ f (n) = O(n2 )
DSA: Basic concepts
Some concepts on data
Recursion
one. Recursion and the basic
components of recursive
algorithms
Complexity of
Algorithms
Some example of Big-O: Algorithm Efficiency
Asymptotic Analysis
n!
Basic concepts on DSA.86
Basic concepts
Big-Oh and Growth Rate on DSA
Dept. Computer
Recursion
means that the growth rate of f (n) Recursion and the basic
components of recursive
algorithms
Properties of recursion
g(n) C/C++
Complexity of
Algorithms
• We can use the big-Oh notation to Algorithm Efficiency
Asymptotic Analysis
Problems and common
growth rate
Basic concepts on DSA.87
Basic concepts
Standard Measures of Efficiency on DSA
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
log2 n Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
• big-Omega
• f (n) is Ω(g(n)) if there is a constant c > 0 DSA: Basic concepts
and an integer constant n0 ≥ 1 such that Some concepts on data
Algorithm
Recursion
Recursion and the basic
• big-Theta
components of recursive
algorithms
Properties of recursion
Dept. Computer
Science
g(n) Algorithm
Pseudocode
Complexity of
Dept. Computer
Science
Recursion
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
1 2 3 5 8 13 21 34 55 89 Recursion implementation in
C/C++
Complexity of
Algorithms
T (n) = 1 + T (n/2) ⇒ T (n) = O(log2 n) Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
Complexity of
T (n) = O(log2 n) Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
8 5 21 2 1 13 4 34 7 18
Recursion
Dept. Computer
Science
19 8 3 15 28 10 22 4 12 83
Recursion
T (n) = O(n) + 2T (n/2) Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
Complexity of
Dept. Computer
Science
P and NP Problems
Pseudocode
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Science
chine). Recursion
Recursion and the basic
components of recursive
algorithms
Complexity of
Algorithms
deterministic machine). Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems
Dept. Computer
Travelling Salesman Problem: Science
possible round trip that both starts and finishes at any one Pseudocode
8 Properties of recursion
7 Recursion implementation in
C/C++
9 5 Complexity of
15 Algorithms
a d Algorithm Efficiency
6 9 Asymptotic Analysis
Problems and common
complexities
8 P and NP Problems
11
e f
Dept. Computer
Science
Recursion
8
b c Recursion and the basic
components of recursive
algorithms
7 Properties of recursion
Designing recursive algorithms
9 5 Recursion and backtracking
15 Recursion implementation in
a d C/C++
Complexity of
6 9 Algorithms
8 Algorithm Efficiency
11 Asymptotic Analysis
Dept. Computer
Science
NP-complete: NP and every other problem in NP is
polynomially reducible to it.
NP algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
P = NP? complexities
P and NP Problems
Dept. Computer
Science
THANK YOU.
Pseudocode
Recursion
Recursion and the basic
components of recursive
algorithms
Properties of recursion
Designing recursive algorithms
Recursion and backtracking
Recursion implementation in
C/C++
Complexity of
Algorithms
Algorithm Efficiency
Asymptotic Analysis
Problems and common
complexities
P and NP Problems