Tree (General Tree) - Data Structures & Algorithms Tutorials In Python #9

Поділитися
Вставка
  • Опубліковано 7 лип 2024
  • Tree data structure is used to represent hierarchical data such as organization hierachy, product categories, geographic locations etc. In this video, we will go over general tree data structure. We will cover binary trees in another tutorial. We will implement tree in python and build a tree of electronic item categories.
    Code: github.com/codebasics/data-st...
    Exercise: github.com/codebasics/data-st...
    Topics
    00:00 introduction
    00:26 What is tree data structure
    03:47 Tree implementation in python
    21:54 Exercise
    #tree #pythontree #treedatastructure #datastructures #algorithms #python
    Do you want to learn technology from me? Check codebasics.io/?... for my affordable video courses.
    Next Video: • Binary Tree Part 1 | B...
    Previous video: • Queue - Data Structure...
    Complete playlist: • Data Structures And Al...
    🌎 My Website For Video Courses: codebasics.io/?...
    Need help building software or data analytics and AI solutions? My company www.atliq.com/ can help. Click on the Contact button on that website.
    #️⃣ Social Media #️⃣
    🔗 Discord: / discord
    📸 Dhaval's Personal Instagram: / dhavalsays
    📸 Instagram: / codebasicshub
    🔊 Facebook: / codebasicshub
    📝 Linkedin (Personal): / dhavalsays
    📝 Linkedin (Codebasics): / codebasics
    📱 Twitter: / codebasicshub
    🔗 Patreon: www.patreon.com/codebasics?fa...

