Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
Data Structures
&
Algorithms
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
1. Function
2. The Concept Of Stack
3. The Sequence Of Execution During A Function Call
4. Parameter Passing & Call By Reference
5. Resolving Variable References
6. Recursion
7. Stack Overheads In Recursion
8. Writing A Recursive Function
9. Types Of Recursion
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
–
!"#$##%&'"
–
(!)#"*# "!!""+",!#"*
–
-(!".'*
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
# "$/#012#3
4
# 567
./#56787993
4
5 9017
:
# 7
:
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
;-<
–
-stack $'%%"!"#"#=!"#
>##= ",$+(""!!push"pop
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
?@AB--CC
–
When the funcon is called, the current execuon is temporarily stopped and the
control goes to the called funcon. Aer the call, the execuon resumes from the
point at which the execuon is stopped.
–
To get the exact point at which execuon is resumed, the address of #% )#
###%#"*. When the funcon call completes, the address
at the top of the stack is taken.
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
?@AB--CC
–
Funcons or sub-programs are implemented using a stack.
–
When a funcon is called, the address of the next instrucon is pushed
into the stack.
–
When the funcon is !nished, the address for execuon is taken by using
the pop operaon.
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
D--E-B
–
passing by value
•
#%"!,.""&#%"!! "#%"
–
passing by reference
•
changed value aer the funcon completes
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
N=8
(Method)
N=8
(Method)
5F
5F
5F
5F
N=8
(Method)
N=8
(Method)
5F
5F
5G
5G
"+,$"!
"+,$.
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
./#3
4
5967
:
.;/#E3
4
E5E967
:
.?/#3
4
5967
:
By Value ???
By Reference???
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
FCB--HC
IJ%""",!",!,$+ !(!.2#%!"!
>+ (.
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
K
- A method of programming whereby
a funcon directly or indirectly calls
itself
- Problems: stop recursion?
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
K
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
K
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
K
"#'
"#'
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
K
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
K
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
L-<-
–
' (#"#!#M#%(#%."#%#"*
%"
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
GJB-
–
",!#'#"(+" ""#"!'"$%(
."(+" !',".#"*%"
–
"(+" $%"#(.$2
# "+2")(
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
N
–
C-/#$OP%3
–
-C/QR3
–
H-/%S(%T3
–
A-C/Q"#$O3
–
/!U+3
–
-C/#VW+%X3
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
N
–
C-
•
!$ "*"+!"!!##!."% #%.
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
N
-
-C
"!". .!"
#"!2#%"!!#%!"##%+#%.&2
#%"!.#%"!!#
Author: Trần Duy Thanh – Phone : 0987773061- Email: – Blog:
N
IA-C
-)("!.#%"#2.$'#"'#
"(#"."!!#%."!!2'!%"")("!
,."!!!"##%Y.#%"#"#/)("!
"+.#%'n! #2#%'!,O/a
3."!!
'%""( ,3