Doubly Linked List | Insert, Delete, Complexity Analysis

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 พ.ย. 2024

ความคิดเห็น • 116

  • @BlueTreeCode
    @BlueTreeCode  3 ปีที่แล้ว +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 2 ปีที่แล้ว +10

    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  8 หลายเดือนก่อน

      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 2 ปีที่แล้ว +8

    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  8 หลายเดือนก่อน +2

      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 3 ปีที่แล้ว +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  3 ปีที่แล้ว

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

  • @johnlysterarbiol1174
    @johnlysterarbiol1174 หลายเดือนก่อน

    The visualization on the bottom and the code on the top is spot on, very easy to understand.

  • @magicshroomliberety
    @magicshroomliberety 4 ปีที่แล้ว +7

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

  • @BlueTreeCode
    @BlueTreeCode  5 ปีที่แล้ว +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 3 ปีที่แล้ว +1

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

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

  • @NoveltyKnown
    @NoveltyKnown 4 ปีที่แล้ว +5

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      Thank you for the kind comment, Angel!

  • @marhawk6468
    @marhawk6468 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      You're welcome, marhawk!

  • @hamzariaz9700
    @hamzariaz9700 4 ปีที่แล้ว

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

  • @aghashahhyder6084
    @aghashahhyder6084 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      I'm glad it helped, Agha! :)

  • @virjeeva
    @virjeeva 3 ปีที่แล้ว

    Clearly explained DLL along with animation and code, Thanks

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      I'm glad it helped, Jeevanandham! :)

  • @mohdymi
    @mohdymi 2 ปีที่แล้ว

    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!

    • @BlueTreeCode
      @BlueTreeCode  8 หลายเดือนก่อน

      Thank you so much!!!

  • @mohammadjunaid8093
    @mohammadjunaid8093 3 ปีที่แล้ว +2

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว +1

      You're very welcome, Mohammad! Thank you for the kind comment.

    • @MohsinAli-zq5mw
      @MohsinAli-zq5mw 3 ปีที่แล้ว

      Pasa waaaa

    • @mohammadjunaid8093
      @mohammadjunaid8093 3 ปีที่แล้ว

      @@MohsinAli-zq5mw Rasha kna Che pa Rapadesawam.

  • @disuoluwatoyin545
    @disuoluwatoyin545 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      Thank you so much, Toyin!

  • @Shelly-kx2wz
    @Shelly-kx2wz 4 ปีที่แล้ว +2

    Thank You!! The visual explanation helped a lot.

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว

      Glad it's helped, Cryptix 44! :)

  • @mkuroglu
    @mkuroglu 3 ปีที่แล้ว +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

  • @samytouabi4087
    @samytouabi4087 3 ปีที่แล้ว

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

  • @runwuhuang3078
    @runwuhuang3078 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      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 ปีที่แล้ว

    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

  • @prova_prime3630
    @prova_prime3630 3 ปีที่แล้ว

    cant tell you how much i love you right now

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      It's very much appreciated, prova_prime!

  • @arsyandatjandra1085
    @arsyandatjandra1085 3 ปีที่แล้ว

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

  • @deanbaquir290
    @deanbaquir290 4 ปีที่แล้ว +2

    Amazing explanation!

  • @MelodyAnastasiaHarper
    @MelodyAnastasiaHarper 3 ปีที่แล้ว +1

    This was so informative and helpful, thank you!

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      Glad it helped, Melody! :)

  • @arber10
    @arber10 4 ปีที่แล้ว +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  4 ปีที่แล้ว +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 2 ปีที่แล้ว +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)

  • @ya00278
    @ya00278 4 ปีที่แล้ว +1

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

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว

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

  • @bibekmaity28
    @bibekmaity28 4 ปีที่แล้ว

    Most amazing video on linked list ever💕💕💕💕

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว +1

      Thank you for the kind comment, BIBEK MAITY :)

  • @hrithikjaysingpure9623
    @hrithikjaysingpure9623 3 ปีที่แล้ว +1

    Thanks man this was so helpful.

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว +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 3 ปีที่แล้ว

      @@BlueTreeCode sure!

  • @elpaso7271
    @elpaso7271 3 ปีที่แล้ว

    You're a live saver!!!

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      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 2 ปีที่แล้ว

    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?

  • @miraclecindy
    @miraclecindy 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  8 หลายเดือนก่อน

      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.

  • @orestdymarchuk2910
    @orestdymarchuk2910 2 ปีที่แล้ว

    Much appreciate for explanation! 🇺🇦❤️

    • @BlueTreeCode
      @BlueTreeCode  8 หลายเดือนก่อน

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

  • @nasimajosefi
    @nasimajosefi 2 ปีที่แล้ว

    thank you for your explanation :)

    • @BlueTreeCode
      @BlueTreeCode  8 หลายเดือนก่อน

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

  • @neilgoswami142
    @neilgoswami142 4 ปีที่แล้ว

    bro ur so clutch for this video

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว

      Thank you very much, Neil Goswami! :)

  • @samandarboymurodov8941
    @samandarboymurodov8941 3 ปีที่แล้ว

    thank you, it was well explained

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

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

  • @manabel8964
    @manabel8964 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      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.

  • @ericlee6169
    @ericlee6169 4 ปีที่แล้ว

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

  • @h.k3260
    @h.k3260 2 ปีที่แล้ว

    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?)

  • @hamzariaz9700
    @hamzariaz9700 4 ปีที่แล้ว

    Sir you are great

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      Thank you, Hamza! I try my best.

  • @Gzzzzzz111
    @Gzzzzzz111 4 ปีที่แล้ว

    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  4 ปีที่แล้ว

      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 4 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว +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.

  • @huzijadli8499
    @huzijadli8499 4 ปีที่แล้ว

    GREAT CONTENT !!

  • @zucucuz
    @zucucuz 4 ปีที่แล้ว

    thank u soooo much that was sooooo helpful

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว

      Glad you found it helpful! :)

  • @hamzariaz9700
    @hamzariaz9700 4 ปีที่แล้ว

    Sir why you are not upload that types of videos

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

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

  • @seifalamiryousef8233
    @seifalamiryousef8233 2 ปีที่แล้ว

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

    • @betrayy5151
      @betrayy5151 ปีที่แล้ว

      Yeah it should be O(1)

  • @archirnobenz
    @archirnobenz 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

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

  • @alex0917lfo
    @alex0917lfo 4 ปีที่แล้ว

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

    • @alex0917lfo
      @alex0917lfo 4 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว +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 4 ปีที่แล้ว

      @@BlueTreeCode Thanks a lot!

  • @Github_tech_with_ty
    @Github_tech_with_ty 4 ปีที่แล้ว

    Thanks again

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      You're very welcome, Tyrique!

  • @Github_tech_with_ty
    @Github_tech_with_ty 4 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      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 :)

  • @edgarpinia3564
    @edgarpinia3564 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      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 :)

  • @Github_tech_with_ty
    @Github_tech_with_ty 4 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      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 :)

  • @kennethdelacruz9485
    @kennethdelacruz9485 3 ปีที่แล้ว

    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  3 ปีที่แล้ว +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 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      @@kennethdelacruz9485 Glad to hear, Kenneth!

    • @kennethdelacruz9485
      @kennethdelacruz9485 3 ปีที่แล้ว

      @@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 3 ปีที่แล้ว

      Confused also.

  • @that_off
    @that_off 8 หลายเดือนก่อน

    wahsh

  • @robertstimmel1100
    @robertstimmel1100 3 ปีที่แล้ว

    12:52

  • @duanle6085
    @duanle6085 4 ปีที่แล้ว

    like

  • @nedwilliams8806
    @nedwilliams8806 3 ปีที่แล้ว +1

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

  • @evelynsummer4020
    @evelynsummer4020 3 ปีที่แล้ว

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

    • @BlueTreeCode
      @BlueTreeCode  3 ปีที่แล้ว

      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!