КОМЕНТАРІ • 216

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

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

    • @smaransure2234
      @smaransure2234 24 дні тому

      Please sir don't inject coronavirus into my computer
      I haven't looked at solutions yet but please don't inject coronavirus into it I beg you

  • @malikrumi1206
    @malikrumi1206 2 роки тому +66

    Ok, this video is two years old, and you've moved on to a lot of other things. But I just want to point out - because I've searched - while there are plenty of so-called tutorials about binary trees, there is almost nothing about general trees. I get it, people always want to take the easiest option, even if that doesn't really help their followers in the long run - or the short run, for that matter, because they quickly find out that too simplistic tutorials don't get you very far in the real world. So this is an appreciation, and a thank you, for the thoroughness and completeness of your work, and your interest in actually helping people learn what they need to know.

  • @sukurcf
    @sukurcf 3 роки тому +54

    The best thing about your videos is that you provide a real world example for every data structure that we are going to discuss.

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

      i know Im asking randomly but does anyone know a tool to get back into an Instagram account??
      I was dumb lost my account password. I would love any tips you can give me.

  • @souvikmitra2652
    @souvikmitra2652 3 роки тому +20

    sir , I had my computer teachers in my college . But you are the one who actually taught me the Data Structure concepts and made me think why they were important and why we need to do know it . Some teachers sometimes dont know , how critical their roles are in some one life . Happy Teachers day to you even though today is not the teacher's day

  • @narinpratap8790
    @narinpratap8790 3 роки тому +10

    Bro this is awesome! Your DS & Algo tutorials are so easy to understand and they also cover the fundamentals very well. Thanks so much for doing this :D

  • @d25102
    @d25102 9 місяців тому +2

    genuinely one of the most helpful tutorial series on this website! thank you!

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

    Watching this is 2021 for my Software Engineering's degree and man you are awesome ! Thank you for this awesome video !

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

    Thank you so much for the tutorial! I'm new to data structure and all your explanations help a lot! Hopefully it will help me land a job one day. :)

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

    Really very happy about finding such an obvious and understood funny video series about data structures and algorithms. Everything is 100% clear with deeply explained theories and well-understood practicals. Also, the exercise series with the videos are highly appreciated. Dear sir thank you so much for the fantastic video series. ❤💖

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

    Thank you
    #codebasics, I wasn't understanding Tree implementation in python until I got this tutorial. Thank you

  • @Mohamed-hm7jo
    @Mohamed-hm7jo 4 роки тому +13

    We are waiting for your data structure continuation series...please post asap so we make use of this quarantine time.Also request a solved example per ds model.
    Thanks

  • @Vinicius-nd8nz
    @Vinicius-nd8nz 4 роки тому

    Thank you for the video!!! Wonderful explanations!

  • @tionut4228
    @tionut4228 3 роки тому +3

    Love your data structures and alogrithms series!

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

    Absolutely brilliant and enjoyable to watch, thank you!

  • @alooooshm
    @alooooshm 4 роки тому +1

    Thanks a lot! We are waiting for your data structure continuation series...

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

    Yet another excellent lesson. Thanks again.

  • @muhammedrajab2301
    @muhammedrajab2301 3 роки тому

    This tutorial was a bit tricky but I managed to learn this and I did the exercises correctly without looking the solution. Thanks a lot Sir!!!!!!

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

    This video is amazing ! Looking forward to upcoming videos .I am a beginner and this data structure series helps me a lot!!

    • @codebasics
      @codebasics  4 роки тому +1

      Glad you liked it karthi

  • @platnnum1129
    @platnnum1129 3 роки тому

    Your videos saved my this semester thank you so much

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

    Awesome Video! You made a clear explaination of everything!

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

    Very informative video sir, thanks for sharing....request to upload next one soon :)

  • @CommonNoun9
    @CommonNoun9 3 роки тому +1

    Really like your videos man, keep 'em coming

  • @jorgegonzaloalfaro5378
    @jorgegonzaloalfaro5378 3 роки тому +1

    Thanks so much for this!!!

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

    I recently completed my MS in engineering in US. Have been learning python specifically to enhance my ML skills. Your videos have been really helpful. Appreciate your efforts.

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

      Hey man I needed some help , if you don't mind.

  • @annlaosun6260
    @annlaosun6260 2 місяці тому

    Thank you so much. This tutorial and excerise is the most helpful one for me to understand python class.

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

    Nice representation, thank you.

  • @sanjeevKumar-eg6hp
    @sanjeevKumar-eg6hp Рік тому

    Thanks for a such simple and short explanation all information was to the point.

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

    Thanks for the video, I've had a harder time finding n-ary tree information, so much is about binary trees

  • @ece-b-087-thamaraiselvansp5
    @ece-b-087-thamaraiselvansp5 3 роки тому +1

    Really helpful for for every person because I college level every teacher they teach only the theory concept but you can clear the concept real life examples In Linux file system is like this model.before seen this video I am not understanding where we can use the tree concept in real life.but know I am understanding very clearly.please upload these kind of real life data structure concept.❣️

  • @celestinejoy9519
    @celestinejoy9519 3 роки тому

    Wow so nice .Your dsa playlist is so good and u explained it very well . It was really helpful. Also the exercises were interesting.

  • @lucas86999
    @lucas86999 4 роки тому

    Thank you Dhaval for this, this is what I was looking for. Great jog!!!!!!!!!

  • @a.human.
    @a.human. 2 роки тому

    No lie, this was one of the best tree tutorials ever! definitely recommending to each of my friends :)

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

    I compiled the code without maintaining parent link it worked fine for traversing from root to leaf node

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

    Fantastic! Thanks 👍

  • @deepam.g4558
    @deepam.g4558 3 роки тому

    Very useful. Thank you

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

    Thank you so much, very useful 🙌🙌

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

    Thank you! This was really usefull.

  • @thecamelbackfiles3685
    @thecamelbackfiles3685 3 роки тому

    Wow. So clear!

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

    ThankYou very Much sir

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

    Thank you sir these videos are helping a lot

  • @ludviklamb
    @ludviklamb 3 роки тому +1

    I came to this video after not understanding Udacity’s explanation of it. You’ve done a fantastically better job at explaining this. Thank you !

  • @runeheidt
    @runeheidt 3 роки тому +1

    This was soooo great. You helped me a great deal. Thank you.

  • @salin.chaudhary
    @salin.chaudhary Рік тому

    thank you very much for such an awesome explanation 🤗

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

    This is pure gold
    Got say that

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

    only one word.... Awesome!

  • @Turjak_art
    @Turjak_art 3 роки тому

    Very nice sir, thank you

  • @PaulinhoOsfaya1
    @PaulinhoOsfaya1 4 роки тому +55

    hahahahahahaah "if you directly look the solution, I gonna inject corona virus in your computer!" Dude, I laughed so hard! Awesome!

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

    that's a brilliant guide thank you!

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

    your knowledge in oops concept is excellent ...

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

    This is superb....!!!!!!!

  • @iShubhamPanchal
    @iShubhamPanchal 4 роки тому +1

    🙏Dhanyavaad 💕

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

    Great video.

  • @ahmedkhalid6481
    @ahmedkhalid6481 19 днів тому

    THANK YOU SO MUCH !

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

    This is insane.thanks

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

    21:48 XD XD. Like I would hear myself sometimes. You have got my like for it.

  • @art_ik
    @art_ik 3 роки тому

    Thanks, Best tutorials to get started

  • @aaronaaronaaron5922
    @aaronaaronaaron5922 3 роки тому +1

    This tutorials are as funny as excellent!! Thanks 😁😁😁

  • @StudyGyaan
    @StudyGyaan 3 роки тому

    Awesome Tutorial - when ever i want to revise, i just go through these tutorials

    • @codebasics
      @codebasics  3 роки тому +1

      I am happy this was helpful to you.

    • @StudyGyaan
      @StudyGyaan 3 роки тому

      @@codebasics I saw ur comment, at the same time I was watching ur binary search video 😁

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

    It's amazing!

  • @jorgegonzaloalfaro5378
    @jorgegonzaloalfaro5378 3 роки тому +1

    bro you are so good at teaching!! thank you!!

  • @jagritisehgal3867
    @jagritisehgal3867 4 роки тому

    great explanation

  • @podaisotopaclaudia
    @podaisotopaclaudia 3 роки тому

    This video helped me understand a lot this topic, thank you !!!

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

    Thank you for the playlist ❤❤❤
    For Q.1 , I found it difficult to solve the logic....
    For Q.2) It was pretty simple
    Using this playlist for my GATE preparation 💪💪💪

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

    Write a function called searchBFS which given the tree or graph as defined below returns every number smaller than 4 in the order it was found using the breadth first technique.

  • @user-mq8pw6oi7g
    @user-mq8pw6oi7g 8 днів тому

    The best video ever

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

    I often find that writing iteration-over functions in the same space as recursion-into functions can cause people a ton of issues with understanding. Instead, you could also write get_level() recursively like this:
    def get_level():
    if not self.parent:
    return 0
    else:
    return self.parent.get_level() + 1

  • @FahmiEshaq
    @FahmiEshaq 6 місяців тому

    Thank you

  • @MadhuExplorer
    @MadhuExplorer 4 роки тому +1

    Thanks for creating data structure videos..

    • @codebasics
      @codebasics  4 роки тому

      Glad you like them!

    • @naveenkrishnavamshi2502
      @naveenkrishnavamshi2502 3 роки тому

      @@codebasics can you explain me this "child.parent = self" i did not get it properly in the video

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

    For printing levels, I found a much better and easy implementation. Hope this helps!
    def printTree(self, level=0):
    indent = " " * level
    if level==0:
    print(self.data)
    else:
    print(indent +"|__"+ self.data)
    if self.children:
    for child in self.children:
    child.printTree(level + 1)

  • @ankit7918
    @ankit7918 4 роки тому +1

    Thank you sir 🙂

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

    just awesome

  • @tusharsrivastava4328
    @tusharsrivastava4328 4 роки тому +1

    sir please make videos on how to deal with text data in machine learning?

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

    Haha, I watched your vids about Classes, came back to this one listened to "child is an instance of tree node class, i will have a parent property and ..." and my brain instantly shuts off, not understanding the relationship xD
    I get inheritance within a new object. But the jiggle juggle of two methods within the main class creating the child and the parent within itself is killing me hahaha

  • @obadajaber2759
    @obadajaber2759 3 роки тому

    amazing

  • @PriyankaSingh
    @PriyankaSingh 3 роки тому +7

    Can you cover more topics as a part of this series such as heaps, priority queues?

  • @KavitaSingh-uw3cn
    @KavitaSingh-uw3cn 2 роки тому

    Hey , can you tell me how i can print the parent nodes of the any search element inside the general tree?

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

    @codebasics Thanks so much, and I really appreciate how helpful your videos are! I've been working with Python data structures for more than a year and have about 7 years of experience. I am very comfortable using Python data structures. Does learning Java data structures help me crack FAANG?

  • @hassaanraheem5644
    @hassaanraheem5644 4 роки тому +1

    Sir kindly upload arrays data structures 1d , 2d and 3d using numpy in python 9 days from my DS exam

  • @songsport1917
    @songsport1917 3 роки тому

    Молодец ❗❗❗

  • @devisowmyamorampudi1898
    @devisowmyamorampudi1898 3 роки тому +1

    def print_tree(root,indent):
    print(indent + root.data)
    if len(root.children) > 0:
    for child in root.children:
    print_tree(child,indent*2)
    print_tree(root," ")
    This can get you the indentation without counting levels. btw thanks pal;)

  • @MegaMaliak
    @MegaMaliak 3 роки тому

    Could you possibly advise how to print the results in a table where every line and column consists of in line reading of parent to furthest child? example,
    parent | child 1 | apple
    parent | child 1 | banana
    parent | child 2 | apple
    parent | child 2 | banana
    ?

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

    Thanks sir

  • @balajichippada
    @balajichippada 3 роки тому

    Sir can you explain how to convert this tree into nested dictionaries please

  • @RunyCalmera
    @RunyCalmera 3 роки тому

    How would you print it visually?

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

    Hello Sir, how does one do DFS iteratively on this general tree structure. I keep running into issues. def print_tree(self):
    print(self.data)
    if self.children:
    for child in self.children:
    child.print_tree() def print_tree(root):
    if root is None:
    return []
    stack = []
    stack.append(root)
    while stack:
    curr = stack.pop()
    if curr is not None:
    print(curr.data)
    stack.append(curr.children)

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

    I really appreciate this video. I do have a question though. In a work environment are we expected to assign the child nodes statically or is there a way to dynamically set the child nodes?

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

      You can set nodes dynamically. When you do that you need to balance out a tree by re arranging nodes

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

    Hey Dhawal. Why did you not make a different class for build tree and add methods like add_child inside that?

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

    Thank you so much for this video. Is it possible to print the level of leaf node using the technique at @19:00 minute

  • @siddhanth177
    @siddhanth177 3 роки тому

    I Directly looked at the solution! :P

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

      now you are doomed :) you need to send your laptop for corona virus quarantinee :)

    • @sakshamsinha6945
      @sakshamsinha6945 3 роки тому

      @@codebasics lol

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

    @23:17 Sir, I cannot have Corona Virus in my computer, I found the exercise interesting and have solved it without looking at the solution.

  • @gowrik.s8478
    @gowrik.s8478 3 роки тому +1

    then how to check the level of leaf node

  • @Windiddy
    @Windiddy 3 роки тому

    Hi so this code printed a tree structure but it does not create a tree structure folders. How do I make folders using this code?

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

    in order traversal is only returning left values and root node when i run program

  • @jaysoni7812
    @jaysoni7812 4 роки тому +5

    hello sir i writing this program by my self and what i did change the code
    instead of creating get_level function i pass level parameter in print_tree() method, that's decrease the line of code
    here it's my code
    def print_tree(self, level = 0):
    prefix = " " * level + "__|" if level != 0 else ""
    print(prefix, self.data)
    for c in self.children:
    c.print_tree(level + 1)

    • @codebasics
      @codebasics  4 роки тому +1

      Nice tip actually. Yes this can make the code more compact

  • @salsabillaaliskaputri6931
    @salsabillaaliskaputri6931 3 роки тому

    did thats tree can clustering some topic from large text documents like twitter?

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

    Can you show us how to get the number of children in a given level? Something like get_children(self, level=0) method and passed param level (int) would return total number of children at that specified level.

  • @ritikbhilware4030
    @ritikbhilware4030 3 роки тому +8

    Hey, Can you also make a playlist for all the different kinds of algorithms used? Will be very helpful.

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

    Hello Sir, can you please create a video developing of project using only DSA ?

  • @nrrajan6802
    @nrrajan6802 3 роки тому +6

    Hi can you explain how to build this tree dynamically, ie values coming from an array or json

    • @simplygood6335
      @simplygood6335 3 роки тому

      There are no problems in doing that stackoverflow.com/questions/444296/how-to-efficiently-build-a-tree-from-a-flat-structure
      You just need to have 1 loop, on each step you check, if element has a parentId, if true then get the parent from the original array then do parentNode.children.add(elementNode); elementNode.parent = parentNode; (I have omitted parent/element node creation)

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

    I got a small doubt. print_tree is a method of class (Treenode) right. at the end of the code, we used (print_tree) method. Rather than using (root.Treenode._print_tree) why we are using just(root._print_tree)