Join Raghavendra Dixit for an in-depth discussion in this video Understanding recursion, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Now let's try to understand how recursion…works, and why would we get that stack overflow error…in case you forgot the breaking condition,…or if the depth of recursion is big.…So let's use the factorial program to understand this.…Now as you may know that a program's runtime…usually creates a stack, which is called a method stack…or a call stack, using which it keeps track…of local variables or expression, evaluation etcetera.…Now this call stacked in context of recursive methods…is also called as recursion stack.…
It's one and the same thing, just a different name.…Now let's say that the factorial method is called…with the parameter five.…Inside the factorial method,…it checks if the parameter is zero, and it is not.…So this method returns five into factorial of four.…But factorial four itself is a method call,…whose value is not yet known.…So this expression five into factorial four,…is stored in what is called as a stack frame…and pushed into the recursion stack.…
And now the call is made to factorial four.…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.