Data Structures: Stacks and Queues

  Рет қаралды 570,072

HackerRank

HackerRank

Күн бұрын

Пікірлер: 152
@enjoyinglife9853
@enjoyinglife9853 3 жыл бұрын
You explained this better in 5 mins, than my professor could in 2 hours! Thank you so much!
@abdulmohibabdulrahman6924
@abdulmohibabdulrahman6924 2 жыл бұрын
Legend 🙄🙄
@argonred
@argonred 2 жыл бұрын
So very true
@mutatednut
@mutatednut 2 жыл бұрын
Better than my professor could in 3 weeks
@drzlilj
@drzlilj 2 жыл бұрын
Better than my professor could in 2 semesters
@tannerbarcelos6880
@tannerbarcelos6880 5 жыл бұрын
It is funny when you get a pretty good foundation in your intro to comp sci courses how easily it is to understand these data structures. Then again, Gayle is an amazing teacher! Not a luxury we all get with college, lol.
@tan8067
@tan8067 5 жыл бұрын
Thank you very much ma'am. Stacks and Queue's have been stressing me out for the longest, but now I have actually taken the time to sit down and understand them and they are actually fairly simple, at the mention of pointers, I used to tremble, but now I realise that I have got nothing to fear at all!
@Digger-Nick
@Digger-Nick 4 жыл бұрын
7 months late, but a stack and a queue are the most basic concepts to understand...
@tan8067
@tan8067 4 жыл бұрын
@@Digger-Nick I agree. On paper, they're VERY easy to understand. I just had trouble implementing them when it came to actual problems.
@hilapartuk6769
@hilapartuk6769 5 жыл бұрын
Greate video! One suggestion - When implementing a Stack, it makes more sense to call the Node's pointer "prev" than "next", because logically it doesn't point to the one that comes after him :)
@laurafigueroa9922
@laurafigueroa9922 4 жыл бұрын
true, I called mine 'down' :)
@vaibhavyadav-patil3695
@vaibhavyadav-patil3695 4 жыл бұрын
'down' makes much more sense.
@laurafigueroa9922
@laurafigueroa9922 4 жыл бұрын
@@vaibhavyadav-patil3695 yea! Tho I was told it wasn't best practice 🤦‍♀️
@vaibhavyadav-patil3695
@vaibhavyadav-patil3695 4 жыл бұрын
@@laurafigueroa9922 why & who told you that?
@hilapartuk6769
@hilapartuk6769 4 жыл бұрын
@@vaibhavyadav-patil3695 you're right, but Gayle used the word prev in her other videos (I think it was LinkedList, not sure)... so just to be consistent with her other tutorials :)
@najeebiBrahvi
@najeebiBrahvi 3 ай бұрын
Very Very simply explained. It is better than the Course which I bought from Apna College!
@martinmtandi335
@martinmtandi335 8 жыл бұрын
awesome vid. you are the first person who has really explained the coding of this algorithm in a manner i actually understood.
@dragonore2009
@dragonore2009 7 жыл бұрын
At the university you do as the video is depicting. At least from C++ a person can just easily use the built Queue and Stack library, but you learn nothing. At the university they show you how a Stack and Queue work, like the video and then you implement it. You are not allowed to use any STL libraries. I learned alot, when I was restricted from using STLs and I would recommend everyone make a program that can easily be done with STL libraries, but to not use them, this forces you to understand programming better.
@dragonore2009
@dragonore2009 7 жыл бұрын
Obviously I don't mean production code, but for someone who is learning.
@johnsena0007
@johnsena0007 6 жыл бұрын
You're really have a point!
@geekyprogrammer4831
@geekyprogrammer4831 6 жыл бұрын
@@dragonore2009 you are right!
@vela7447
@vela7447 5 жыл бұрын
Huh, at my uni we used nodes for linked lists and trees, but python lists for stacks/queues... This was a far better explanation.
@xynyde0
@xynyde0 4 жыл бұрын
@@vela7447 python lists implementations are similar to dynamic array implimentations. Where as in this video stacks and queues are the implementations of linked lists.
@CSEconceptswithParinita
@CSEconceptswithParinita 5 жыл бұрын
Thank you so much ma'am! You're an inspiration for new tutors like me🙏💙💙💙
@silvershocknicktail6638
@silvershocknicktail6638 7 жыл бұрын
I see so many tutorials for coding using this same doodling/animation software, but I don't recognise it. What is it?
@procrastinator0357
@procrastinator0357 4 жыл бұрын
Although I understand what stack is and how to implement, I’m struggling to see when I can use stack, like in which “actual programming” situations.
@kulsumkhansla4101
@kulsumkhansla4101 4 жыл бұрын
I think we can use in when we want to check some kind of grammar or syntax, usually in the case of a compiler( lexer and parser)
@amadmlinka4812
@amadmlinka4812 4 жыл бұрын
It is also useful for implementing a post-fix notation system, if you want some user inputed data to be calculated.
@fahimhassan9024
@fahimhassan9024 4 жыл бұрын
This is my question too lol. I understand the implementation I guess, but I have no idea where this might be required :3
@Digger-Nick
@Digger-Nick 4 жыл бұрын
@@fahimhassan9024 It's not as important or difficult as these people make it out to be.
@Edsiaren
@Edsiaren 4 жыл бұрын
I had to use it on a calculator app that converted infix (1+2*3) to postfix(2 3 * 1 +) before calculating the problem. Converting to postfix helped a lot with nested problems (i.e. 1+2(3*4(1(3-2)))-4*3(1)) for me. I'm sure there's a work around without having to convert it to postfix, but finding a way to dig inside that parentheses and making sure those problems are solved in order was pretty troublesome. Look up postfix conversion or "Reverse Polish Notation" (RPN) on youtube, one of the videos show how a stack is used to determine what problems are going to get solved first.
@frankchen3021
@frankchen3021 3 жыл бұрын
Your videos are always so straight-foward!
@YoniFraimorice
@YoniFraimorice 8 жыл бұрын
Node class in 4:20 has a private constructor ,why's that? the class Node is private, that's fine since we're only using it and exposing it to our solution class, however creating the c'tor of the Node class as private won't allow us to instantiate it (only from within the Node class)
@martinmtandi335
@martinmtandi335 8 жыл бұрын
got the same qstn too
@pascal3889
@pascal3889 7 жыл бұрын
The outer class can access the private methods and fields of the inner class.
@gurukarthi
@gurukarthi 7 жыл бұрын
Since, We are supposed to create object for the class Stack/Queue not for the class Node. Because the class Stack/Queue will take care of creating the object for the class Node. Moreover, The class Node is created to make use of data organization inside the Stack/Queue not from outside!..peace!
@mohdbilal6561
@mohdbilal6561 2 жыл бұрын
very well understood.Thanks mam from India 🇮🇳
@luiscarlosquesadasequeira1548
@luiscarlosquesadasequeira1548 3 жыл бұрын
Can anyone explain at 3:33, in the remove method, why the tail need to be set to null after updating/removing the head? L36.
@CaveDave
@CaveDave 4 жыл бұрын
This is very confusing, it would have been much more simple to follow along if you would have kept your "line of people" analogy from the beginning 1:00 where the "tail" is on the left side making more sense because new people (nodes) will enqueue on the left side to represent an growing queue. Now you have mixed it all up: 2:40 . You add a new node but put it on the right side and make it part of the tail.
@rumelia
@rumelia 7 жыл бұрын
This series of Data Structures is great! Succinct, clear, and to the point. I only wished they used C++ since I got a final of it coming up :D
@englotv
@englotv 6 жыл бұрын
this is true coding. you helped me understanding sta cks
@danielabengona5142
@danielabengona5142 4 жыл бұрын
Where do you think it would be applicable to use them in some certain programs?
@kataya5005
@kataya5005 5 жыл бұрын
does it make sense that node is a static class, since we're making instances of the node with different data ?
@mohamedalifrani5416
@mohamedalifrani5416 5 жыл бұрын
Interesting implementation. But "top-level static classes" don't exist in Java! So the Queue class must just be a public class. In other cases if you need a "top-level static class" you can declare it as "public final", make its constructor "private" and its members as "static".
@somerandomguy000
@somerandomguy000 3 жыл бұрын
that happens when you’re just reading your teleprompter without actually knowing the thing
@deli5777
@deli5777 3 жыл бұрын
Thanks for this, you made the code seem so much simpler
@theSeniorSDE
@theSeniorSDE 3 жыл бұрын
Thanks for these easy videos to undertand.
@Eric-xh9ee
@Eric-xh9ee 2 жыл бұрын
This is by far the best explanation I've seen! PS why didn't you delete the node you popped, in the stack? I thought you always delete nodes you add otherwise you'll run out of memory
@DopetheKid
@DopetheKid 2 жыл бұрын
because technically it is deleted. nothing is pointing to it anymore so its garbage collected.. when using an array, that is when you should delete because array takes up a block of memory at a time.
@凛-r3h
@凛-r3h 4 жыл бұрын
Stacks and queue are pretty easy to remember their meaning. Its the same as the english meaning of stacking and queue!
@robertbonham6621
@robertbonham6621 4 жыл бұрын
Currently working on a class project where we can choose to either do stack or queue, which one would be better implement/ use. Stacks or Queues?
@ngndnd
@ngndnd Жыл бұрын
for the pop method in stack, it is removing the element that i added first, not the one that i added last. Or maybe im just getting confused bc of the way its actually implemented in code, idk
@hasansakib3502
@hasansakib3502 7 жыл бұрын
Sometimes i wonder how many subscribers did you get after these wonderful lectures??
@loummad9552
@loummad9552 2 жыл бұрын
I dont understand this line plz (@3:37) if head == null ===> tail == null;
@denver832
@denver832 4 жыл бұрын
Is 2:33 's code executable i think its not.
@joyalmeida6565
@joyalmeida6565 6 жыл бұрын
can you suggest me a title for a project which uses data structure in c. I need a project which uses link list/ stack / queues
@piero9665
@piero9665 7 жыл бұрын
Good explanation!!! thanks Gayle
@dennisrufi143
@dennisrufi143 6 жыл бұрын
Hello, Very well explained but I am confused with remove method. How is it actually removing a particular node in Queue?
@sonnix31
@sonnix31 6 жыл бұрын
Lol, well explained, but you are confused? Watch Durga Sir and you'll understand.
@growingprogrammer6593
@growingprogrammer6593 5 жыл бұрын
She actually just removes any reference to it. This means that the Garbage Collector, speaking in terms of JavaEnv, will delete it because it is a data without references.
@xynyde0
@xynyde0 2 жыл бұрын
in garbage collected languages like java and python, when an object has no references or is 'unreachable', it is deleted by the garbage collector. But if you are writing the same data structures in languages like C++, you will have to manage memory by yourself. Which means, you will allocate and deallocate memory for any objects you create.
@jamesyoo67
@jamesyoo67 5 жыл бұрын
Question for Stack.Pop(). Why do we not destroy the old Top object and set it to null, after setting the new Top?
@jamesyoo67
@jamesyoo67 5 жыл бұрын
Edit: looking at StackOverflow, in Java and C# it is worth it to null out the reference after popping it.
@BrandonAB
@BrandonAB 4 жыл бұрын
When the camp counselor tells everyone to line up at the flag pole and then when everyone does, he says to turn around, that’s LCFS.
@shibinfrancis9826
@shibinfrancis9826 6 жыл бұрын
How did you add first tail? If(head == null){ head = node; tail ?}
@anjani0agrawal
@anjani0agrawal 5 жыл бұрын
For Queue, add. If head is null shouldn't head and tail both be assigned to Node?
@DONofC0D
@DONofC0D 5 жыл бұрын
That is what she's done there. In the add method she will always set the tail to the node. And if head is null, she has also set head to the node. This means head and tail points to the same node
@feifeiliu276
@feifeiliu276 2 жыл бұрын
Thanks! So easy to understand.
@sakshamp4488
@sakshamp4488 3 жыл бұрын
Nice explanation. 🤩
@Kuriocity
@Kuriocity 6 жыл бұрын
*I dont understand the tail node object why you are overwriting it in the add method???*
@pablocs12
@pablocs12 6 жыл бұрын
Is not overwriting it, at that point of the code (line 24) the "tail" object is still an instance of to the penultimate node (the 3th in the graph), what is doing there is switching the reference of its next node to the new tail. So the "next" node of 3th one ,is now the 4th node. I hope I've made myself understood.
@abtest5053
@abtest5053 2 жыл бұрын
Is it necessary to put Node class inside stack class?
@uyarahmet
@uyarahmet 4 жыл бұрын
Sound of the keys, OMG :D
@sundarb6673
@sundarb6673 5 жыл бұрын
Thank you, Gayle!
@DopetheKid
@DopetheKid 2 жыл бұрын
i dont really understand the if(head == null){ tail == null; } line in remove() of the queue. can someone explain?
@mustafak9565
@mustafak9565 7 жыл бұрын
in the add method of quene, cant we just let tail.next= node without the if(tail!=null) check?
@scpancakes
@scpancakes 7 жыл бұрын
It really depends on your compiler and a number of other factors, but when you try to access data members from a null pointer you will experience "undefined" behavior. In other words, you may be trying to access data from an object that does not exist! In my case it always ends in a segmentation fault. It's always best to avoid code that results in unexpected behavior. Note: coming from c++ but I imagine its much the same
@XxGummib3arxX
@XxGummib3arxX 7 жыл бұрын
Yes, you can do something like this public void add(char c) { if (head==null) { Node newNode=new Node(c); head=newNode; tail=newNode; } else { Node newNode=new Node(c); tail.next=newNode; tail=newNode; } }
@abdulrashid1060
@abdulrashid1060 5 жыл бұрын
At 3:17 you said "Remove from head of linked list" :)
@thewatcherlollol
@thewatcherlollol 4 жыл бұрын
Well, most of these Data Structures are implemented using Linked Lists.
@baljeetsingh5813
@baljeetsingh5813 5 жыл бұрын
which ide you were using?
@danielabengona5142
@danielabengona5142 4 жыл бұрын
Why do you think it is appropriate in some certain programs?
@aishikbhattacharya4296
@aishikbhattacharya4296 3 жыл бұрын
Why cant we use a different class for Node as we did for linkedlist
@Beziu1
@Beziu1 6 жыл бұрын
why remove method returns data instead of void ?
@Lea7herFace
@Lea7herFace 6 жыл бұрын
it should be called dequeue
@TheMediocreDev
@TheMediocreDev 6 жыл бұрын
It's actually changing the data (setting the tail to null) instead of just manipulating the pointers. Basically, need to return method with .data but not just .next()
@_danzo7
@_danzo7 6 жыл бұрын
because its have to return the value that had been removed like when u r in a real queue and u r an integer when its ur turn they cant just say next and ignore u
@mukulsaini1659
@mukulsaini1659 3 жыл бұрын
what would be the time complexity of this?
@williamplay1000
@williamplay1000 6 жыл бұрын
Why are the nodes static?
@kyy6150
@kyy6150 6 жыл бұрын
why do you need "Next" and "Tail" reference variables, why cant you just use "Next" as the tail instead of having 2 reference variable referring to the same object.
@MinecraftLetstime
@MinecraftLetstime 6 жыл бұрын
Then you have to traverse the queue to insert an element to the tail.
@growingprogrammer6593
@growingprogrammer6593 5 жыл бұрын
This way you can avoid going through the queue to insert an element (because you already have the tail!)
@hmak5423
@hmak5423 5 жыл бұрын
Amazing. Just amazing. Btw, I clicked because I thought Charlize Theron is the teacher.
@cenkercanbulut3069
@cenkercanbulut3069 6 жыл бұрын
Well explained, Subbed!.
@moviefanie
@moviefanie 4 жыл бұрын
Nothing wrong with this video. I found in some interviews, for Queue people especially look for enqueue and dequeue methods instead of remove and add.
@thadtayo
@thadtayo 7 жыл бұрын
Why does she create a Stack class and Queue class? Are these data structures not built into Java?
@revdevstudios
@revdevstudios 7 жыл бұрын
they are but she teaches you the implementation and how these data structures work.
@XxGummib3arxX
@XxGummib3arxX 7 жыл бұрын
They are are in the Java api, but the point of the video is to show you how they could possibly be implemented and how it works internally. In her case using a linked list. What if you went to a job interview and they asked you to implement a queue? You would probably fail in that case.
@joecamroberon9322
@joecamroberon9322 5 жыл бұрын
Because the video would be 30 seconds long is she did that.
@736939
@736939 8 жыл бұрын
I though that it's null when head==tail on 2:13
@zentes08
@zentes08 8 жыл бұрын
Not necessary. If we have 1 element in the queue, head==tail is true.
@yoitslemonboy6988
@yoitslemonboy6988 5 жыл бұрын
can we please get the source?
@syedmuqeet
@syedmuqeet 5 жыл бұрын
I got confused with stack push pop operation
@mergatafa8501
@mergatafa8501 7 жыл бұрын
excellent lecture
@shoban2090
@shoban2090 7 жыл бұрын
Why do we keep 'Node' as a inner class?
@officialsterlingarcher
@officialsterlingarcher 5 жыл бұрын
so that it can't be accessed outside of the queue or stack class. It doesn't make much sense on why we don't want to access it outside of this class in this scenario. But say that you're building an algorithms library for other programmers to use and you add these data structures to it. You don't want those other programmers to accidentally access the node class and start messing around with raw data without having to go through the helper functions in the outer class. That would defeat the whole purpose of the data structure you're making.
@jamesyoo67
@jamesyoo67 5 жыл бұрын
@@officialsterlingarcher In her sample code, I can't manipulate her Stack's data because A) Top is a private member of Stack, and B) data is a private member of Node, both with no public setters or getters. Defining a private Node class within a Queue class means, outside the Queue class, I cannot freely create and use Node objects on my own.
@ms.r1611
@ms.r1611 3 жыл бұрын
Wow I didn't know the face behind the book: Cracking the coding interview.
@greerhanshaw
@greerhanshaw 8 жыл бұрын
At the risk of being tedious, can someone explain: is a stack/queue a data structure (as described here), an abstract data type (as described on Wikipedia) or both?
@GuardianTam
@GuardianTam 7 жыл бұрын
It's both. it's an abstract data type when you're talking about how it behaves. it becomes a data structure when you actually implement it, since there are many different ways to do so.
@jacksonjoestar5035
@jacksonjoestar5035 7 жыл бұрын
A stack can be an abstract data structure, remember that an abstract data structure is A class where not all methods are initialized.
@nafeesahmed4942
@nafeesahmed4942 7 жыл бұрын
How i can use this editor for practice ?
@anjaligoyal1754
@anjaligoyal1754 7 жыл бұрын
hackerrank.com
@victor3btn598
@victor3btn598 2 жыл бұрын
Why is stack like a linked list
@hao5868
@hao5868 5 жыл бұрын
Which IDE was used in this tutorial? Thanks!
@growingprogrammer6593
@growingprogrammer6593 5 жыл бұрын
It is the default code section used in HackerRank
@Ibrah_id
@Ibrah_id 6 жыл бұрын
Very clear and informative ❤️
@jamesperez6964
@jamesperez6964 8 жыл бұрын
What is the deal of the dot operator being used with the 'this' pointer? this.data = data; instead of, this->data = data; ???
@HafisCZ
@HafisCZ 8 жыл бұрын
Because it's Java, not C++. In Java operator - > is for lambda. In C++ 'a.x' returns member x of the object a, and 'a->x' is short for (*a) .b (returning member of object's pointer). It's explained there better: stackoverflow.com/questions/4984600/when-do-i-use-a-dot-arrow-or-double-colon-to-refer-to-members-of-a-class-in-c
@averagehooligan620
@averagehooligan620 2 жыл бұрын
So helpful! thx
@NinjaTuna9
@NinjaTuna9 4 жыл бұрын
A stack is just a singly-linked list??? WTFFFF
@jx_cob5988
@jx_cob5988 4 жыл бұрын
True, it really just defines how items are removed and added to it. There is some other stuff if you go deeper however.
@danielbreen3945
@danielbreen3945 6 жыл бұрын
_intentionally keeps her own book at the bottom of her "stack" to show humility_
@M4th3u54ndr4d3
@M4th3u54ndr4d3 4 жыл бұрын
@@charlesj9106 lol
@Jemmeh
@Jemmeh 6 жыл бұрын
Thank you for the video. I suggest using a pop filter with the microphone next time though, there's a lot of little pops in the audio and it's distracting.
@MosesHashim3
@MosesHashim3 5 жыл бұрын
the idea of stack and queue is simple, but everyone has a different way to code it. I could not follow you and read what you were coding.
@Tux0xFF
@Tux0xFF 4 жыл бұрын
a static class that contains another inner class, i need to re learn java
@whitebird365
@whitebird365 5 жыл бұрын
Thank you!
@jl-dq5ch
@jl-dq5ch 5 жыл бұрын
waiting an hour or two for a movie?!
@collegestudent6071
@collegestudent6071 4 жыл бұрын
Why don't these tutorials specify the language...
@charleskenney3574
@charleskenney3574 7 жыл бұрын
Wow thats good schema
@benzeltser9851
@benzeltser9851 4 жыл бұрын
why did it take my teacher 3 hours to teach at, and not as good as this video tbh.
@tedyhy24
@tedyhy24 6 жыл бұрын
It's great!
@AshokAshok-ig9jk
@AshokAshok-ig9jk 5 жыл бұрын
Super
@brd8764
@brd8764 4 жыл бұрын
FILO and LIFO.
@skylarkim22
@skylarkim22 6 жыл бұрын
thanks!
@0xssff
@0xssff 3 жыл бұрын
but why Java (eww) tho?
@fatimaaw
@fatimaaw Жыл бұрын
thank u!
@RogerKeulen
@RogerKeulen 8 жыл бұрын
Wrong, Fake news: The _head_ is the first element. The rest is the _tail_. ;-)
@adamsadam366
@adamsadam366 8 жыл бұрын
nice! =)
@duncanphillipgreen
@duncanphillipgreen 6 жыл бұрын
Hm, I don't think this will even compile!
@KwabenaAning
@KwabenaAning 6 жыл бұрын
Yeah...
@rasam.priyan
@rasam.priyan 2 жыл бұрын
I feel sad ... Just because she used Java to teach stacks and queues...
@sim1manson1
@sim1manson1 3 жыл бұрын
FAKE QUEUES!!!
@fernandoluis53
@fernandoluis53 6 жыл бұрын
You did not talk about big-o at all. very unprofessional
@KelleyKouture
@KelleyKouture 5 жыл бұрын
she has a whole video on big-o. This video was about stacks/queues and it was very well done
Data Structures: Trees
9:57
HackerRank
Рет қаралды 1 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Top 7 Data Structures for Interviews Explained SIMPLY
13:02
Codebagel
Рет қаралды 248 М.
Data Structures: Hash Tables
6:25
HackerRank
Рет қаралды 1,5 МЛН
Queue - Data Structures in Python #3
16:19
NeuralNine
Рет қаралды 2,9 М.
Data Structures: Heaps
10:32
HackerRank
Рет қаралды 1,3 МЛН
Stacks and Queues (Python) - Data Structures and Algorithms
14:10
Stack Data Structure In STL | C++ Tutorial
16:59
Portfolio Courses
Рет қаралды 19 М.
Data Structures: Cycles in a Linked List
5:19
HackerRank
Рет қаралды 167 М.
Learn Queue data structures in 10 minutes 🎟️
10:07
Bro Code
Рет қаралды 142 М.
Stacks & Queues - DSA Course in Python Lecture 5
14:58
Greg Hogg
Рет қаралды 16 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 685 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.