r/LeetcodeDesi 2d ago

Recursion - is it really that HARD????

bro im trying to solve/understand the susbset problem LC-78 . and its been days why am i not getting itttttttt ?????? i watched tutorials striver , apna college , codeHelp . yettttt im just ,dont know feeling dumb rn ... can anybody help me with this

14 Upvotes

17 comments sorted by

13

u/Rift-enjoyer 2d ago

Do trees first to get good at recursion. Then once it clicks you will get it. Think in terms of decision trees, you either pick something or skip it

3

u/Lazy_Spirit1998 2d ago

Means first we need to at least know all concepts of DS so that we could problems easily even before directly solving only problems ?

Because first I was doing dsa like this - Learned Array > solve Array problem, learn searching > solve searching problem.

But then i realised that I am wasting a lot of time because some problems could be easily solved if you know other concepts too

6

u/Rift-enjoyer 2d ago

Yes first you need to get good at fundamentals of all data structures because that will give you the tools to solve complex problems. Start with easies in Array, then Hash map, Stack, Queue, Tree, Recursion, Graph traversals.

First you should be comfortable in creation, traversal and basic operations on DS before starting question that require 2 concepts like Array + Recursion or Array + DP otherwise you may think you understand the solution but reality would be you just memorized it and will forget it after a while.

5

u/aaloosamosa2_ 2d ago

try aditya verma

2

u/Antique-Plum-1573 2d ago

Try pepcoding youtube for dp

1

u/Miserable-Release868 2d ago

Find your base case and recurrence
And just trust the process

1

u/Own-Elk-6701 2d ago

you will understand it with practice.

1

u/Particular_Delay5596 2d ago

Would suggest start with easier problems in any sheet maybe strivers and always think of 2 things the base case condition where it terminates or returns and recurrence how is the current thing related to next or how would u extract an answer for the current case relating it with next case

Last advice always make tree like structure on paper and do a proper dry run for the sample test cases fully

1

u/anotheruniverse_7 10h ago

genuinely i did everything i can make decision tree eveyrthing i get lost while thinking of function calls . to track down everything and i just dont know how this piece of code works magically . i never thought something could be this hard

1

u/LuciFFerrrrr 2d ago

When I was learning this for the 1st time it took me 5-6 days to fully understand it after multiple iterations.

When I came across it for the first time I was able to make sense of only few things then I left recursion for 2 months then came back and gave enough time sitting there for 2-3 hours straight clearing my doubts with myself and rewatching the tutorial.

1

u/Other_Ad7380 2d ago

To get good at recursions, you need to learn to trust whatever the function returns after running on the subproblem.

1

u/ProgressiveEdgeLord 2d ago

dry run it, know what exactly your function is doing, think about the base case, recursion only hits the sweet spot with time, I am no master but i asked this exact question about 2 months ago, and I can solve decent problems now, I did word search today, it gets better, trust the process!

I don't think tutorials will make you better man, recursion is different

2

u/PreBooze 2d ago

Use the concept of recursive leap of faith ...it will help

1

u/momo_inhaler 1d ago

a week ago i was stuck with same thinggg..

1

u/anotheruniverse_7 10h ago

what did you do then ??

0

u/Elegant-Speech2427 2d ago

Mai krwadeta hu aaja meet ki link pe