Binary Tree 1. Constructing a tree (algorithm and pseudocode)

Поділитися
Вставка
  • Опубліковано 25 січ 2025

КОМЕНТАРІ • 52

  • @KuntaKinteToby
    @KuntaKinteToby 4 роки тому +44

    I paid $8600 for a bootcamp course and I've learned more from your channel for free.
    Honestly you've saved my career as a programmer because I was beginning to think I'm just not smart enough to get these concepts. But I was wrong, I just wasn't being taught properly. I understand this stuff really easily with proper explanation.

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 роки тому +12

      Thanks for the lovely comment. Stick with it. There's lots of great material online :)KD

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

      @@ComputerScienceLessons You're very welcome, thank you for the excellent guidance!

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

      I'm not understanding how you had any "career as a programmer" when you took a "bootcamp course".

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

      @@atlantic_love Do I really have to explain to you how going to school and then building a portfolio works?
      I'm not going to, but thanks for replying to a 2 year old comment to say something nasty and condescending, I hope it feels real good.
      I'll be blocking you now.

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

      @@KuntaKinteToby Nasty? Nobody was nasty. I simply questioned you. I don't believe you, in other words. Spreading misinformation is disingenuous.

  • @jibran6635
    @jibran6635 3 роки тому +5

    Highly underrated channel!

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

    Damn, my code looked exactly like your pseudocode, except in one place: instead of using the pointers to the elements in the array/data structure whose elements you use to form the tree, I dynamically allocated memory everytime I needed it. Learnt a lot about pointers and dynamic memory allocation along the way!

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

      Excellent. Once you understand the fundamental principle of the algorithm, you can adapt and refine it in all kinds of ways when you implement it. :)KD

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

    Such simple explanations, thank you so much

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

    sir you are a legend

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

    You just saved my school life

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

    There is only one question left... What is it used for and why do you need something like this?

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

      Good question. In hindsight, I wish I had said more about the applications of binary trees. Database indexes are constructed like this to enable fast retrieval of data. Network routers also store information about other routers on a network like this, for the same reason - fast retrieval. Some data compression algorithms (E.G. Huffman encoding) make use of binary trees. There's a good Stack Overflow article about it here. stackoverflow.com/questions/2130416/what-are-the-applications-of-binary-trees :)KD

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

      @@ComputerScienceLessons thank you :D Looks like stack overflow has always an answer for you 😂

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

    Do you have any advice of how to learn these ADTs quickly? I have my A levels exam (CIE 9608 P4) in one month and I left data structures last and I shouldn't have done that. (You have the best explanations on the internet btw)

    • @ComputerScienceLessons
      @ComputerScienceLessons  3 роки тому +9

      Stick to the ones mentioned in the specification of your course. Namely: stack, queue, linked list, dictionary, binary tree. Get to know the way they work first, i.e. what do they look like when you add and remove data items. You should be sketching lots of diagrams. Then move on the the written algorithms. Study the past papers and sample papers (and mark schemes) on the exam board's website and get a feel for the style of questions; often they ask the same questions year after year but with different data www.cambridgeinternational.org/programmes-and-qualifications/cambridge-international-as-and-a-level-computer-science-9608/past-papers/ Give it about an hour data and don't neglect the other stuff you need to know. Stay positive, a month is plenty of time if you use it wisely.
      Good luck. :)KD

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

      @@ComputerScienceLessons Thanks for the advice! I will try my best

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

      @@roasted_guava5706 how did it goo lol??

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

    JavaScript guy here - haven't worked with trees - the result looked like a mess to me (i.e. despite a lot of comparisons the tree isn't sorted such that you could easily find stuff) - is this really somehow more efficient for some things?

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

    What happens if you have two nodes with the same value?

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

      Less than equal condition with left so it will be allocated to left

  • @umer09
    @umer09 5 років тому +1

    Is this a Binary Tree or Binary Search Tree? As per my understanding, this should be a binary search tree since the data is being assigned according to rules. Can you please confirm?

    • @ComputerScienceLessons
      @ComputerScienceLessons  5 років тому +4

      The name 'Binary Search Tree' is often shortened to 'Binary Tree'. Same thing.

    • @princesspranaya7123
      @princesspranaya7123 5 років тому +1

      @@ComputerScienceLessons I dont think so. Every binary search tree is a binary tree but binary tree is not a binary search tree. Binary tree just keeps adding nodes to right and left.

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

      @@princesspranaya7123 They technically aren't the same that's true, but in practice when people say 'binary tree' they mean 'binary search tree', because a true/pure 'binary tree' isn't nearly as useful.

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

    Hi, are the 3 array variables defined in the form of a record? Then the array is is defined as Type record?

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

      You could use three array variables, or you could use a two dimensional array. I'm not sure I understand your terminology. Personally, I would not describe these arrays as records.

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

    Brilliant explanation!!!

  • @Domappcent
    @Domappcent 5 років тому +1

    This Helped so much. Thankyou! :D

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

    I get the urge to reimpplement this lesson in code, use all of the Harry Potter cast and then see who comes out on top.

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

    Thank you !

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

    So terminal nodes can also mean infertile, yes? XD

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

    do you have python version of this

  • @azkymohamed123
    @azkymohamed123 7 років тому +2

    Thank you sir

  • @armeenhossain665
    @armeenhossain665 5 років тому

    I didn't the ptr part?
    Explain me the line "Do until ptr = 0"?

    • @ComputerScienceLessons
      @ComputerScienceLessons  5 років тому +4

      Hi Armeen. The algorithm is trying to find an unoccupied position in which to put the new node. Imagine a tree that already has lots of nodes in it, and we are trying to add a new node. If a potential parent of the new node has a left pointer with a value of 0, it means that it doesn't already have a child on the left of it, so this position is free for the new node if it needs to go there. If a potential parent of the new node has a right pointer with a value of 0, it means that it doesn't already have a child on the right, so the right position is free if this is where it needs to go. This is why each loop in the pseudo-code runs until it finds a ptr value of 0. The exit condition of the loop (Do until ptr = 0) is a bit like saying "do until we find a parent with nothing already attached in place I need to go". Make sure you understand the diagram and the table first and the pseudo-code will start to make sense. Stick with it. It still amazes me how someone invented this in the first place.

    • @armeenhossain665
      @armeenhossain665 5 років тому +1

      Correct me if I am wrong. Ptr works as a free pointer?

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

    Good

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

    You do save lives

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

    literal W programmer

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

    nice content. although I don't like the pseudocode. I code in python, java and cpp but still, your pseudocode looks like a Frankenstein's monster to me.

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

      I like VB because it looks most like the pseudocode used on UK exam papers :)KD