Data Structures: Linked Lists

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

Комментарии • 357

  • @wolfferoni
    @wolfferoni 6 лет назад +567

    You know that moment of satisfaction when you finally understand something? I got it from this video. I've spend so much time watching my lectures, looking at tutorials and explanations of LinkedLists and never really understood it. I decided to write you the code and try to explain to myself what each line meant and when I got stuck, listened to you explain it with the little diagrams and finally(!) understand what on earth this node and head and next thing means. THANK YOU.

    • @patcoder1287
      @patcoder1287 4 года назад +3

      @Ella Blun spot on.
      It's called removal of bias
      Very effective tool.
      Sad how we humans are literally built to doubt every damn thing unless reinforced by multiple sources
      But it's the reality we must live with.

    • @jasoncarzano9388
      @jasoncarzano9388 4 года назад

      Yeah

    • @alfonsocanady7564
      @alfonsocanady7564 2 года назад +4

      It’s been 4 years, what are you doing now?

    • @Vrinda219
      @Vrinda219 2 года назад

      Nice

    • @reynaldosilva1115
      @reynaldosilva1115 Год назад

      @@alfonsocanady7564 he is still trying to solve linked list problems,… haha ask me what I’m doing in 4 years!!

  • @eliastefera8574
    @eliastefera8574 2 года назад +3

    This is probably the best video you can find on RUclips that talks about LinkedList. Great job!

  • @grace1081
    @grace1081 7 лет назад +47

    Gayle, if you ever see this, I really love the way this mini lesson is organized and delivered. Very helpful I thank you I am passing a class because of you!!!

  • @khatharrmalkavian3306
    @khatharrmalkavian3306 4 года назад +166

    Any conversation about linked lists should BEGIN with the following warning:
    "You probably shouldn't be using a linked list for this."

    • @pvic6959
      @pvic6959 3 года назад +4

      @Peterolen i have no idea why that person said that. linked lists absolutely have their place. this is like saying "You probably shouldn't be using a _hash table_ for this." Well, if you just need to store a list of things, then yes, you dont need a hashtable. But if you need a quick mapping, 100% use a hashable. All data structures have their uses and strong points

    • @pvic6959
      @pvic6959 3 года назад

      @Peterolen But an ArrayList is just an implementation of a linked list. I don't really see it as different. However, if we treat them as different, I agree with you. I can only remember using LinkedList (the data type) like once lol. Most of the time i used ArrayList. But to me both of these are linked lists (the concept, not the data type)

  • @MannyGonzalezReyna
    @MannyGonzalezReyna 7 лет назад +28

    Thanks so much for putting the algorithm and the coding together on the same page, that's the best way to learn any coding language.

  • @SenLan-o2h
    @SenLan-o2h Год назад +1

    You know that moment of satisfaction when you finally understand something? I got it from this video.

  • @elbuhdai605
    @elbuhdai605 5 лет назад +22

    Thank you so much. The visual representation that changes with each new line of code is so helpful for a concept like this. Code for nodes can often look kind of cryptic without a visual representation of how things move.

  • @nkeiruw5873
    @nkeiruw5873 4 года назад +9

    I've never watched a programming video from beginning to end before. A truly class explanation. Thank you!

    • @jehrilipaad5075
      @jehrilipaad5075 4 года назад +1

      SIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIMPHHHHH

    • @xfire3778
      @xfire3778 4 года назад

      Jehrili Paad couldn’t agree more

  • @saindst
    @saindst Год назад

    The one thing I have come to find out about all these data structure explainations on youtube is that only a hand few will ever give you an actual REAL life damn example of where and HOW it is used so you can actually make sense of it all. It makes a HUGE, a HUUUUUUUGE difference.

  • @gnanasekaranebinezar7199
    @gnanasekaranebinezar7199 2 года назад

    I have been looking for crystal clear explanation to algorithms such a long time. Finally I landed up on right place. What a diligent explanation. Learned a lot. Splendid. No words to appreciate further.

  • @moneytree7924
    @moneytree7924 5 лет назад +9

    Appending a node to a linked list doesn't have to be O(n) if we keep track of the `tail` node as well as the `head` node. But very well done explanation as usual, Gayle! Your content are always such confidence boosters!!

    • @saveerjain6833
      @saveerjain6833 2 года назад +1

      is that not just doubly linked?

    • @sanjeen2503
      @sanjeen2503 Год назад

      ​@@saveerjain6833 no.

    • @murloc_rampage3856
      @murloc_rampage3856 Год назад

      @@saveerjain6833 It's not doubly because doubly linked lists have a pointer to the previous and next nodes. To Append at O(1) all we'd need is for the linked list to have both a head var and a tail var. By keeping track of a tail node, we make appending at the end O(1) because we have instant access to the tail node as well as allowing us to assign the new tail node and set it to keep track effectively. Then by making it into a doubly linked list this makes searching faster do to our doubly linked list allowing us to search both ends of the entire set to quicken searching. so having a tail node by the linked list definition does not make it a doubly linked list. It's the nodes themselves that have a pointer to before and after nodes that makes it doubly linked. I hope this makes sense.

  • @kidou123456
    @kidou123456 5 лет назад +1

    The wrapper class of LinkedList dynamically changes the head by prepending to inform other "lists" pointers. This is really neat! Thank you!

  • @Buebrowndj
    @Buebrowndj 3 года назад +2

    Excellent, easy to digest explanations and 0 ads. Thank you for your content

  • @guptayash4
    @guptayash4 6 лет назад +4

    The deleteWithValue(int data) function will throw NullPointerException when the element does not exist in the LinkedList.
    For Example, LinkedList: 7 (List has only one Node, I.e. only head node with value 7)
    And, you try to delete the node with value 5.

  • @Fivousix
    @Fivousix 8 лет назад +75

    Great videos, I have been watching some and I really like the way you draw at the same time you show the code. They are short and straight to the point.
    I would just like to point out for future viewers that in C/C++ if you do not explicitly delete those nodes memory will be leaking.

    • @pascal3889
      @pascal3889 7 лет назад +3

      Yes. While using C/C++, after deleting a node you also need to free the memory which was allocated to the node. The programmer is required to handle memory management in C/C++.

    • @damnstupidoldidiot8776
      @damnstupidoldidiot8776 5 лет назад

      delete head;
      head=head->next;

    • @damnstupidoldidiot8776
      @damnstupidoldidiot8776 5 лет назад

      @@xCwieCHRISx Whoops, my bad!
      head=head->next;
      delete head->previous;

    • @TheKhakPakflyest
      @TheKhakPakflyest 4 года назад +1

      Dope! I was watching this from a C++ background and was thinking to myself, "java doesn't have to explicitly free memory?" xD

    • @ronaldskorobogat3152
      @ronaldskorobogat3152 4 года назад +3

      @@TheKhakPakflyest Java has the garbage collector and any time it sees that an object can't be reached, like in the video where we skip over that Node object, it automatically deletes the object and frees up the space. Something C++ doesn't offer ;)

  • @ej-14-
    @ej-14- Год назад

    I re-watched this video several times, thank you for posting this!

  • @markkfitx
    @markkfitx 6 лет назад

    This is one of the few videos that I found does not make the topic more confusing. Thanks so much

  • @abdelrhman110
    @abdelrhman110 7 лет назад +277

    My God, that keyboard click sound is erotic. What keyboard is that?

    • @shadowalkzx
      @shadowalkzx 7 лет назад +18

      iMac keyboard

    • @masteryoda3679
      @masteryoda3679 6 лет назад +24

      Abd-Elrhman Rizk lmfao. I thought the same thing and wondered if i was the only one who enjoyed that sound until I went to the comments section and saw this. I'm glad i wasn't the only one. Lol.

    • @scwalcofscwalcof1404
      @scwalcofscwalcof1404 6 лет назад +25

      Get yourself a mechanical keyboard and the sound of this keyboard will make you cringe.

    • @megamanx2006
      @megamanx2006 6 лет назад +5

      Abd-Elrhman Rizk dude, if sounds like that are your thing, search ASRM audio or something like that...

    • @mirknankazmzad8517
      @mirknankazmzad8517 6 лет назад +11

      omg thanks, i searched and i'm listening to it like 1 hour or something. this is great. like braingasm

  • @KaisarAnvar
    @KaisarAnvar Год назад +1

    She is SUCH A GENIUS

  • @nitishmehta9322
    @nitishmehta9322 5 лет назад +10

    Really amazing tutorial on Linked lists, thank you!! Just want to add why accessing array is faster because its elements are always stored in contiguous memory locations this is kind of its disadvantage also as you need to have in advance that contiguous chunk of memory in advance. Feel free to correct me if I am wrong.

  • @segintendorocks
    @segintendorocks 6 лет назад +22

    This girl is amazing. Thanks for the fantastic tutorial :D.

  • @user-xr2ik2ci2t
    @user-xr2ik2ci2t 5 лет назад +5

    Great video! I was so confused with Linked Lists in my CS class, but this makes it so simple to understand!

  • @asivaprasadam
    @asivaprasadam 4 года назад +4

    Minor correction with the function:
    deleteWithValue (int data);
    Change: Move the special case if statement completely to the end of the while loop.
    Reasoning: If the head and the next node has the same value and equals the data value. The next element won't be deleted. So the special case should be after the while loop. Correct me if I'm wrong.
    Example data for the original function to fail : 10, 10, 20, 39, 48, ... data = 10

    • @chelseyfoster7260
      @chelseyfoster7260 2 года назад

      She could also change the if statement that checks if the head needs to be deleted to a while statement.

    • @sanjeen2503
      @sanjeen2503 Год назад

      she has mentioned the requirement of the function - delete only the first node having data same as the given data

  • @francis-comedy-club
    @francis-comedy-club 3 года назад

    of all the "LinkedList" videos I've watched, None can be compared to this. Thank you for this explanatory video 🥳🥳🥳🥳🥳🥳🥳🥳🥳

  • @alcatraz8623
    @alcatraz8623 2 года назад

    a video from 2016 gave me the info i needed, thank you

  • @BruceKarrde
    @BruceKarrde Год назад +1

    So, do I understand correctly, that with this linkedlist we're only adding values and re-routing instead of actually removing values? If so, would this mean that the size will increase over time? If so, is there any way to access the values that have been 'ignored'?

  • @arilowen
    @arilowen 9 месяцев назад +1

    Will the delete implementation work for the last node on a list?

  • @xuwang1292
    @xuwang1292 6 лет назад +6

    if you talk about the usage of this structures.Such as where can we use this structures and where can not. I think this video will be much better.

  • @kakashi99908
    @kakashi99908 2 года назад

    Linked list are used on existing objects like Bags or even implemented in the bag itself. Is there a name for things like Linked List? I think they are called sorting algorithms..

  • @Xtremedave2
    @Xtremedave2 5 лет назад +7

    I've seen other implementations that have a tail Node that points to the end of the linked list, making appending an O(1) operation. Why is this not taught in this video?

    • @EchoVids2u
      @EchoVids2u 4 года назад

      Exactly what I was thinking.

  • @damilola_adegunwa
    @damilola_adegunwa 2 года назад +1

    thanks for this. I'm trying to find problems that would fit LinkedList best

  • @tannerbarcelos6880
    @tannerbarcelos6880 5 лет назад +1

    Linked lists are one data structure I really understand with not much of a problem. Although pointers are still a struggle for me, the linked list makes a lot of sense.. I guess practice, practice, practice will help!

  • @bakihanma1865
    @bakihanma1865 2 года назад

    Gayle is awesome, I got her book, only read 1st chapter so far .

  • @rajatsharma3673
    @rajatsharma3673 4 года назад

    your explanations are so smooth I'm so thankful to you ma'am.

  • @SandraWantsCoke
    @SandraWantsCoke Год назад +1

    Is there a course like this but in Go?

  • @CarlitoProductions
    @CarlitoProductions 6 лет назад +3

    This is super clear to me, and I'm briefly flipping through data structures since someone told me I should learn them to apply for work. I understand how it's set up in Java, but how would these be implemented in Javascript outside of DOM?

  • @thanhattran284
    @thanhattran284 3 года назад

    Great vid! I understand it faster than 100x times thanks to you

  • @j3froc63
    @j3froc63 5 лет назад

    So linked list are actually objects that point to another object? And at 2:30 when you write 'Node next' does the program already know what 'next' does? Is 'Node next' like a method that is predefined within the program??

  • @tannerbarcelos6880
    @tannerbarcelos6880 5 лет назад

    Appending and displaying both recursively or just with a loop I practically have down. It’s the destructor and the delete() methods in c++ where the struggle kicks in a bit

  • @kurifukun7633
    @kurifukun7633 3 года назад +1

    Good video but noob question, where do you specifically put the main driver code(public static void main(String[] args)) ? Thanks

  • @Karen_Mkrtchyan_Horquri_Gandz
    @Karen_Mkrtchyan_Horquri_Gandz 10 месяцев назад +1

    I might be wrong but doesn't this code have a memory leak? You are never destroying an element, so the original value entered is still there, but now there isn't a pointer to it. Its just gonna hand out there and every time you delete an element, another chunk of memory becomes unaccusable.

  • @mk177
    @mk177 3 года назад +1

    This is otherworldly explanation technique, amazing. "Actionpacked supercoder blockcuster" ! :)

  • @looseyfur6669
    @looseyfur6669 5 лет назад +6

    omg someone i can understand!! amazing, thank you for speaking clearly! that is hard to come by in this area!!

  • @SamvitAgarwal
    @SamvitAgarwal 6 лет назад +4

    Hey, great video! I was just wondering, however, when is using a linked list actually useful? Since for most operations it requires linear time, versus an array which requires constant time for most operations, what is the main advantage of using a linked list versus an array?

    • @xXZombieHunter0802Xx
      @xXZombieHunter0802Xx 6 лет назад +9

      My main appeal is that it's dynamic and the memory isn't assigned when compiled, like an array. An array has to be whatever length you initialize it to, but you can continually add to Linked Lists. The reason is that arrays use memory locations right after each other, so the computer needs to know how far to go before stopping. The Linked List uses the a memory address, so as long as it knows where to go, it doesn't need consecutive memory locations, and be continuously added to without overflow.

  • @mac_88_59
    @mac_88_59 6 лет назад +1

    understood this way better the way you explained it compared to how my professor did. thank you so much.

  • @elcat9091
    @elcat9091 6 лет назад

    At 5:31, it is stated that current is a method. Isn't it an instance variable of type Node?

  • @scottrichman798
    @scottrichman798 6 лет назад

    Wonderful explanation. Textbook for my class gets confusing sometimes since its not step by step so these videos help explain further

  • @veronika_franz
    @veronika_franz 6 лет назад +1

    It's a very good video.
    The method deleteWithValue ...
    when you have a LinkedList with
    headvalue0 | linkedToNextValue1 -- value1 | linkedToNextValue2 -- value2 | linkedToNextValue3 -- value3 | linkedToNull
    and you want to delete value2,
    you go to value1 and set the former "linkedToNext2" variable to "linkedToNextValue3", so basically you work around as said in the video.
    But this does not delete Value2, right? Because value2 is still linkedToNextValue3, so it should not be collected, should it?
    headvalue0 | linkedToNextValue1 -- value1 | linkedToNextValue3 -- value3 | linkedToNull
    value2 | linkedToNextValue3 --^
    So, basically you have information hanging around, haven't you?
    To really delete value2, wouldn't it be necessary to set the link of "value2 | linkedToNextValue3 --^" to "value2 | linkedToNull", so that this element can be collected, like this:
    headvalue0 | linkedToNextValue1 -- value1 | linkedToNextValue3 -- value3 | linkedToNull
    value2 | linkedToNull
    so, this would be:
    ...
    while(current.next != null) {
    //if data of the next element of the current element
    //equals the data we want to delete
    if(current.next.date == data) {
    //set the next-variable of the current element
    //to the value safed in the next-variable of next element (so it's next next)
    current.next = current.next.next;
    //and set the next-variable of the next-element to null
    //current.next.next = null;
    }
    }
    NullPointerException should in this case not occur, as next-element exists (because we found it and want to delete it), so there is a variable that can be set to a certain value, in this case it's null. And we have an exception for the last element. And only the last element can contain null in the next-variable.
    And considering that LL are used for many elements, because that's why they are so practical (better than arrays with specific length), plus the operations that can be used over a longer period of time, this looks to me like the outcome is something like a christmas tree/one data string with information hanging around.
    Is there somewhere an explaination how java's LinkedList is structured/built? I think you cannot actually get the actual Node (Node current = ...), but have to work through with methods such as element(), ... So, I am actually looking for something that can be used for a Node variable (as I would do it in the LL that I built on my own).

  • @brontiago
    @brontiago 2 года назад

    If you keep a tail variable along with the head, appending to the list should be 0(1) since you won't have to traverse the whole list to the end

  • @cast1439
    @cast1439 4 года назад

    Thanks for the lesson! It really helped me understand the code much better. Also, I do believe you have a problem with your append method. Your linked list will end up adding the first element twice.

  • @alifruslan2728
    @alifruslan2728 4 года назад

    Just curious trying, probably that statement in line no. 45 is not necessary, right? The while loop will accomplish the task I guess. Correct me if I am wrong kindly. And the video is too good. Thank you.

  • @adamhendry945
    @adamhendry945 4 года назад +1

    None of the nodes you delete are destroyed with your method (not only the head). You have two nodes pointing to the subsequent node because the link of the "deleted" node is never removed (garbage collection won't pick this up). Although you can't access deleted nodes anymore since it's not doubly-linked, your memory grows without bound, which is bad.

    • @sanjeen2503
      @sanjeen2503 Год назад

      link TO the deleted node is changed. Thus, there remains no reference assigned to access it, hence it will be garbage collected.

  • @entertainme151
    @entertainme151 8 лет назад +4

    You noted that when calling the remove method, if the is to be removed, then the node is never really "destroyed." This was in contrast to the case where the node was in the middle, where there was no such note. I assume you're talking about a Java implementation, so are you saying Java's garbage collector can't detect such a deletion? If this is the case, how would I fix this bug?

    • @Hereisthething
      @Hereisthething 8 лет назад +1

      I was thinking the same thing! We could fix it by having the head.next point to null before "deleting" it. Java's linkedlist implementation does this to apparently help gc - android.googlesource.com/platform/libcore/+/refs/heads/master/ojluni/src/main/java/java/util/LinkedList.java#176

    • @LazerNR
      @LazerNR 6 лет назад

      once you remove the node, you are essentially removing the reference to it. if you haven't referenced that node directly elsewhere outside some local scope, which you likely haven't, the garbage manager will detect it and delete it. this is true for managed languages such as java and c#. for c and c++, you would need to manually delete most times unless you are using smart pointers and such.

    • @0207chinna
      @0207chinna 6 лет назад

      referenceless memory which is left undeleted in c++ causes memory leak..

    • @isfisfisf
      @isfisfisf 6 лет назад

      I think that comment only applies to languages without garbage collection or am I wrong? Why wouldn't the garbage collection collect that? There would be no reference to the old head...

  • @frutoramirezjuanjose5930
    @frutoramirezjuanjose5930 Год назад

    What model of keyboard are you using? it sounds so satisfying

  • @florianhug221
    @florianhug221 8 лет назад +18

    I think there is a problem in the deleteWithValue-method of the example. Because the while is checking for current.next it won't be able to delete the value if it is in the last node of the list.

    • @yiani31
      @yiani31 8 лет назад +24

      I don't think there's a problem: it's not 'current' that gets deleted, it's current.next. If the value is in the last node, then when current == the second-to-last node, the code will set current.next = current.next.next, which is null

    • @ranjitasahu1621
      @ranjitasahu1621 7 лет назад +2

      yes it can't delete the last node

    • @pranavpatil795
      @pranavpatil795 7 лет назад +2

      yiani31 yes you are right. The real problem is NullPointerException when you set current = current.next while deleting last node. A small null check should be placed before setting value for current

    • @IMaxoI
      @IMaxoI 7 лет назад +9

      There is no Exception. When you call current.next=current.next.next, and current is the second to last node, current.next.next will be null. This means that current.next will be null after the deletion, and this is not only fine, but desired. NullPointerException is trown when you actually try to use the null value somehow, like accessing it.

    • @veronika_franz
      @veronika_franz 6 лет назад

      like when you create the first node (head) then only the data variable is set, but not the next variable, so maybe it goes automatically null

  • @squadbustersgamings
    @squadbustersgamings 5 лет назад +1

    Why do we need to create current=head?
    What does it do??

  • @lohithn8557
    @lohithn8557 4 года назад

    On deleting of data, do head element will be updated? As we are assigning head to current node variable and delete operation is performed on it.

  • @lingeswarannagarajan293
    @lingeswarannagarajan293 7 лет назад +11

    Great video but i am expecting the coding in C but u r doing in it java. I am not familiar with it.... anyways nice explanation for the core concept

    • @VzAmPliFiEdzV
      @VzAmPliFiEdzV 6 лет назад +5

      @Ella Blun well Java is also object oreinted where c isn't. So it might be harder wrapping your head around imperative languages if you've only had practice with oop

    • @isfisfisf
      @isfisfisf 6 лет назад +1

      Also Java does garbage collection where C does not. This means that, in Java, if nothing is pointing to an object, then it will automatically be deleted. In C, you have to do this deletion your self or you might get memory leaks.

    • @user-oo2gz9ln8v
      @user-oo2gz9ln8v 5 лет назад

      Ella Blun really bad analogy. it’s more like cursive vs print and not really being able to decipher cursive.

  • @jgraiver
    @jgraiver 5 лет назад +1

    what actually gets returned in the public void append(int data) method? I'm confused as to why you need the return statement on line 17?

    • @xguilloful
      @xguilloful 5 лет назад

      the if statement handles the situation when the head is null. If they leave the code without the return on line 17 it'll add the node where its supposed to and then it'll run the code below it (since we don't have an "else" at the end of the if statement bracket) and it'll add the same node a second time

  • @idilsaglam1278
    @idilsaglam1278 3 года назад +1

    This video is very helpful! Thanks a lot !!!!

  • @EchoVids2u
    @EchoVids2u 4 года назад

    1:15 Correction. If you implement a linked list with a tail variable pointing to the last node, appending to the end of a list will take 0(1) time.

  • @rvohra91
    @rvohra91 7 лет назад +1

    Nice tutorials. Just a small note, maybe for prepend method, you should check for null head and assign it the new value, rather than creating a new node and point it to null. Again, it totally depends on scenario, but you considered it for other methods, so thought to point.

  • @webdev4786
    @webdev4786 3 года назад

    Just changing the pointer, wouldn't that create trash in memory? Is there a way to clear the object from the memory?

  • @joaocampos9615
    @joaocampos9615 4 года назад

    Hey, @HackerRank. There was only one thing i did not understand : "If we preappend we have a issue because we change the Head..." Only with preappend ? i guess we always need a Wrapper/class and a "stamp" on one node to navigate and do operations and always know which one is the first. To not miss a single node. Is this correct ?
    Anyway, thanks for the free learning :)

  • @shaikmasthan8254
    @shaikmasthan8254 5 лет назад

    That is an amazing explanation. I have two questions
    1. Does the deleted node garbage collected?
    2. How to delete a node with duplicate data. I.e.If there are multiple nodes with same data and we want to delete the last data Node. ? How do we differentiate the two nodes with same data ?

  • @saurabhbazzad
    @saurabhbazzad 6 лет назад +1

    I think there is a problem with this code, both the Node class and LinkedList classes are declared public whereas we can have only one public class per file

  • @mergatafa8501
    @mergatafa8501 7 лет назад

    The best lecture I have ever listened

    • @Maaaaars
      @Maaaaars 7 лет назад

      seriously! This is the best one I've seen. She's hella good

  • @Tony.Nguyen137
    @Tony.Nguyen137 3 года назад

    The class node has only 2 fields, Node next and int data. What if I want to add a String to my LinkedList, to which field is the string allocated??

  • @cindy__4920
    @cindy__4920 7 лет назад +4

    This video is very helpful. Thank you!

  • @abcstephanie
    @abcstephanie 5 лет назад +1

    thank you!! you explained this so beautifully clear. kudos

  • @felipefallas2726
    @felipefallas2726 3 года назад

    but what if I want to delete what's inside a node, taking as a parameter a reference to the data inside said value, and not the number of node itself, how would you approach that?

  • @Blacktop_Battle
    @Blacktop_Battle 3 года назад

    If you just walk around an item in a linked list, isn't that item still stored in memory, since we haven't actually deleted it? On a large scale, can that cause problems?

  • @manivannan39
    @manivannan39 6 лет назад

    while appending an element does the head node keep changing and we add a new node after the head node? , is that the meaning of the append code in the video

  • @amazon5272
    @amazon5272 2 года назад

    why do you need to walk through a linked list for delete? is not linked list have o(1) for insert and delete?

  • @r1ch007cs123
    @r1ch007cs123 2 года назад

    Great explanation of the linked list.

  • @alexalmanza8989
    @alexalmanza8989 6 лет назад

    is there a better way to remove the head? since you aren't able to access it wouldn't that cause a memory leak? or is it different in java

  • @blyatman635
    @blyatman635 6 лет назад

    Can you introduce another node in the Linked List class that will remember the last member we add, something like tail, and when adding you just add to the tail and make it O(1) instead of O(n) ?

  • @captainutki01
    @captainutki01 6 лет назад +1

    We can't have two public classes in the same file though right?

  • @ardiansyah6794
    @ardiansyah6794 5 лет назад

    I wished she was my lecturer.. so fluent and to the point 😀

  • @chodfanclub8004
    @chodfanclub8004 5 лет назад

    Won't the delete function only delete the first instance of a node with matching data? Not every instance?

  • @samuelzrna1651
    @samuelzrna1651 5 лет назад

    But what if you want to delete the head and if the head is the only node in the linked list?

  • @vivekjadon2986
    @vivekjadon2986 7 лет назад

    One question. if I make use of a temporary object to store current node in append function, then I won't need the LinkedList class containing head separately. I can implement it using just one class. I will use that temporary object to reach the end of linked list while the head will remain the same. Is this correct?

  • @YouTube_Staff
    @YouTube_Staff 4 года назад

    snaps out for you, this is such a great explanation.

  • @plttji2615
    @plttji2615 3 года назад

    Thank you for the video, I am preparing for the following interview question. When searching for the element in the list, what if the list is too big, then what would you do? I am really struggling how to answer this question. Could you please help me?

  • @maymotivation6215
    @maymotivation6215 4 года назад

    your voice is so sweet i grasped everything u said

  • @Steve-jr9yz
    @Steve-jr9yz 11 месяцев назад

    Can `current.next.next` be null.empty? Ie, what if we are trying to remove the last element?

  • @quantalk_lecturequantalk3409
    @quantalk_lecturequantalk3409 6 лет назад

    Question! Why the data's type is int, we can store any data type in node right? so why (int data)

  • @FBGZ
    @FBGZ 6 лет назад

    in link lists can you have different types of data at the same time? such as intergers and strings at a same time

  • @phillyeagles0728
    @phillyeagles0728 6 лет назад

    Thanks for the video. Just wondering, would it be fine to have a contructor in LinkedList, that would take a node as a parameter, and allow you to create LinkedList objects? Or maybe it's useless?

  • @sarthakgupta2528
    @sarthakgupta2528 7 лет назад

    great explanation!! right from the scratch. this helped me a lot, thanks!!

  • @paladin1147
    @paladin1147 4 года назад

    Put the return at the end so if you there are any duplicates in the (DeleteWithValue) it wont skip them over.

  • @somerandomguy000
    @somerandomguy000 3 года назад

    Append is also constant if you keep a reference of your tail.

  • @yousefbaghlaf6713
    @yousefbaghlaf6713 6 лет назад

    What if we wanted to show the elements of the linked list? Like a show method?

  • @wibowester
    @wibowester 5 лет назад +1

    Reallly thank you for explaining!!! I learned a lot from it!

  • @pXxDisasteRxXq
    @pXxDisasteRxXq 3 года назад

    ok, let's suppose that I declare my class Node.
    It has inside itself a declaration of another class Node, that is Node next.
    so, when I declare an instance of my Node class, e.g. Node node, it should initialize his Node next, who should initialize his Node next, who should initialize his Node next, who should initialize his Node next, who should initialize his Node next, who should initialize his Node next, who should initialize his Node next, (.......) and this loop should get us to a memory overflow soon or later, meaning the portion of memory that was planning for the program execution can't contain all my Node instances.
    I'm curious to know why this doesn't happen, cause I feel there is something big I still can't get about these data structures.

  • @TimScratch
    @TimScratch 5 лет назад

    Would nesting the class node under linked list make a difference?

  • @crackcodinginterview4995
    @crackcodinginterview4995 4 года назад

    That’s a nice way to explain Linked list!

  • @malakdesouky9123
    @malakdesouky9123 4 года назад

    Which coding platform did you use? Thank you this was very helpful!

  • @anonymousvevo8697
    @anonymousvevo8697 4 года назад +1

    i just loooove you , and your explanations

  • @deagan_o
    @deagan_o 7 лет назад +3

    I really don't understand why we need to walk through all nodes in the list to append a new node.
    Just define a first/head and last/tail pointer in the list class.
    l.append() will then be in constant time.

    • @tylera3126
      @tylera3126 6 лет назад +1

      Deagan Otterspeer what if you want to delete the last node

    • @deagan_o
      @deagan_o 6 лет назад +1

      In a singly linked list or doubly?
      For singly: l.delete() is not l.append().
      l.append() can be in constant time, deleting the first element constant time, deleting the last element O(n),
      deleting an element in the middle O(n-distance to end)
      SLL can be useful if you want to save memory on a list that will only be added to / checked, and rarely deleted from the end of it. Priority queues for example, if implemented as SLL, will always delete first (constant), appended to end (constant).
      DLL allows constant modifications anyway, except for adding/removing non-first or non-last elements.
      And even those times could be improved by for example, binary searching if list is ordered - log n
      Or if not ordered, you could start your search at first or last depending on where the element is expected to be (if known), or, intuitively, start + 1 and end - 1 ... till start + n/2 and end - n/2 in O(2n/2), which will be better than to left-to-right list traversal in O(n - distance to end) if the element is in the second half. Basically, if the element then is closer to start or end than the middle, it'll be better.

    • @streetfighteryamahar178
      @streetfighteryamahar178 5 лет назад

      MapleStory For Life baby!