Join Raghavendra Dixit for an in-depth discussion in this video Tail recursion, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] In the last section…we saw how a recursion called stack works.…Now can there be a way…to avoid stack overflow kind of errors?…Think about it.…Well there is another type of recursion…called tail recursion,…which if optimized for, can avoid stack overflow errors.…So the kind of recursion that we just saw…was head recursion.…So we can write a program using tail recursion like this.…We write a factorial method…which takes an int type of parameter…and further in detail we want to calculate the factorial of…and under n type of parameter result,…which holds the value of the previous calculation.…
So every time we calculate the factorial…the result of the calculation…is passed in the result parameter.…You will see what I mean by that in a second.…Then we write the breaking condition,…where if n is equal to zero,…we just return the result itself,…because that should be holding the value of the factorial.…Otherwise we would cause a recall the factorial method…and every time we do so, we decrease the value of n by one.…
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.