L1. Implement TRIE | INSERT | SEARCH | STARTSWITH

Поділитися
Вставка
  • Опубліковано 10 лис 2021
  • Check our Website:
    In case you are thinking to buy courses, please check below:
    Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
    Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
    Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
    Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
    Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
    Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
    Linkedin/Instagram/Telegram: linktr.ee/takeUforward
    ---------------------------------------------------------------------------------------------------------------------------------------------------- C++/Java Codes - takeuforward.org/data-structu...
    Pre-requisite: Should know the concept of pointers, struct in CPP, classes in java, basic programming
    In this video, we discuss the Insert, search and start with the functionality of TRIE Data Structure and its usage!
    Please share this channel as much as you can. Also, it's an earnest request to drop a comment "understood" if you are watching this video, so that I get to know you understood from this video.
    SDE-Sheet/Linkedin/Telegram/Instagram: linktr.ee/takeUforward
    -------------------------------------------------------------------------------------------------------------
    Problem Link: bit.ly/3n4m3Hu

КОМЕНТАРІ • 385

  • @takeUforward
    @takeUforward  2 роки тому +195

    Just a small request, please do comment “understood” if you understand by watching this video. Helps me a lot mentally. Hardly will take 2 seconds!!
    Lets start this trend on TUF for every video you watch ☺️

    • @agrawalhimanshu
      @agrawalhimanshu 2 роки тому +2

      IN thumbnail it should be implement TRIE instead of implement TREE

    • @hareeshr3979
      @hareeshr3979 2 роки тому +2

      I completed the SDE sheet still imposter syndrome is killing me 😢, I'm at my 5th semester

    • @noobprogrammer3040
      @noobprogrammer3040 2 роки тому

      bhaiya your explanation is the best.

    • @swapnilsingh710
      @swapnilsingh710 2 роки тому

      understood

    • @aeroabrar_31
      @aeroabrar_31 Рік тому +3

      Thanks s'TRIE'ver for this amazing 'TRIE' playlist.. 😅😁📌

  • @vikrambabariya5166
    @vikrambabariya5166 Рік тому +34

    Completed Trie Series, I can definitely say your way of teaching is best in the teaching field. Thanks for providing this type of highly rated content free of cost. 🙏

  • @shree_divyansh
    @shree_divyansh 2 роки тому +59

    Understood!!! You explained so good that after watching the insert explaination of trie (till 13:23), I paused the video and coded insert, search and startsWith. After that I resumed video to match the code.

  • @Ishan301
    @Ishan301 2 роки тому +137

    Small Correction at 24:57 in C++ code line 42, when we will move to the reference trie it should be node=node->get(word[i]); instead of just node->get(word[i]); By the way great content and really nice explanation :)

    • @sukritiguin5637
      @sukritiguin5637 2 роки тому +7

      Yes.. current node is updating every times

    • @ashutoshpatel5030
      @ashutoshpatel5030 11 місяців тому

      Yes Exactly I was also wondering the same.

    • @rohitk472
      @rohitk472 11 місяців тому +1

      same I was thinking.

    • @K.AnshulReddy
      @K.AnshulReddy Місяць тому +1

      bro u have literally saved my day ,i was really confused how this was working

  • @lakshyaKumar12
    @lakshyaKumar12 Рік тому +6

    Completed Trie Series, I can definitely say your way of teaching is best in the teaching field. Thanks for providing this type of highly rated content free of cost

  • @tanujajoshi5253
    @tanujajoshi5253 2 роки тому +7

    This video is really good. I was actually looking for a Trie playlist. I started trie a week back from gfg but couldn't understand. Now I'm starting again from your playlist. Please continue making videos for this playlist so that I can complete this concept timely. Thank you. Lots of support. And yeah, "understood".

  • @likhithl7928
    @likhithl7928 Рік тому +4

    I was always demotivated by the complexity in Tries.. For the very first time i understood everything.. I felt very high after being able to code it in python myself.... Thanks man ❤

  • @dharani8871
    @dharani8871 Рік тому +5

    Understood. No one can do a dry run like you do. You are perfect.

  • @prateekgaur2709
    @prateekgaur2709 2 роки тому +4

    At 29:30 ,in startsWith func(),for loop should be from i=0 to i

  • @bharathjanakiraman7232
    @bharathjanakiraman7232 2 роки тому +3

    Understood. Also, I was able to solve the shortest unique prefix problem by only watching this video. Great explanation!!. Thanks a lot for this!

  • @AB-tp9eg
    @AB-tp9eg 2 роки тому +38

    Understood, bhaiya one thing that I want to request that please keep your face in every video while teaching. It would be great 🙂

  • @evergreen7781
    @evergreen7781 2 роки тому +4

    Not only did I understand, but also revised & learned best practices using OOPs.

  • @abhimanyubahree1455
    @abhimanyubahree1455 7 місяців тому

    Thank you so much. I finally learnt Trie. After your explaination and seeing the struct Node. I decided to give it a try and code on my own. In

  • @utkarshmishra6667
    @utkarshmishra6667 2 роки тому +2

    Understood...btw striver you have a great teaching proficiency my friend...as amazing as it can be...🔥🔥✌

  • @mohaimenchowdhury
    @mohaimenchowdhury Рік тому +1

    Long lasting trie-phobia has been recovered. Thanks for the content.

  • @mohaktrivedi9591
    @mohaktrivedi9591 2 роки тому

    Understood in one go! Thanks for the concise explanation!

  • @accessdeniedk6240
    @accessdeniedk6240 2 роки тому

    Such a great video! Easily understood and thanks for providing us with such contents.

  • @AliAkbarFaiz
    @AliAkbarFaiz 2 роки тому

    Understood? Was able to code in a single attempt without looking anywhere else. That's how simple u made it 👍❤️

  • @TheElevatedGuy
    @TheElevatedGuy 2 роки тому

    Understood! Really Appreciate it!
    thanks a lot!
    Keep making these type of content for us!
    Thank you very much it is very much helpful.

  • @AbhishekSingh-oz5ei
    @AbhishekSingh-oz5ei 10 місяців тому +3

    Just a small correction in C++ code line 42, when we will move to the reference trie it should be node=node->get(word[i]); instead of just node->get(word[i]); And 2nd one is line 13, return type is void instead of bool. Btw amazing video to understand trie in better way.

    • @ankit462
      @ankit462 10 місяців тому

      i was also thinking the same

    • @hardikkumarsingh
      @hardikkumarsingh 7 місяців тому +1

      There is no error in line 13 , I mean return type would be bool only not void. I guess you meant in line 23, it should be void

  • @akshatsahu8021
    @akshatsahu8021 2 роки тому

    That was cool... got the concept and implementation pretty clearly.. All thanks to you bro.

  • @lakshaysharma6550
    @lakshaysharma6550 2 роки тому +17

    Here is the python code for my fellow pythonistas:-
    class Node():
    def __init__(self) -> None:
    self.links=[None for _ in range(26)]
    self.flag=False
    def containsKey(self,ch):
    return self.links[ord(ch)-ord('a')]!=None

    def get(self,ch):
    return self.links[ord(ch)-ord('a')]
    def put(self,ch,node):
    self.links[ord(ch)-ord('a')]=node

    def setEnd(self):
    self.flag=True

    def isEnd(self):
    return self.flag

    class Trie():
    def __init__(self):
    self.root=Node()

    def insert(self,word):
    node=self.root
    for i in word:
    if(not node.containsKey(i)):
    node.put(i,Node())
    node=node.get(i)
    node.setEnd()
    def search(self,word):
    node=self.root
    for i in word:
    if(not node.containsKey(i)):
    return False
    node=node.get(i)

    return node.isEnd()

    def startsWith(self,prefix):
    node=self.root
    for i in prefix:
    if(not node.containsKey(i)):
    return False
    node=node.get(i)
    return True
    if __name__=='__main__':
    type=[1,1,2,3,2]
    value=['hello','help','help','hel','hel']
    trie=Trie()
    for i in range(len(type)):
    if(type[i]==1):
    trie.insert(value[i])
    elif(type[i]==2):
    print(trie.search(value[i]))
    else:
    print(trie.startsWith(value[i]))

  • @_SOHAMSAMANTA
    @_SOHAMSAMANTA 2 роки тому

    Awesome Explanation !!! And thanks for explaining the production level code .

  • @arnabmondal81
    @arnabmondal81 10 місяців тому +2

    love you dada from Howrah, West Bengal. You are my inspiration.... :)

  • @Dontpushyour_luck
    @Dontpushyour_luck 9 місяців тому

    Starting this trie series. Always wanted to study about tries because I am unable to solve hard questions requiring it's concepts. Hopefully I get clarity with this series. Completed tree series first before starting this!

  • @mohammedanasdanish7509
    @mohammedanasdanish7509 Рік тому

    Understood! Thanks a lot for such a detailed and understandable tutorial!

  • @AhmadSayeed-plus
    @AhmadSayeed-plus 8 місяців тому

    Understood bro. first video in life to understand trie and learned it in first video. What a luck for me

  • @s.g.prajapati3597
    @s.g.prajapati3597 2 роки тому +1

    Awesome Explanation!
    UNDERSTOOD TO THE FULLEST!

  • @yashsinha4712
    @yashsinha4712 2 роки тому +1

    Understood !!!!!
    Amazing explanation ,it was so easy

  • @NinaadMallapur
    @NinaadMallapur Рік тому

    So far the best Trie Data Structure video on youtube

  • @krishnamsinha8320
    @krishnamsinha8320 Місяць тому

    He was right when he said He'll not be running the code as he might have done some syntax errors, and he really has, at 24:57 in C++ code line 42, it will be node=node->get(word[i]); instead of just node->get(word[i]). Man is even ahead of himself.

  • @aryanmaniyar7301
    @aryanmaniyar7301 8 місяців тому

    UNDERSTOOD Striver :) Thank you so much for all your efforts! Truly appreciable!

  • @bhushankorg5606
    @bhushankorg5606 Рік тому

    Understood! reallly a great explaination able to understand in one shot!

  • @sommayghosh4617
    @sommayghosh4617 2 роки тому

    Striver hai toh Trie ko try krskte hai, only DS skipped will try to do now!, Great and lucid explanation ,cheers 🍻🍻

  • @itsyadavraj
    @itsyadavraj 2 роки тому +2

    amazing lecture sir😍
    thank you so much 🙏🙏

  • @mallikdasari
    @mallikdasari 2 роки тому

    Great explanation and coding with industry standards. This will help not only in the interview but also in the daily work.

  • @masterroyjones4228
    @masterroyjones4228 2 роки тому

    Explaining complicated ds like a pro is jst a striver bhaiyya thing nobody else can do that💯

  • @yuvi3398
    @yuvi3398 2 роки тому +4

    Hey striver I am able to understand trie concepts taught by you but I am having difficulty in understanding Object oriented stuff in C++ that you are telling in the video. Could you please recommend some resource from where we can learn this OOPS stuff conceptually or the resource from you learned and mastered it.

  • @juliechoudhary9582
    @juliechoudhary9582 Рік тому

    Its really so nice..Understood each and everything..

  • @sks7856
    @sks7856 2 роки тому +1

    bro, you are doing great work, learnt a lot from your videos....thanks for providing such a quality content.

  • @Manojkumar-rq8hf
    @Manojkumar-rq8hf 2 роки тому

    Great Explanation! Understood very well.

  • @aditidey9366
    @aditidey9366 2 роки тому +1

    understood! quick question though, can't we use a char to int map instead of the array?

  • @stith_pragya
    @stith_pragya 6 місяців тому +1

    UNDERSTOOD........Thank You So Much for this wonderful video.............👍👍🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @SriHarshaChilakapati
    @SriHarshaChilakapati 2 роки тому

    Fantastic explanation! Just two suggestions:
    1. For Striver: Small letters t and f are looking identical in your writing, so consider writing T or F in capitals for added clarity.
    2. For Viewers: This is a good way when you are guaranteed that the strings given are between a to z and in small case. If you have to generify it for all characters, how would you change it? Think about this question a little.
    :)

    • @takeUforward
      @takeUforward  2 роки тому +2

      Sure Harsha, my handwriting is super bad 🤪

    • @SriHarshaChilakapati
      @SriHarshaChilakapati 2 роки тому +1

      @@takeUforward Hey, no. Don't take it in a negative sense. Except for that one instance, your handwriting is pretty much fine.

    • @SriHarshaChilakapati
      @SriHarshaChilakapati 2 роки тому +1

      @@takeUforward Btw, which Whiteboarding tool are you using?

  • @vibhaalur4078
    @vibhaalur4078 2 роки тому

    Understood ! Very well explained !!

  • @ddwatcher
    @ddwatcher Рік тому

    Nice and clear explanation! Just one question. Is there any specific reason for using a struct for Node instead of using a class like the way it has used in the Java code?

  • @sunnykumarsingh7039
    @sunnykumarsingh7039 2 роки тому +1

    Just woke up.
    This video is go-with-my-breakfast video❤️

  • @keshav2113
    @keshav2113 2 роки тому +10

    Wall paper pe correct kar lo bhaiya Implement tree dikha raha hai !!

  • @nbavideos4487
    @nbavideos4487 2 роки тому

    Understood !!! sure man thank you so much for sharing keep pushing that content

  • @atharvakulkarni2024
    @atharvakulkarni2024 2 роки тому +7

    A FEEDBACK CODING LIVE IS MUCH MUCH BETTER THAN EXPLAINING THE WRITTEN SOLUTION..PLEASE FOLLOW THE SAME METHOD FOR FURTHER SERIES!!!1THANKS :)

  • @akshaywairagade5478
    @akshaywairagade5478 2 роки тому +5

    I have a doubt in insertion part consider a word "app" if we first insert it then p will point to null and later if we insert "apple" now p is pointing towards 'l' so here we have lost the fact that "app" word also exists as by our word we should get a null node. So how to deal with this problem @take U forward @Striver

    • @utkarshsharma1185
      @utkarshsharma1185 Рік тому +2

      when we done traversing the word "app" we will check for the flag == true if yes then word exist otherwise not.

    • @adarshgupta2605
      @adarshgupta2605 Рік тому +2

      @akshay
      Actually, I was also thinking about the same problem
      The first time when "app" will be inserted, the second p will point to a null trie and that flag will be marked as true
      Later when "apple" is inserted then it would look like this
      ('a', false)->('p', false)->('p', false)->('l'-> *true*)->('e'->false)->(NULL->true)
      So after you search for "app", it will still return true

  • @TechieDishant
    @TechieDishant 2 роки тому

    Awesome Explanation! 🔥
    UNDERSTOOD

  • @Niranjan-dt2mc
    @Niranjan-dt2mc 2 роки тому +2

    I can not do anything for you but....Just thank you so much Bhaiya ❤️... Learnt a lot form you.... Inspiration to work hard 🙏

  • @rujwideshmukh5382
    @rujwideshmukh5382 2 роки тому +1

    Amazing explanation!!!!

  • @madhavaprashath1453
    @madhavaprashath1453 2 роки тому +3

    What happens when we try to insert a string that is a prefix of previously inserted string???

  • @bhaveshkumar6842
    @bhaveshkumar6842 2 роки тому +2

    Google is lucky to have you 😎😎😎

  • @rohitantil9534
    @rohitantil9534 2 роки тому

    Bhai kmal he krdea hitna difficult lgta tha ye topic Lekin abb bhot easy❤️

  • @therealsumitshah
    @therealsumitshah 2 роки тому

    understood striver...you are a gem.

  • @areebahmadsiddiqui2648
    @areebahmadsiddiqui2648 2 роки тому +2

    Understood excited for the upcoming videos thanq Striver🤩🤩

  • @cenacr007
    @cenacr007 Рік тому +2

    why the return type of setEnd() is bool, shouldn't it be void if it isn't returning anything

  • @akhilkishore7361
    @akhilkishore7361 2 роки тому

    understood , you are doing great job buddy

  • @atulk9122
    @atulk9122 2 роки тому

    U r man of words respect 💯

  • @BEEMohdArbazAli
    @BEEMohdArbazAli 2 роки тому

    Very Well understood. Thanks bhayya

  • @parambharti7095
    @parambharti7095 Рік тому +1

    Just Awesome. Thanks a lot Striver.

  • @rahulpothula1902
    @rahulpothula1902 2 роки тому

    Perfectly understood!!

  • @gandhijainamgunvantkumar6783
    @gandhijainamgunvantkumar6783 2 роки тому

    Understood bhaiya. Keep making this type of amzing content :)

  • @priyankakothari3544
    @priyankakothari3544 2 роки тому

    Understood Completely!!!👍

  • @champion5946
    @champion5946 2 роки тому

    UnderStood
    You said production level code , So
    Can we use range based for loops whenever index is not required ?

  • @abhishekgupta9705
    @abhishekgupta9705 2 роки тому

    Understood. Hats Of!!!!!!!!!!!!!!1

  • @AliAkbarFaiz
    @AliAkbarFaiz 2 роки тому

    understood :))) ! amazing work

  • @eshandhok2591
    @eshandhok2591 2 роки тому +1

    What is the prerequisite for Trie? also, before or after DP? @anyone and @everyone

  • @aarushirai6374
    @aarushirai6374 2 роки тому

    Understood. Really helpful.

  • @rishabhkumar8115
    @rishabhkumar8115 2 роки тому

    Thanks a lot for this valuable things a for free.

  • @chiraggoel4131
    @chiraggoel4131 2 роки тому

    Understood😎👍
    Thanks a alot broo

  • @nishant3904
    @nishant3904 2 роки тому

    UNDERSTOOD very well !

  • @user-bw7gb1yr1p
    @user-bw7gb1yr1p 10 місяців тому

    Understood... super explanation...

  • @santanudutta7097
    @santanudutta7097 2 роки тому

    FULLY UNDERSTOOD 🏵🏵

  • @user-sl3vy8rm2r
    @user-sl3vy8rm2r Рік тому

    people would say that trie is a hard topic, but with you, it does not seem so

  • @sachinaspiran
    @sachinaspiran Рік тому

    compleately understood sir you are amazing

  • @abhishekraj8845
    @abhishekraj8845 Рік тому +1

    teaches well understood well😊

  • @jaykumargupta7307
    @jaykumargupta7307 2 роки тому

    Leetcode daily challenge forced me to come here.. Happy I did!!!

  • @ManishKumar-qs8xh
    @ManishKumar-qs8xh Місяць тому

    You are the best, man!

  • @siddharthsaxena6495
    @siddharthsaxena6495 2 роки тому

    Can u tell the space complexity of trie , because we are taking the links array again and again for reference trie??

  • @mohdaman7228
    @mohdaman7228 Рік тому

    links could be taken as a map , It would reduce the complexity of containsKey class function a little bit.

  • @laraibanwar1618
    @laraibanwar1618 2 роки тому

    Brilliant
    Please make a video of suffix array which jnvloves nlogn solution
    Thnks

  • @harshverma1221
    @harshverma1221 2 роки тому +1

    For all those complaining for the background
    Striver also noticed that hence placed his photo just over that e

  • @aimenmoten2240
    @aimenmoten2240 Рік тому

    Understood!!! Too good

  • @AmritangshuGhosh
    @AmritangshuGhosh 2 роки тому

    Understood. Great Content.

  • @MayurNagrale-py7lu
    @MayurNagrale-py7lu Рік тому

    node = node->get(word[i]) in insert method

  • @harshverma1221
    @harshverma1221 2 роки тому +5

    Understood, very nice lecture 😉

  • @sanbidrc
    @sanbidrc 2 роки тому +1

    Great content as always. Btw How to insert "apples" AFTER inserting "apple". Wouldn't "apple" be lost?

    • @takeUforward
      @takeUforward  2 роки тому +9

      No e’s reference trie has true marked, so u add a new trie for s to e’s reference trie and for s’s reference trie mark it as true

  • @samyakjain7422
    @samyakjain7422 2 роки тому

    Main tera haaye re jabra
    Hoye re jabra fan ho gaya!

  • @zahidgul6337
    @zahidgul6337 5 місяців тому

    in search function, it should be prefix.length instead of word

  • @muskankalra2516
    @muskankalra2516 2 роки тому

    UNDERSTOOOOOOOOOOOOOOOD !!!

  • @jolly_dollyyy
    @jolly_dollyyy 2 роки тому

    Explanation OP !!!

  • @uchihaPrincessSakura
    @uchihaPrincessSakura 2 роки тому +1

    Watched it completly Raj Sir

  • @bhaveshkumar6842
    @bhaveshkumar6842 2 роки тому +1

    Striver bhai, you're the best!

  • @sameerpurwar4836
    @sameerpurwar4836 2 роки тому

    Understood , awesome.

  • @subhroacharjee1562
    @subhroacharjee1562 Рік тому

    best teacher ever

  • @juniorboy1903
    @juniorboy1903 2 роки тому

    Helpful video 😃