Doubly Linked List | Insert, Delete, Complexity Analysis

Sdílet
Vložit
  • čas přidán 13. 09. 2024

Komentáře • 115

  • @BlueTreeCode
    @BlueTreeCode  Před 3 lety +4

    Important Note: For deleteLast and deleteStart, if the return type was void this would be fine, but since we're returning a node, that node should not have any reference to the list (meaning you can still get to the list from that node). This means toDelete.next should be set to null for the deleteStart method and toDelete.prev should be set to null for the deleteLast method before returning toDelete.

  • @north4220
    @north4220 Před 2 lety +8

    i have an exam in 7 hours , you're saving me thank you so much , i love the way you explain and the animations makes it more clear , please continue

    • @BlueTreeCode
      @BlueTreeCode  Před 5 měsíci

      That's the goal! Hope you aced that exam! Please don't forget to share / recommend the channel to others / on social media to help it grow.

  • @wassimfourkaoui7128
    @wassimfourkaoui7128 Před 2 lety +7

    You are a savior man, Best explained Double Linked on the Internet period... You explained it better in 17 mins than my prof did in 120mins!
    Thanks alot!

    • @BlueTreeCode
      @BlueTreeCode  Před 5 měsíci +1

      I'm glad it helped!! Please don't forget to share / recommend the channel to others / on social media to help it grow.

  • @shermukhammadusmonov7417
    @shermukhammadusmonov7417 Před 3 lety +8

    Got stuck at the last challenge of Section 9 of the "Java Programming Masterclass for Software Developers" by Tim Buchalka on Udemy.
    Your videos helped me a ton to understand the concepts of Singly/Doubly Linked Lists, which were not properly explained in my paid course
    Dude, you are a freakin' gem! Thanks a lot!

    • @BlueTreeCode
      @BlueTreeCode  Před 3 lety

      Thank you!! I'm very glad it's helped you, Shermukhammad!

  • @magicshroomliberety
    @magicshroomliberety Před 4 lety +7

    Best lecture by far on doubly linked lists on the web and possibly in college clear and to the point great job

  • @NoveltyKnown
    @NoveltyKnown Před 3 lety +5

    THIS WAS THE BEST VIDEO I HAVe SEEN SO FAR!!! Great work please post more!

  • @smileifyoupoopie9926
    @smileifyoupoopie9926 Před 4 lety +12

    YESSS FINALLY NOT HINDI VIDEO HOLY CRAP.
    edit: you're expert, thanks to You, linked lists are easy for me now.

  • @BlueTreeCode
    @BlueTreeCode  Před 5 lety +3

    Hey Everyone! Thanks for checking out my video! Don't forget to Like, Subscribe, and MOST IMPORTANTLY click that Notification Bell for updates! :)

  • @dilrubakhan7112
    @dilrubakhan7112 Před 3 lety +1

    This is the best Data structure series I would say. Thank you

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety

      Thank you, Dilruba! Please feel free to share these videos on social media as they do help out the channel a lot.

  • @marhawk6468
    @marhawk6468 Před 3 lety

    I now understand doubly linked list because of you!!! These videos and animations are amazing!!

  • @mohdymi
    @mohdymi Před 2 lety

    Yeah, once I saw that Singly linked list video, and was totally amazed of how simple you made it, when I got into your channel and found this video I was %100 sure it was going to be even better!

  • @mohammadjunaid8093
    @mohammadjunaid8093 Před 3 lety +2

    Bundles of Thanks! sir for making my life easier, I appreciate your work, and keep it up.

  • @aghashahhyder6084
    @aghashahhyder6084 Před 2 lety

    Gosh..!
    I never thought this topic is this much Simple and Easy...
    Man You nailed it..!
    Love You😍❤️

  • @hamzariaz9700
    @hamzariaz9700 Před 3 lety

    Sir you clear the whole concept of doubly and singly linkdlist in just one video

  • @Shelly-kx2wz
    @Shelly-kx2wz Před 4 lety +2

    Thank You!! The visual explanation helped a lot.

  • @samytouabi4087
    @samytouabi4087 Před 3 lety

    Thank you so much, I couldn't understand why doing .prev.next would change anything but now I do thanks to you!

  • @ya00278
    @ya00278 Před 4 lety +1

    Thank you sooo much for the explanation! way much better than my teacher did!! subscribed:)

    • @BlueTreeCode
      @BlueTreeCode  Před 4 lety

      Thank you, and I'm glad it helped, Ya Li! :)

  • @virjeeva
    @virjeeva Před 3 lety

    Clearly explained DLL along with animation and code, Thanks

  • @disuoluwatoyin545
    @disuoluwatoyin545 Před 3 lety

    I'm so happy I found this video! and channel best explanation for LL

  • @arsyandatjandra1085
    @arsyandatjandra1085 Před 3 lety

    u just earned a new subscriber mate, very nice and informative video

  • @mkuroglu
    @mkuroglu Před 3 lety +1

    One of the most informative videos I have seen about linkedlists TY ! Just one question I have: at delAfter shouldn't last line of code be: toDelete.prev.next= null; ? Because at this point we know our toDelete is the last node of the list wouldn't setting its prev.next= toDelete.next; make it a nullPointerException ? This has been boggling my mind

  • @hrithikjaysingpure9623
    @hrithikjaysingpure9623 Před 3 lety +1

    Thanks man this was so helpful.

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety +1

      Thank you so much, Hrithik! Please feel free to share these videos on social media as they do help out the channel a lot.

    • @hrithikjaysingpure9623
      @hrithikjaysingpure9623 Před 2 lety

      @@BlueTreeCode sure!

  • @MelodyAnastasiaHarper
    @MelodyAnastasiaHarper Před 3 lety +1

    This was so informative and helpful, thank you!

  • @prova_prime3630
    @prova_prime3630 Před 3 lety

    cant tell you how much i love you right now

  • @deanbaquir290
    @deanbaquir290 Před 4 lety +2

    Amazing explanation!

  • @runwuhuang3078
    @runwuhuang3078 Před 3 lety

    Thank you, it's very clearly explained! I have followed you

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety

      Thank you so much, Jacob Huang! Please feel free to share these videos on social media as they do help out the channel a lot.

  • @Sauce-ke
    @Sauce-ke Před rokem

    Why dont you have a tail and only head? The main advantage of Doubly Linked List is that you dont have to traverse all the way to the end if you want to delete at the end or add at the end because you have tail. But you helped me a lot thank you

  • @bibekmaity28
    @bibekmaity28 Před 4 lety

    Most amazing video on linked list ever💕💕💕💕

    • @BlueTreeCode
      @BlueTreeCode  Před 4 lety +1

      Thank you for the kind comment, BIBEK MAITY :)

  • @arber10
    @arber10 Před 4 lety +2

    Thank you, it's very clear explained!
    Wouldn't be the time complexity for "Insert End" and "Delete End" also O(1) if the "head.prev" would point to the last element in the list, and the "last.next" to the head (head.prev.next = head)? So basically you would have a circle.

    • @BlueTreeCode
      @BlueTreeCode  Před 4 lety +2

      @Arber Osmani Thank you and I'm glad it helped :) So, what you're thinking about is most likely a circular doubly linked list (a small variation to the doubly linked list). In that case, then yup, head.prev would refer to the last node and head.prev.next would refer to head. Therefore inserting and deleting at the end would be an O(1) operation. This, however, happens to be a non-circular doubly linked list, so head.prev refers to null, and the only way to reference the end would be to traverse the entire list. Hope this helped. :)

    • @tychojurjens9466
      @tychojurjens9466 Před 2 lety +1

      @@BlueTreeCode but with a doubly linked list you also keep track of the tail and not only the head. so that means the time complexity of adding a node to the end is the same as adding a note to the benning being O(1)

  • @elpaso7271
    @elpaso7271 Před 2 lety

    You're a live saver!!!

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety

      Thank you, Ryan! I really appreciate it. If you enjoy this content, feel free to share it as it helps out the channel. :)

  • @rebechkah
    @rebechkah Před 2 lety

    I am having some issues understanding the syntax of the code from Delete Node After:
    "for (; toDelete !+ null; toDelete = toDelete.next)"
    what is the semi-colon at the beginning?

  • @nasimajosefi
    @nasimajosefi Před rokem

    thank you for your explanation :)

    • @BlueTreeCode
      @BlueTreeCode  Před 5 měsíci

      Thank you! :) Please don't forget to share / recommend the channel on social media to help it grow.

  • @samandarboymurodov8941

    thank you, it was well explained

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety

      Thank you Samandar! Please feel free to share these videos on social media as they do help out the channel a lot.

  • @huzijadli8499
    @huzijadli8499 Před 4 lety

    GREAT CONTENT !!

  • @zucucuz
    @zucucuz Před 4 lety

    thank u soooo much that was sooooo helpful

  • @hamzariaz9700
    @hamzariaz9700 Před 3 lety

    Sir you are great

  • @h.k3260
    @h.k3260 Před rokem

    Guys quiick question, min 3:03 how does maikng before.next= head, then assigning head to before work(thats like saying 3->5, then saying 5->5 no?)

  • @neilgoswami142
    @neilgoswami142 Před 3 lety

    bro ur so clutch for this video

  • @orestdymarchuk2910
    @orestdymarchuk2910 Před 2 lety

    Much appreciate for explanation! 🇺🇦❤️

    • @BlueTreeCode
      @BlueTreeCode  Před 5 měsíci

      Thank you so much!! Please don't forget to share / recommend the channel to others / on social media to help it grow.

  • @manabel8964
    @manabel8964 Před 3 lety

    Thank you for your time. but ur lecture is like running water

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety

      Thank you for the feedback, Mana! I really do appreciate it. I have definitely slowed down in my later videos. You can try adjusting the speed to 0.75/0.5 via the settings icon.

  • @miraclecindy
    @miraclecindy Před 3 lety

    Such great explanations! really appreciate your great work. Is it possible to post the actual codes for us to try them out?

    • @BlueTreeCode
      @BlueTreeCode  Před 5 měsíci

      Thank you so much!! I no longer have the code, but it's something I will do in the future. Please don't forget to share as it will help the channel to grow.

  • @ericlee6169
    @ericlee6169 Před 3 lety

    Can I know how to do the Delete Node Before? I tried but it’s just not working

  • @Gzzzzzz111
    @Gzzzzzz111 Před 4 lety

    Hi, wonderful explanation of linked list, but I would like to know why you did not choose to have another Node just for the last node in the list. Wouldn’t having a last node be more sufficient when you are trying to delete or add nodes in the end?

    • @BlueTreeCode
      @BlueTreeCode  Před 4 lety

      Hi Gabriel Zn, Thank You! I'm assuming you mean a "tail" reference. I chose to use just a "head" reference, because sometimes you will be given a DLL without a "tail" and for whatever reason you may be expected to manipulate the linked list as is. However, it depends on what you want out of the linked list. For example, a really good use of a Doubly Linked List with a "tail" would be a LRU(Least Recently Used) cache, where you'll remove the least recently used items from the "tail" for example and add the most recently used to the head. Whatever the situation, once you know how to manipulate the list without a tail, doing so with a tail will be very easy. Hope this helps :)

    • @Gzzzzzz111
      @Gzzzzzz111 Před 4 lety

      @@BlueTreeCode Thank you for getting back to me! Really appreciate the work. Hope you can make more data structure videos like this. :)

    • @BlueTreeCode
      @BlueTreeCode  Před 4 lety +1

      @@Gzzzzzz111 No Problem! Looking back at my answer, I meant to remove the LRU node from the tail. I'll edit it in. I'm glad it's helping. I would like to add more videos, especially to finish up the series on data structures, but I have quite a lot going on at the moment. Once things ease up, I'll try to get those videos up.

  • @seifalamiryousef8233
    @seifalamiryousef8233 Před 2 lety

    doesn't a doubly linked list have a tail? won't that makes adding and removing from the end easier and faster?

  • @archirnobenz
    @archirnobenz Před 2 lety

    So basically, think of the next and previous of a node as the pointers to the address of another node.

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety

      Yep. The prev and next references are basically the addresses to the object(node) they are referring to. Hope this helps :)

  • @Github_tech_with_ty
    @Github_tech_with_ty Před 3 lety

    Thanks again

  • @Github_tech_with_ty
    @Github_tech_with_ty Před 3 lety

    In adding a node to End why could you just say curr.next=n ? Isn't curr.prev already curr?

    • @BlueTreeCode
      @BlueTreeCode  Před 3 lety

      Hi Tyrique, I think you may have mistaken n.prev with curr.prev. Note that 'n' will be the last node in the list. Not setting n.prev to curr will mean we cannot traverse backwards from the end of the list (which disrupts the formation of the Doubly Linked List). Hope this helps :)

  • @hamzariaz9700
    @hamzariaz9700 Před 3 lety

    Sir why you are not upload that types of videos

    • @BlueTreeCode
      @BlueTreeCode  Před 3 lety

      I'm planning to upload a video on Hash Tables soon.

  • @alex0917lfo
    @alex0917lfo Před 4 lety

    Hi, is that possible you can upload the while loop version of DeleteToAfter? Thanks

    • @alex0917lfo
      @alex0917lfo Před 4 lety

      and please also upload the while loop version of AddToAfter. Thanks

    • @BlueTreeCode
      @BlueTreeCode  Před 4 lety +4

      Hi, @@alex0917lfo. So to covert the for loop to a while loop, we want to look at the stopping(toDelete != null) and iterative (toDelete = toDelete.next) condtions. And all we do is replace the for loop with:
      while(toDelete != null){
      if(toDelete.data == data){
      toDelete = toDelete.next;
      }
      }
      For the recursive method, it's a bit more work but it's pretty simple. The first thing to do is get rid of the parameter 'curr' since this was only used for passing the state to the next recursive call. We can add curr inside the method block instead.
      Then starting from scratch: we'll check to make sure head != null.
      void addAfter(int insertAfter, int data){
      DllNode curr = head;
      if(curr == null){
      return;
      }
      .....
      }
      The next step is to copy the 2nd if block along with its nested if and throwing it inside of a while loop (This is our logic). Then get rid of the else block, since that's used for the recursive call.
      while( curr != null){
      if(curr.data == insertAfter){
      DllNode n = new DllNode(data);
      if(curr.next != null){
      curr.next.prev = n;
      n.next = curr.next;
      }
      curr.next = n;
      n.prev = curr;
      break; //once the node is inserted, break out the loop.
      }
      curr = curr.next; // iterates over the list.
      }
      And all we do is combine these parts, and that's it :) Hope this helps.
      void addAfter(int insertAfter, int data){
      DllNode curr = head;
      if(curr == null){
      return;
      }
      while( curr != null) { //stopping condition.
      if(curr.data == insertAfter){
      DllNode n = new DllNode(data);
      if(curr.next != null){
      curr.next.prev = n;
      n.next = curr.next;
      }
      curr.next = n;
      n.prev = curr;
      break; //once the node is inserted, break out the loop.
      }
      curr = curr.next // iterates over the list.
      } //end of while loop.
      }

    • @alex0917lfo
      @alex0917lfo Před 4 lety

      @@BlueTreeCode Thanks a lot!

  • @Github_tech_with_ty
    @Github_tech_with_ty Před 3 lety

    Also why are you doing todelete.prev.next = null why not just todelete = null

    • @BlueTreeCode
      @BlueTreeCode  Před 3 lety

      Hi Tyrique, in order to remove an object, there must not be any references pointing to that object. If we set toDelete to null, the previous node's next will still be pointing to the node that toDelete was originally pointing to. Notice that by setting toDelete.prev.next to Null, we're removing the only reference pointing to the last Node, therefore allowing it to be garbage collected / destroyed. Hope this helps :)

  • @edgarpinia3564
    @edgarpinia3564 Před 3 lety

    hi your videos are amazing, i have a question, how compare a nodo with other nodo in the double linked list

    • @BlueTreeCode
      @BlueTreeCode  Před 3 lety

      Hi Edgar, you can compare nodes via their data or memory address. Comparing via memory addresses will let you know if the two references point to the same node. For example. If (p1 == p2) means p1 and p2 reference the same node. Comparing via data would be something like, if (p1.data == p2.data). This just compares their data properties, however it doesn't tell us if p1 and p2 are referencing the same node. Hope this helps :)

  • @that_off
    @that_off Před 6 měsíci

    wahsh

  • @kennethdelacruz9485
    @kennethdelacruz9485 Před 3 lety

    Please answer
    User input:
    Code
    Description
    Price
    Quantity
    Type
    How can I use double linked list if user input 5 instead of 1 base on your tutorial

    • @BlueTreeCode
      @BlueTreeCode  Před 3 lety +1

      Hi Kenneth, that sounds like a 'Product', so you can create a Product class with instance variables (code, description, price, quantity, type).
      class Product {
      //You can adjust to whatever types you need.
      int code;
      String description;
      double price;
      double quantity;
      String type;
      public Product(code, desc, price, quantity, type){
      /* Initialize the instance variables here with the arguments */
      }
      }
      Once that's done, you can do something like this:
      class DllNode {
      Product product;
      DllNode next
      public DllNode(product){
      //NB: product a reference to a Product Object.
      this.product = product;
      this.next = null;
      }
      }
      Hope this helps :)

    • @kennethdelacruz9485
      @kennethdelacruz9485 Před 3 lety

      @@BlueTreeCode thankyou btw. I already pass my project but I'm happy that I've learned new ways to do a linkedlist

    • @BlueTreeCode
      @BlueTreeCode  Před 3 lety

      @@kennethdelacruz9485 Glad to hear, Kenneth!

    • @kennethdelacruz9485
      @kennethdelacruz9485 Před 3 lety

      @@BlueTreeCode Btw, how can I stored values of the variables
      System.out.print("
      Enter a Code :");
      code = sc.next();
      System.out.print("
      Enter a Description:");
      desc = sc.next();
      System.out.print("
      Enter a price :");
      price = sc.nextDouble();
      System.out.print("
      Enter a quantity :");
      quant = sc.nextInt();
      System.out.print("
      Enter a type :");
      type = sc.next().charAt(0);
      where to store?
      Product n = new Product(code,desc,price,quant,type); ??
      then when I call it in a method InsertBegin()
      public class DoublyLinkedList{
      public DoublyLinkedList(DllNode head){
      this.head =head;
      }
      public void InsertBegin(Product product){
      if (head == null){
      head = new Product(code,desc,price,quant,type);
      }
      }
      }
      Im just practicing your tutorial.

    • @kennethdelacruz9485
      @kennethdelacruz9485 Před 3 lety

      Confused also.

  • @duanle6085
    @duanle6085 Před 4 lety

    like

  • @nedwilliams8806
    @nedwilliams8806 Před 3 lety +1

    Is it me or does he sound like he has marbles in his mouth sometimes

  • @evelynsummer4020
    @evelynsummer4020 Před 2 lety

    you speak too fast like a bullet train it's hard for me to catch up...

    • @BlueTreeCode
      @BlueTreeCode  Před 2 lety

      Hi Evelyn! I'm so sorry about that. I was unaware of how fast I was speaking due to limited feedback in the beginning days of the channel. However, I've definitely adjusted in my later videos. For now you can try adjusting the video speed to 0.75/0.5 via the settings icon. Let me know if that helps and thank you for the feedback, Evelyn!