Generate Parentheses | 2 Approaches | Magic Of Recursion | Recursion Concepts And Questions

preview_player
Показать описание
This is the 14th video of our playlist "Recursion Concepts And Questions". Find the Details below :

Video Name : Generate Parentheses | 2 Approaches | Magic Of Recursion | Recursion Concepts And Questions
Video # : 14

🔍 Unraveling Recursion: A Journey into the Depths of Code

🎥 Welcome to the 14th Video of my Recursion Playlist! 🚀 In this enlightening video, we will solve another very famous recursion/backtracking problem "Generate Parentheses". We will start with a Simple story as well as Tree Diagram for understanding the problem and then we will be Converting Story to code and writing the recursive code for the problem and also I will also be explaining the Time and Space Complexity of the code 🌐. We will be solving it using 2 Approaches.

🔍 What's Inside?

🔗 Simple story understanding with 2 Approaches along with Tree Diagram

🔗 Converting Story to code and writing the recursive code for Generate Parentheses problem

🔗 Explanation of Time and Space Complexity of the code

👩‍💻 Who Should Watch?

This playlist is for everyone but best suited for Freshers who are new to Recursion.

🚀 Embark on the Recursive Adventure Now!

Approach Summary :
Approach-1 (Simple Recursion):

This approach uses a recursive function to generate all possible combinations of parentheses.
The isValid function checks whether a given combination is valid or not by maintaining a balance of open and close parentheses.
The main recursive function (generate) explores all possibilities by adding an open parenthesis and a close parenthesis in each recursive call.
T.C : O(2n* (2^(2n)) - Removing constant - O(n * (2^n))
S.C : O(2*n) - Removing constant - O(n * (2^n)) - recursion stack space - Max depth of recusion tree
Approach-2 (Smart Recursion):

This approach also uses a recursive function, but it is optimized to generate only valid combinations.
The generateAll function explores possibilities by only adding an open parenthesis when the count of open parentheses is less than n and adding a close parenthesis when the count of close parentheses is less than the count of open parentheses.
This approach avoids generating invalid combinations, reducing the overall time complexity.
T.C : O(2^n)
S.C : O(2*n) - Removing constant - O(n * (2^n)) - recursion stack space - Max depth of recusion tree

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction
00:10 - Motivation
01:04 - Problem Explanation
04:26 - Approach-1 Thought Process + Tree Diagram
10:50 - Story to Code + Trust in Recursion
18:59 - Approach-1 Time & Space Complexity
22:34 - Coding Approach-1
26:46 - Approach-2 Thought Process
36:02 - Approach-2 Time & Space Complexity
37:38 - Coding Approach-2

#codestorywithMIK
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear #RecursionExplained #CodingJourney #Programming101 #TechTalks #AlgorithmMastery #Recursion #Programming #Algorithm #Code #ComputerScience #SoftwareDevelopment #CodingTips #RecursiveFunctions #TechExplained #ProgrammingConcepts #CodeTutorial #LearnToCode #TechEducation #DeveloperCommunity #RecursiveThinking #ProgrammingLogic #ProblemSolving #AlgorithmDesign #CSEducation
Рекомендации по теме
Комментарии
Автор

MIK Bhai 18:18 agar counter use karenge to "( ) ) (" me true dikhana chahiye jab ki woh false hai. in this case ham condition rkh sakte ki kisi bhi point p sum -ve nahi hona chahiye

shantanughosh
Автор

subeh subeh ek भाषण miljata hai to maja aajata hai bhaiya 💞💞

lofireverbz-wygo
Автор

As always you made the concept very clear and easy... Thanku Bhaiya for providing such a wonderful explanation

AnjuGupta-szuk
Автор

hard one becomes easy :) when it's @CodestorywithMIK!!! definitely one day you will be the king in DSA world.

SanjeevKumar-xvlw
Автор

Please also resume your HLD playlist as well, those were really helpful

ayushgoel
Автор

Hey mik can you make a video of today's leetcode contest 3 and 4 th question. Thanks in advance.

anuppatankar
Автор

Woow, such a good explanation.Keep up the great work . Your videos are so helpful.

vaidehidarji
Автор

Amazing, how many videos remaining in recursion? Please completeee

hiteshjain
Автор

Wow you have explained in very easy way♥️

AWRaza-bmrz
Автор

The nth Catalan number is a sequence of natural numbers that have many applications in combinatorial mathematics. Catalan numbers count the number of distinct ways[different or separate ways] to correctly arrange n pairs of parentheses, among other combinatorial structures.
Binomial Coefficient Formula: C(n)=[1/(n+1)]*[2n/n]
for example if Catalan no is 3 then asper above formula answer will be 5 which means there are 5 valid ways to arrange 3 pairs of parentheses
below output
((()))
(()())
(())()
()(())
()()()

omkarsawant
Автор

more easy code
res = []
def bt(op, close, cur) :
if len(cur) == 2 * n :
res.append(cur)

if op < n :
bt(op + 1, close, cur + '(')

if close < op :
bt(op, close + 1, cur + ')')



bt(1, 0, '(')
return res

ArjunSaxena-wlqs
Автор

*but count wale approach me toh ))(( ye bhi valid ho jayega na -1-1+1+1 = 0*

onceajeeaspirant
Автор

Hi Mazhar I really liked your channel but I want to tell you many times when I see a new question I dont know what to start seeing your video give confidence but what I am doing wrong or should do better ?

rasish
Автор

bro ek doubt hai jaise aapne bola ki jab bhi options and chocies dikhe question mein toh recursion socho but maine ek chiz notice kari ki is question mein hum 2 options try kar rahe hai open bracket ya close bracket but subst vale question hum try kar rahe hai ki ya to nums[i] ko include karenge in subs ya exclude toh ye chiz question pe depend karegi ki options kya and hume konsa approach lagana hai ? please eaboarte on it bro ye backtracking bohot tough lag raha hai khud se nahi such pata hun

nish
Автор

Please sir make video for question : leetcode 959. Regions Cut By Slashes, it is really confusing

Gaurav-vlym
Автор

Bhai concept ki videos kab upload kroghe

harshlakra
Автор

Today leetcode contest questions explain

vaibhavbhatt
Автор

Why we are calling recursion for n length again it should be for n-1 length.

muskanyadav
Автор

bhaiya time complexity smj nahi aai 1st ki

gryffindor
Автор

Bhai concept ki videos kab upload kroghe

harshlakra