Тёмный

Data Structures: Linked Lists 

HackerRank
Подписаться 266 тыс.
Просмотров 1 млн
50% 1

Learn the basics of Linked Lists. This video is a part of HackerRank's Cracking The Coding Interview Tutorial with Gayle Laakmann McDowell. www.hackerrank.com/domains/tut...

Наука

Опубликовано:

 

26 сен 2016

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 357   
@wolfferoni
@wolfferoni 6 лет назад
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 года назад
@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 3 года назад
Yeah
@alfonsocanady7564
@alfonsocanady7564 2 года назад
It’s been 4 years, what are you doing now?
@Vrinda219
@Vrinda219 Год назад
Nice
@reynaldosilva1115
@reynaldosilva1115 Год назад
@@alfonsocanady7564 he is still trying to solve linked list problems,… haha ask me what I’m doing in 4 years!!
@grace1081
@grace1081 6 лет назад
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!!!
@MannyGonzalezReyna
@MannyGonzalezReyna 6 лет назад
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.
@elbuhdai605
@elbuhdai605 4 года назад
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.
@eliastefera8574
@eliastefera8574 Год назад
This is probably the best video you can find on RU-vid that talks about LinkedList. Great job!
@khatharrmalkavian3306
@khatharrmalkavian3306 4 года назад
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 года назад
@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)
@kidou123456
@kidou123456 4 года назад
The wrapper class of LinkedList dynamically changes the head by prepending to inform other "lists" pointers. This is really neat! Thank you!
@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.
@user-xr2ik2ci2t
@user-xr2ik2ci2t 4 года назад
Great video! I was so confused with Linked Lists in my CS class, but this makes it so simple to understand!
@markkfitx
@markkfitx 6 лет назад
This is one of the few videos that I found does not make the topic more confusing. Thanks so much
@Buebrowndj
@Buebrowndj 2 года назад
Excellent, easy to digest explanations and 0 ads. Thank you for your content
@nitishmehta9322
@nitishmehta9322 5 лет назад
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.
@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 🥳🥳🥳🥳🥳🥳🥳🥳🥳
@saindst
@saindst 9 месяцев назад
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.
@rajatsharma3673
@rajatsharma3673 4 года назад
your explanations are so smooth I'm so thankful to you ma'am.
@user-px9zz3fo9o
@user-px9zz3fo9o 7 месяцев назад
You know that moment of satisfaction when you finally understand something? I got it from this video.
@segintendorocks
@segintendorocks 5 лет назад
This girl is amazing. Thanks for the fantastic tutorial :D.
@ej-14-
@ej-14- Год назад
I re-watched this video several times, thank you for posting this!
@mac_88_59
@mac_88_59 6 лет назад
understood this way better the way you explained it compared to how my professor did. thank you so much.
@abcstephanie
@abcstephanie 5 лет назад
thank you!! you explained this so beautifully clear. kudos
@KaisarAnvar
@KaisarAnvar Год назад
She is SUCH A GENIUS
@scottrichman798
@scottrichman798 6 лет назад
Wonderful explanation. Textbook for my class gets confusing sometimes since its not step by step so these videos help explain further
@cindy__4920
@cindy__4920 6 лет назад
This video is very helpful. Thank you!
@nkeiruw5873
@nkeiruw5873 3 года назад
I've never watched a programming video from beginning to end before. A truly class explanation. Thank you!
@jehrilipaad5075
@jehrilipaad5075 3 года назад
SIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIMPHHHHH
@xfire3778
@xfire3778 3 года назад
Jehrili Paad couldn’t agree more
@tannerbarcelos6880
@tannerbarcelos6880 5 лет назад
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!
@alcatraz8623
@alcatraz8623 2 года назад
a video from 2016 gave me the info i needed, thank you
@Fivousix
@Fivousix 7 лет назад
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 лет назад
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 4 года назад
@@xCwieCHRISx Whoops, my bad! head=head->next; delete head->previous;
@TheKhakPakflyest
@TheKhakPakflyest 4 года назад
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 года назад
@@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 ;)
@looseyfur6669
@looseyfur6669 5 лет назад
omg someone i can understand!! amazing, thank you for speaking clearly! that is hard to come by in this area!!
@bakihanma1865
@bakihanma1865 2 года назад
Gayle is awesome, I got her book, only read 1st chapter so far .
@owonubijobsunday4764
@owonubijobsunday4764 5 лет назад
Thank you very much. You just lifted a load off me head
@thanhattran284
@thanhattran284 3 года назад
Great vid! I understand it faster than 100x times thanks to you
@hassankazmi5443
@hassankazmi5443 6 лет назад
Awesome job Gayle!
@wibowester5173
@wibowester5173 5 лет назад
Reallly thank you for explaining!!! I learned a lot from it!
@YouTube_Staff
@YouTube_Staff 4 года назад
snaps out for you, this is such a great explanation.
@sarthakgupta2528
@sarthakgupta2528 6 лет назад
great explanation!! right from the scratch. this helped me a lot, thanks!!
@abrahamparker6140
@abrahamparker6140 5 лет назад
Excellent emphasizing. Thanks a lot.
@sundarb6673
@sundarb6673 5 лет назад
Thank you, Chris Gayle!
@rsmease
@rsmease 6 лет назад
@aycanocal6506
@aycanocal6506 4 года назад
Great tutorial, easy to understand! Thank you!
@cast1439
@cast1439 3 года назад
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.
@guptayash4
@guptayash4 5 лет назад
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.
@ardiansyah6794
@ardiansyah6794 4 года назад
I wished she was my lecturer.. so fluent and to the point 😀
@xuwang1292
@xuwang1292 5 лет назад
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.
@mk177
@mk177 3 года назад
This is otherworldly explanation technique, amazing. "Actionpacked supercoder blockcuster" ! :)
@anonymousvevo8697
@anonymousvevo8697 4 года назад
i just loooove you , and your explanations
@omarm9794
@omarm9794 5 лет назад
thank you so much for the video. now i understand the linked lists.
@moneytree7924
@moneytree7924 5 лет назад
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 года назад
is that not just doubly linked?
@sanjeen2503
@sanjeen2503 Год назад
​@@saveerjain6833 no.
@murloc_rampage3856
@murloc_rampage3856 6 месяцев назад
@@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.
@maymotivation6215
@maymotivation6215 3 года назад
your voice is so sweet i grasped everything u said
@crackcodinginterview4995
@crackcodinginterview4995 3 года назад
That’s a nice way to explain Linked list!
@idilsaglam1278
@idilsaglam1278 3 года назад
This video is very helpful! Thanks a lot !!!!
@fzane14
@fzane14 3 года назад
Thank you so much, this was very easy to follow.
@oscarwang7920
@oscarwang7920 5 лет назад
Thanks for the explanation !
@Dpaz2009
@Dpaz2009 7 лет назад
i love this channel :) it's so good!
@r1ch007cs123
@r1ch007cs123 2 года назад
Great explanation of the linked list.
@vakameli
@vakameli 6 лет назад
Thank you ! Very nice explanation !
@suryadevarakarthik1814
@suryadevarakarthik1814 3 года назад
Amazing explanation 👨‍🔬
@mergatafa8501
@mergatafa8501 7 лет назад
The best lecture I have ever listened
@mjohnson510
@mjohnson510 7 лет назад
seriously! This is the best one I've seen. She's hella good
@damilola_adegunwa
@damilola_adegunwa 2 года назад
thanks for this. I'm trying to find problems that would fit LinkedList best
@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
@colinbecko
@colinbecko 6 лет назад
Very understandable, thank you! Subscribed!
@simiiv5021
@simiiv5021 3 месяца назад
You made it so easy!!!
@koshykoshy9276
@koshykoshy9276 6 лет назад
Thank you
@osmanmusse9432
@osmanmusse9432 2 года назад
Great Explanation
@johnnyniklasson2956
@johnnyniklasson2956 2 года назад
Loved it! thanks
@PholoshoSeloane
@PholoshoSeloane 3 года назад
you are theeeeeee best.. I love this
@asivaprasadam
@asivaprasadam 3 года назад
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
@SamvitAgarwal
@SamvitAgarwal 5 лет назад
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 5 лет назад
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.
@CarlitoProductions
@CarlitoProductions 5 лет назад
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?
@vivekvitthalraopatil2775
@vivekvitthalraopatil2775 5 лет назад
you are fired
@praveencbharadwaj
@praveencbharadwaj 3 года назад
Thank you.Salute
@abhishekbedi1432
@abhishekbedi1432 6 лет назад
Awesome Video! Can you please include insert at position also.
@huycao8521
@huycao8521 3 года назад
thank you for the video.
@gabrielpereiramendes3463
@gabrielpereiramendes3463 5 лет назад
Good Lesson!!!
@SumitChandorkar
@SumitChandorkar 7 лет назад
Good Explanation, i understood well
@drdunkan15
@drdunkan15 7 лет назад
Sumit Chandorkar Do you know what happens during the Node next; part of the code?
@shaikmasthan8254
@shaikmasthan8254 4 года назад
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 ?
@abdelrhman110
@abdelrhman110 6 лет назад
My God, that keyboard click sound is erotic. What keyboard is that?
@shadowalkzx
@shadowalkzx 6 лет назад
iMac keyboard
@masteryoda3679
@masteryoda3679 6 лет назад
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 лет назад
Get yourself a mechanical keyboard and the sound of this keyboard will make you cringe.
@megamanx2006
@megamanx2006 6 лет назад
Abd-Elrhman Rizk dude, if sounds like that are your thing, search ASRM audio or something like that...
@mirknankazmzad8517
@mirknankazmzad8517 6 лет назад
omg thanks, i searched and i'm listening to it like 1 hour or something. this is great. like braingasm
@FBGZ
@FBGZ 5 лет назад
in link lists can you have different types of data at the same time? such as intergers and strings at a same time
@paladin1147
@paladin1147 4 года назад
Put the return at the end so if you there are any duplicates in the (DeleteWithValue) it wont skip them over.
@notlun
@notlun 3 года назад
Fantastic
@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?
@-a5624
@-a5624 4 года назад
THANK YOU
@viditaagrawal4169
@viditaagrawal4169 2 года назад
Awesome!
@Xtremedave2
@Xtremedave2 5 лет назад
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.
@blyatman635
@blyatman635 5 лет назад
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) ?
@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
@malakdesouky9123
@malakdesouky9123 3 года назад
Which coding platform did you use? Thank you this was very helpful!
@Pulkit__7
@Pulkit__7 5 лет назад
Thanks
@vertigo6982
@vertigo6982 4 года назад
A good follow-up video to this one would be "Dangling Pointers"
@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.
@solomonrajkumar5537
@solomonrajkumar5537 6 лет назад
Thanks, Mam... very brilliantly explained!!!
@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..
@rvohra91
@rvohra91 7 лет назад
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.
@ebrahimmansour7606
@ebrahimmansour7606 3 года назад
totally agree with you :D
@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?
@captainutki01
@captainutki01 5 лет назад
We can't have two public classes in the same file though right?
@hichdima
@hichdima 4 года назад
thanks
@TimScratch
@TimScratch 5 лет назад
Would nesting the class node under linked list make a difference?
@miguelvalente2572
@miguelvalente2572 7 лет назад
Simple question about creating the LinkedListClass. In oracle when creating a class its needs to have the same name as the CLASS FILE name. So how to circunvent this problem.
@somerandomguy000
@somerandomguy000 3 года назад
Append is also constant if you keep a reference of your tail.
@veronika_franz
@veronika_franz 6 лет назад
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).
@entertainme151
@entertainme151 7 лет назад
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 7 лет назад
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 5 лет назад
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 5 лет назад
referenceless memory which is left undeleted in c++ causes memory leak..
@isfisfisf
@isfisfisf 5 лет назад
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...
@GurdeepSabarwal
@GurdeepSabarwal 5 лет назад
linked list implementation at 1:59
Далее
Learn Linked Lists in 13 minutes 🔗
13:24
Просмотров 264 тыс.
Why You Should AVOID Linked Lists
14:12
Просмотров 271 тыс.
skibidi toilet 76 (part 1)
03:10
Просмотров 12 млн
Все кругом Миланы... 🤣
00:12
Просмотров 235 тыс.
Data Structures: Heaps
10:32
Просмотров 1,2 млн
Algorithms: Memoization and Dynamic Programming
11:17
Просмотров 963 тыс.
Data Structures: Trees
9:57
Просмотров 998 тыс.
Linked Lists - Computerphile
10:11
Просмотров 203 тыс.
Так ли Хорош Founders Edition RTX 4080 ?
13:00
Сложная распаковка iPhone 15
1:01
Просмотров 14 тыс.
S-Pen в Samsung достоин Золота #Shorts
0:38