This session effectively bridges the gap between abstract algorithmic theory and pragmatic industry application by grounding recursion in real-world financial logic. It transforms a foundational programming concept into a tangible tool for solving complex, multi-layered business problems.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Day 4 - International level Bootcamp on DSA for DeepTechAdded:
Okay. Hello.
Good evening everyone. Let's start our session in next 2 minutes now.
Good evening guys. Can you hear me? Can you please respond in chat box?
Yep. Let's wait for a minute and we'll start our session.
Fine. Let me share my screen.
Today is day four. I want to discuss one very important topic recussion.
Just a second.
Just I'm admitting all So today just a second let me reserve theation for others otherwise more people will be ready to disturb the session.
Okay. So today is day four and I'm going to discuss about everybody please go on mute.
Yep.
These things I'm going to discuss in today's session like regression fundamentals, basic regression problems, factorial and the series lot of things very important topic again. Okay, I hope you know right wherever you go.
I mean all the product best companies for sure they'll be asking these things only problem solving how you how you get problem solving. If you're good in data structures then problem solving you can understand in a better way.
Fine. I will start with recussion with some real life examples followed by real life examples followed by real time examples then why recussion is more important in data structures I'll take some one or two banking examples in insurance examples mostly I will be taking mostly I'll be taking banking and insurance examples in the upcoming days the reason is I mostly worked on banking and insurance examples that is the reason I'll be discussing more. Okay, let us start the session guys. Lot of things, lot of important things.
Recussion, I will start with recussion.
What is recussion? Generally, recursion means a function calling itself again and again until a condition is met. Until a condition is met.
completely concentrate on my session.
Recussion means recursion means see here recursion means in simple words. I'll start with very simple and I'll go with very advanced things. A function calling itself.
Don't message anything in chat box.
Listen very carefully again and again.
Until until a condition is met.
I mean how can I say you know in our normal words do the same work.
Do the same work repeatedly but with smaller input.
Smaller input each time.
For example, for example, you are climbing the stairs. You are climbing the stairs. To reach step five, you first reach step four. To reach step four, you first reach step three and so on. Finally, step one. Okay. So base case same in recursion function keeps calling itself.
Function function keeps calling itself. I'll explain with very beautiful examples itself. Okay. Stop.
stop when it reaches the base condition.
When it reaches the base condition.
Okay.
Now see here why recussion is more important in DSA.
Why it is so popular?
Why recursion is important in DSA? Why are we discussing here?
It helps to solve the complex problems very easily.
It helps most important points. I will start with some theoretical points and completely practical approach. It helps to solve the complex problems.
Complex problems easily and used in everywhere. trees, graphs, backtracking everywhere we are going to use and it make the code it make the code taught and clean.
So we are having different different algorithms in DSA used in algorithms used in algorithms like binary search everywhere. Binary search like merge sort merge sort sort DFS depth first search depth first search okay I mean take one note here without recursion Without recussion, many DSA problems, many DSA problems become hard to implement. Hard to implement. Okay. Now take these points.
I want to discuss about more real time examples. For example, function calling itself. I want to show you one real time one or two real time examples.
just take these points everybody I'll be giving 2 minutes time then I'll explain DF means the depth first going forward I'll be discussing one it is one of the DSA concept I will discuss Very good. Many people responded function calling itself. Just now I have seen your messages.
I want to discuss one or two real time game scenarios. Then let's go with examples.
Once you're done, you can respond in chat box.
So someone is asking about if there is no base case in recussion the program will never stop calling itself. It goes into an infinite loop and finally crashes.
What happens without a base case?
Function keep on calling itself again and again. Memory keeps on increasing stack memory basically. Finally program throws an error called stack overflow error. Stack overflow error.
Shall I show you one example for this?
If there is no base case, I can tell you one real time example if you want.
uh for example generally uh I want to discuss someone is asking about if there is no base case this one I told it stops when it hits the base condition but someone is asking if there is no base condition what will happen. Let me open Eclipse IDE.
by Python here I'm not going to discuss anything about Python all the 30 days we are going to discuss by using Java only data structures here I'm going to discuss by using Java we can work with data structures by using either Java Python C or C++.
Okay. Now let me complete this example. I open my Eclipse ID.
This is our workspace. Let me click on launch.
Yes, design patterns is necessary for interview purpose. At least you should have some idea what are the design patterns we are having creational structural all these things.
I'm closing all the files today what we have discussed. I'm going to create a separate package for today's things.
Even while you're practicing, try to practice like this. Now, new package com.modu dot dsa dot d4.
Right click on your package new. For example, if there is no base case, I'll show you a very small example.
For example, if there is no base case h see here, vester of int.
Okay. Now, so what should happen here? System del.
of n okay test of n minus one so keeps calling forever this one same test right again inside the test I'm calling this it keeps calling forever Double slash is for comments. Why I have given multiple times.
Okay. Keeps on calling forever. Java program execution starts from the main method. Me click on control space.
Now tell me if I give test of five.
What is the output here?
Sorry. First let me create object.
No base case.
OBJ is equal to mu no base case by using objects we need to take all the methods right if I run this first five will be printed next five minus 1 4 5 - so again every time the value will pass here if you see here 5 4 3 2 1 See here finally what we are getting it's keep on running what we are getting stack overflow error it never stops why because -1 -2 - 3 it's keep on calling right there is no base condition finally it crashes and it has given stack overflow every recursive call uses the stack memory only memory is limited if the call is never stops memory gets full and JVM throws an error JVM throws an JVM throws an error just a Yes.
uh we are discussing something here.
Okay. Memory is limited. If call never stops, right? Memory gets full. J will throw an error.
For example, if you want to stop it, for example, if uh if n is equal to zero, we can stop it like this. We can write the code inside this here. If of n =0 then just return nothing.
Now what we'll get the output only we'll get up to 5 4 3 2 1 if it is zero it will stop.
Clear?
Who has this question? I hope you understood the concept. Oh, so they are completely in Rohan lot of freshers are there if I don't explain this kind of things right might be you are already aware how much I can cover in a month I'll be covering if you think that if you are not able to pop up with these things okay whoever are asking some doubts right I need to respond right yes they are not aware they're asking these questions I need to explain right like you I cannot ask this question Right? At least you don't know these kind of things. Can I ask this kind of questions? If someone ask you, you might not be knowing something. If I ask the same thing, it won't be good. Right?
For you, it is a simple doubt for them.
It's a hard one.
It should not be like this. Yes, definitely we'll go with some speed. But whenever they are having some question, right, I need to answer, right?
Don't mind Rohan.
Is it clear guys?
Yes, we can write in multiple way. We can write a single code in multiple ways.
Fine.
Now let's come back.
I don't know who has asked this question but uh I hope it is clear for that person.
Fine. Now I want to disc as I told you right I want to discuss some real time examples like banking or insurance companies where exactly we are going to use this kind of things? Any idea guys?
For example, you know one thing I think Rohan or someone has asked me I'm not going bit faster. Lot of people saying that sir you are going very fast. Can you explain bit slowly?
Everyone should understand and uh we cannot satisfy everyone right am I correct?
Some examples I want to discuss here.
For example, you know about loan EMI calculation, right? It is a repeated monthly loan EMI calculation.
Loan EMI calculations repeatedly.
So what happens?
Every month same formula applied right every month just take simple example don't go to more complex same formula applied previous balance next balance previous balance precursive approach can simulate this previous balance then next balance same every month.
For example, if you take some insurance example, insurance example, policy renewal reminder, check every year. If not expired, check the next year. Same process repeated. This is also a recussion concept.
Here is exactly in real time applications where we are going to use if it is insurance policy renewal remainder check every year if not expired. Right.
Take next here also.
Same process repeated.
Clearer where exactly that generally when you are learning something you need to think that where we are going to use this concept in real time. Even Java also whatever it is same process repeated. This is nothing but recussion concept.
Clear?
Can you tell me some recussion sample programs?
So someone is asking about banking example. Uh so generally for example a customer take a loan of 10,000. Assume that a customer has taken a loan of 10,000. Bank has added a 10% interest.
Customers base 2,000. Right? We want to calculate the remaining parents after n months.
See this example once in a better way. For example, you are the customer.
Okay. You have taken a loan of 10,000 every month.
Bank adds 10% interest.
10% interest. I mean customer pays how much?
10% means 2,000.
For example, we need to calculate the remaining balance after months, right? Every time we need to calculate the remaining balance after n months.
How recussion here?
New month, new balance depends on previous month balance.
Each month what happens here?
New balance depends on previous month balance.
Previous month balance.
Okay. So same formula repeats every month right?
Same formula repeats every month.
So we use recursion clear concept factorial has given Fibonacci series correct is it clear now?
Yeah, just take these points I want to discuss with an example. Very good.
Or we can do one thing ma instead of discussing about fabric or factorial.
Shall we discuss this kind of things sir? Banking example I think it would be better for you people.
Just take these things.
a small example I'll be discussing then factorial these kind of things anyway you can practice right I'll show you yeah this loan example I'm planning to explain now so that you'll be Done. Now shall we go with an example now?
Shall we start the examples?
Yeah, same example here. Whatever I discussed, I want to show you with an example.
Uh where is the eclipse?
Let me close another workspace.
a small this loan example only I'll show you.
So from now onwards if you want to ask any doubt as related to real time series or else some other examples you can practice completely real time examples I'll be discussing what I will do you know I'll be creating a new package for this example listen very carefully new package comsc C dot day4 dot banking okay fine right click new class for example I'm creating a class called bank now listen very carefully how we are going to work with recursion in real time I want to show you so double Calculate balance of int months comma double balance.
For example, if months is equal to double equal to zero, written balance.
This is base case.
base case is very important.
Okay. Now what we need to check here balance is equal to balance is equal to balance plus interest rate we need to calculate right balance into 10% means 0.10 10.
We are adding the 10% interest here for your understanding purpose. Add 10% interest again after that balance is equal to balance minus 2,000 monthly payment.
Right?
This is monthly payment here written calculate balance of we need to minus the months right months minus 1. This is recursive call here.
Recursive call. Listen very carefully. Now I want to create main method.
For example, double result is equal to for example 3 months.
I'll do one thing. I will make this method as static directly. You can call static methods you can access directly.
So calculate balance of for example 3 months 10,000 amount system.out.t print of remaining balance for your understanding purpose plus result once. Let me run this code.
So how it is going to calculate? Just a second guys.
3 months, right?
For example, if I want to calculate 3 months, for example, if you know mathematics here, the same thing I want to show you with the normal explanation.
month one first. Okay. Now, how it is going to work?
10,000. Just a second.
10,000 plus 10% right 10,000 + 10% and 10 11,000 right so we are paying 2,000 that means 11,000 minus 2,000 now how much It is 9,000.
Similarly, month two.
Listen very carefully. Calculations I'm doing here.
Month two. So, how much you have here?
9,000 + 10%. General in the real time also if you take some loan, they'll be working like this. 9,000 + 10% 9,000 + 900 and 9,900 9,900 again 9,900US 2,000 if I make you bor don't uh I'm not making you bor right like this it is going to do calculations again month three here I'm calculating for 3 months again 7,900 + 10%.
I mean approximately how much 10% 790 790 + 7,900 790 plus 8,690 8690 8690 Coding is easy than this calculations 86 690 - 2,00 690.
Save it once again. Let me run this.
Same output we got. Right.
Clear up.
Just try to understand the code. If you are facing any issues, let me know. Try to understand the logic. Try to understand the calculation. See the output. Everybody step by step we need to write the code map. It's not much difficult.
Able to understand now real time example.
Guys please respond.
How was the example? Is it good?
Why it is balance plus balance into 0.10%.
We need to calculate interest. Right?
After calculating the interest we are adding to actual balance.
It will take some time to explain. Maybe it may take more time but concept is very good and very important.
Is it clear guys? No, what about others? concept clearer everybody I'll be giving two minutes time try to understand the code if you have any questions let me know coding is more easy than these calculations I Okay.
Yes. Amount we have to pay is 2,000 per month. Correct. Mark on. Scroll down.
Nothing is there to scroll down here.
That's it.
I have a question here. If you don't have any questions, I have a question.
Why this is recursion? Why? Because function is calling itself for each month. Each step depends on the previous result.
Stops when month is equal to zero. The same I have written right base case realtime banking use cases maloney calculations interest accumulation credit card outstanding tracking uh for all these things we are going to use you need to think like this for this month calculate then ask the same question for the previous clearer if you are good right I'll take some insurance or e-commerce example No. Shall I take one in example guys?
Same for recursion.
Now related to Fibonacci series factorial these programs you can practice right?
I did not get you.
We can give any number of months. It gives some amount.
It is not infinite. You are giving a fixed number of months, right?
The recussion runs only that many times then it stops.
3 months means three calls. 100 ones means 100 calls. Always it is finite only.
You can give any number here. 100,000 10,000 whatever it is it look like unlimited but each time it runs only for the number you give again I told you related to basic if you give a very large number right too many recursive calls stack memory gets full again you'll get stack overflow Sir, result number 20.
Yes, for 3 months you are getting here and interest is applied on the updated balance every month.
How do we stop recursion early if balance become zero or negative?
Just we need to add one more condition.
We already had months is equal to zero.
Right? Now you can add if balance is less than or equal to zero.
loan closed early return zero. That's it.
We need to add one more condition.
For example, if the balance is 5,000 here, then after couple of months balance will become zero or negative immediately it will stop. No need to continue the remaining months, right?
It saves the unnecessary calculations.
That's what I'm saying. N you can learn any in any language. You are learning the concept here. What is recussion? You're understanding. You can write the code by using Python or Java.
Whatever the language you know accordingly you are going to write here how I am writing maybe maybe by using Python it may be easy but I am good with Java that is the reason I am writing the code by using Java clear if you are good we'll go for another example we will not waste time I want to discuss some incident example now shall we go for the next example just uh take an understanding for 2 minutes of this program. I'll explain the next example on recussion.
Both are good languages. Next four years.
Next four years. No, not only next four years. Anytime.
shall explain the next example guys.
that 20 programs for day one assignment that is enough for array today also just make me remember at 8:45 I'll be giving one more assignment related to recussion and these Okay, fine.
Now, let me open the notepad.
I'm trying to explain one more example, guys.
For example, incidence example I want to explain today.
For example, you are a customer. A customer is having one insurance policy.
Okay. Initial premium.
Initial premium 5,000 every year.
Every year premium increases by 5%.
I want to calculate the premium after years. N years means might be 10 years or 3 years like that.
We want to calculate premium after n years. This is my requirement.
Okay. New premium. How recussion fits here?
No. New premium depends on previous year premium. Right? Same formula repeats every year. Perfect case for recussion.
Note for your understanding purpose.
New premium depends on previous year premium. For your understanding purpose, same formula repeats every year.
Perfect case for recussion.
Just take these points. I want to show you with an example.
If you're good, I explained an example now.
I'll explain an example now.
Same requirement I'll show you in real time how we are going to work.
This main method we can create in a new class also just for understanding purpose here only I have shown you I'm creating a new package for instance example com dot madu dot ds SA dot A4 dot insurance.
Let me create a new class called insurance.
I'm going to create one static method.
Now why I'm creating static method here?
We can call directly without using object. That is the reason I'm making it as static.
Okay. Yeah.
So static just like the previous example here for every year just instead of months uh calculate premium of in years comma double premium.
if of years and if the years is zero base case I'm writing first return premium okay this is the base case now premium is equal to premium plus 5% I told you premium into 0.05.
What does this mean?
Every year increase by 5%.
How easy is see recussion concept written function calling itself. For example, here's -1 premium.
This is the recursive call here.
Okay. Now, let me create a main method.
double result is equal to calculate premium of for example 3 years I want to calculate for 3 years and the premium is assume that I told you 5,000 right 5,000 per year so after 3 years what would be the premium system print of premium After 3 years how much resulting is wrong now that's it per year I'm calculating here 578 something 5,000 + 5% for your understanding purpose first first year itself is boring 5,000 plus 5% 5% of uh 5,000 is how much ma 250 so for understanding purpose 5,000 + 250 50 5 to 5 0. Similarly, here two again 52 5 0 + 5%.
260 number again 5250 plus 250 or 260. Why? Because E250 around 260 something you'll get and 5,00 510 something year three key 5512 or 5510 + 5% % I'm doing some calculation is around 5,700 10,000 5,000 800 for example final premium is 5,000 approximate calculation I have given here 57 exact value clear code explanation mathematical calculation I told you thing.
Mhm. 5512 for second year approximate value I have given 510 551 second year like that you can calculate. So why this is recursion here function is calling itself every year. Each year depends on the previous result stops when years is equal to zero.
Clear everybody. Now once analyze this code analyze this code and let me know if you have any questions.
Can I put this guys? Any concept clearer?
Sure.
Sure. finish tomorrow's topic if you want.
Okay. Tomorrow's topic is classes and objects about string summer like string reversing these kind of things.
Okay. Day file these things.
This is the schedule.
Today I'm discussing about this recussion fundamentals. Tomorrow classes and objects. Next inheritance in polymorphism with related to data structures. Next abstract class abstraction interfaces.
Next week we are going to discuss about uh I mean day eight collection framework list operations insert delete and traversal followed by set and map hashing fundamentals met sort quick sort and all these things day 10 memory management stack versus heap memory binary search day 12 link list reverse list to detect cycle these things.
Day 14 applied practice revision subsets applied practice backtracking all these things advanced hashing mechanisms trees keep and priority Q all maximum all the major topics I'm going to discuss as a part of data structures okay now this is about day five if you want to write it down you can write What happens if the years is negative?
Anybody?
We have not written any condition, right? It will never reach zero. So the base case is never hit. Infinite recursion program will crash. Stack overfl.
Got my point.
Sir, can you also teach taking input from the user like taking the initial premium interest rate and EMI amount from the user? Okay.
But for this you need to use scanner class. Actually if you want to take input from the user we need to use scanner class.
When I run the code, it is going to ask the value not yet done. I want to discuss one more example related to e-commerce.
You need to practice more.
So can I explain e-commerce expl e-commerce example?
Yeah, this is what the Oh no.
Hi.
So, e-commerce example.
For example, a user adds multiple products to the cart. Okay. Each product has its own price, right? We need to calculate the total cart value. Instead of using the loop, we can use recursion concept.
See here how we are going to work.
First check the requirement first.
e-commerce requirement. I'll tell you a user adds multiple products to cart. example.
Okay. Each product will have some price, right?
Each product has a price.
So, what we need to do here, we need to calculate the total C value.
Total C value and one condition here is if total is if total is greater than 5,000 apply 10% discount.
Apply 10% discount.
Okay.
So here add one product price ask recussion to add the remaining products.
Okay that is what the condition here try to understand.
Add one product price.
Ask recussion to add the remaining products.
Just check these things. I want to show you with an example.
Check this example. Uh check this points. Just I want to show you with an example how we are going to work.
I will check where you are going to get the access for all these recordings.
channel. I think in YouTube channel you might be having shall I go with an example Shall we go with an example guys?
Yes, I'll try to give this notes as well, guys. Don't worry.
Same just uh whenever you are practicing something like this, you need to write the points when you're writing some code.
Right click on src new package form. Madu dot DSA dot day four dot what is that e-commerce right click new class called e-commerce Okay, easy concept only but your thinking is more important here. Static double calculate total.
Okay. Calculate total int array of int area array of prices in n.
base case. For example, if of n =0 return zero recursive call here next is what return prices of n minus one plus calculate total of prices comma n minus one.
See here how it is going to work.
Let me create a main method. Try to understand the code.
For example, int of prices is equal to 1,000 2,00500 or example 800.
Now double double total is equal to calculate total of prices and n means prices dot length total number of elements Now what is our condition? Total is greater than 5,000 right? Apply discount logic we need to write if of total is greater than 5,000 total is equal to total minus 10% right 10% means 0 1 10.
So for the values discount applied or not here now 3,4,500 5,300 yes discount applied now system.panov of final car total we are working with Amazon right or we are working with Jeepto right internally this kind of logics will be there see recussion means it's not only fiboni series or some other things or factorial these kind of examples you need to have an idea discount spelling discount applied now 4,770.
No need of any calculations, right?
Total number of elements is how many?
Four.
Calculate total of four. Total is 5,300.
So, total is greater than 5,000. Apply 10% discount. After applying 10% discount, deduct it 4,770.
Clear?
By this, you should be very good in recussion concept.
Many were thinking that recussion concept means factorial, recussion concept is black series. Not those things. These things you need to practice.
I will be checking ma I'll be checking regarding this one.
I'll check with my team and I'll let you know.
Is it clear guys?
I hope you understood the concept. Now if you have any questions you can ask next 10 minutes normal questions not coding questions more.
Yes. Can you give some questions to practice?
How was the today's session? Ma'am, what is the feedback? Any questions? Any doubts? not able to understand. Still am I going Bless.
Previous programmer incident one. Check it.
take the assignments as of now. You can take a just a second file configurator.
read these questions and uh can you tell me whether you're able to work with these things read these questions every yes so I'll be giving questions for all the topics don't worry soon I'll be giving you uh like uh I'll be creating separate uh word document for each day and I'll be giving I'll be uploading in a driving link soon. We will be sharing the driving link to you people. Don't worry guys. I'll take care the difference between package and class. Package means collection of classes. Inside the class we are going to create variables and methods.
Yeah, I'll open e-commerce program. In the meantime, can you please take a snap for this code?
Yes. Yes. All these questions you need to solve by using recussion approach.
I will let you know by tomorrow's regarding uh recordings and materials.
I'm not that good in uh Hindi.
Only English please. I'm sorry.
Okay. Now opening the code e-commerce check it once. Poor has not taken Can we say recussion concept or the replacement of loops?
Recussion is not a replacement of loops.
Loops means repeat using for loop and while loop. Recussion means repeat by a function calling itself.
Both can solve similar problems but one is not a replacement for other.
Sure.
I'm opening the screenshot.
Can you take this questions everybody?
You can connect with me on LinkedIn.
This is my LinkedIn ID. You can connect with me on LinkedIn.
We can perform these things by using loops. But why recussion?
Anyone?
Good question. But can I don't say this answer.
Basically if you're working with loops right we might be having some complexity that is the reason that is the reason we're working with recussion and sometimes code will become cleaner and shorter because of these reasons we are using recussion concept yes convenient way better way correct to Reduce code size is correct. See a lot of answers we are getting.
Time complexity is more in loops. Agree?
You need to practice more. Not only this but once you practice this kind of things right? Anything you can practice.
Whatever the question I ask now you can try right.
simplifies the logic.
Yeah. In the meantime, yes, see I I have given the screen. This is my LinkedIn ID. In the meantime, others can connect with me on LinkedIn.
Sir can you suggest some websites for learning Java details since I'm new to Java though I'm able to understand things I want to learn more can you give me some suggestions Java point is one of the good website ma just go through it and from my end also if you need any documents definitely I'll be providing you I have a number of documents related to Java even I'll be sharing with you people soon at least for now complete these things practice DSA We will discuss more on the upcoming session.
Fine, I'm done from my end for today.
Let me share the link.
So I hope you are good with the concept right as of now if people can upload in the drive we'll let you know soon we have more posts like this for learning we will let you let's complete this feedback link I'm going to share give me a second so that feedback link will be the attendance this.
I think you need to edit and uh fill the font.
Check the link guys. I have given the link.
I hope you are good with the today's session right everybody.
I will let you know by tomorrow related to quiz and all those things.
We will discuss more on it tomorrow where she needs Yeah, if you have taken the link right, I'll close for today.
You can give any college name for guys. I'm closing for now. Let's connect tomorrow. Thank you all. Have a great day.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











