- 5 days ago
Transcript
00:00Hi everyone, in this class, we are going to learn the Stacks Data Structure.
00:03First, we will talk about what are the Stacks and what are the implementation of this class.
00:07And then we will solve the questions that we have asked from Microsoft, Amazon, Adobe like companies.
00:13Now, the implementation of this is also very important because they also ask the companies directly.
00:19So, let's start with Stacks.
00:21Here, you will see a book of books, which is kept in one way.
00:25We will see that the information in the book is very much more than the data.
00:31So, when the data is stored,
00:35we call it a book of Stacks.
00:40So, when we call it a Stacks Data Structure,
00:41we call it Stacks.
00:44We call it Stacks.
00:46We call it a Stacks.
00:48In the memory, we call it Implicit Stack.
00:54Implicit Stack, which the memory or computer or program has made itself,
00:58we need to make it.
00:59Here, the Stacks is our Explicit Stack.
01:04Explicit Stack, programmers, coders, we will make it themselves.
01:08So, when we have to make it explicit stack,
01:11when we make it,
01:12when we make it,
01:13such as recursion time,
01:15back-tracking,
01:15when we are learning back-tracking,
01:16when we are learning that time,
01:17this is the Implicit Stack.
01:19Now, we will see the stack in real life,
01:22we will see many times in real life,
01:23and ignore it.
01:25In English,
01:26there is a basic meaning that,
01:27when there is an object,
01:30there is an object,
01:31there is an object in English,
01:33it will make it in English,
01:34and the data structure of the stack,
01:36where the question is,
01:38it will inspire each other than the other word,
01:39in the future.
01:40Which means in real life,
01:41such as in the real life,
01:41which is 이것 inside one book,
01:44which is left by one book,
01:45and the case of that book,
01:46as we made it,
01:47the books,
01:48and the books,
01:49the books,
01:49the books about the book,
01:50the books,
01:51which are done by both books,
01:56or the books.
02:06of coins and stones. We also play a game of stones. We also play a game in which we
02:11play a piece of stones. We play a piece of stones in which we play a piece of stones.
02:19This is our real life stacks. When we play a piece of roti, we play a stack of rotis.
02:30This is our real life example. This is our real life example. We play a stack of our life
02:36and we play a lot of questions about the stacks. When we talk about stacks, we have three
02:46operations in our mind. This is our push operation, our pop operation and our peak operation.
02:53How do we play a stack in coding? This is already in recursion time.
02:57We play a stack again. Stack is a ball-tie structure, which we store in our data.
03:05First, we store 1, then store 2, then store 3. When we add the data to the ball-tie,
03:15we call it push operation. Push operation, which means we add a stack in our data.
03:22We can add one direction, which means the upper direction. Now, once we have pushed
03:28and the time complexity of this operation will always be a big of one, which means a single operation.
03:36After that, it is our pop operation. Pop operation, which means the upper elements
03:40will be a big of one. Now, the upper element is very special when we talk about stacks.
03:46The upper element is called top. The upper element is called top.
03:51The upper element is called top. The upper element. Now, the kids are from C++ background.
04:06The upper element is called top. Push, pop, peak.
04:19to be our top element will pop.
04:22The third is peak operation.
04:24Peak is going to go.
04:25When we go to the stack,
04:28we will see the top element of the stack.
04:32We will see the top of the stack.
04:33First, we will see these three.
04:37We will see these three operations,
04:38which are the base of the stack.
04:40The three operations of the time complexity
04:42is a single operation.
04:45It is a single operation.
04:46Because if we push
04:48to the top,
04:50we will push this data structure
04:52to last in,
04:53first out data structure,
04:55LIFO data structure.
04:57LIFO, why do we say that?
04:59Because the stack of the stack
05:00is in the last one,
05:02the first one will go.
05:04The last one is in the last one,
05:06and the last one is in the last one.
05:08This is the last in, first out,
05:11LIFO data structure.
05:12We will talk about stack implementation.
05:15We will talk about stack.
05:16First, we have many data structures.
05:18First, the first data structure was
05:21Arrays.
05:21Then, we have array list.
05:23Then, we have linked list.
05:25Then, we have linked list.
05:26These three data structures
05:27individually use,
05:28we can create a stack.
05:30After that, we can create a stack.
05:31When we create a stack,
05:33the code of implementation,
05:35Amazon, OYO,
05:36OYO,
05:36such companies have already asked.
05:38So, there are implementations
05:39too.
05:39So, we will start with arrays.
05:42Array's is the size fixed.
05:45Array's is the size fixed.
05:46Sometimes, it is good for it.
05:47Sometimes, it is good for it.
05:48Sometimes, it is good for it.
05:50In the case, it is negative.
05:53If we have array's help,
05:56then, it will always fix size.
05:58It will always fix size.
05:59It will always be n-size.
06:00We will add n-size.
06:03Now, we need to add more data.
06:04If we need to implement stack,
06:05then, we will add elements to array.
06:07With arrays, it will always be at the top.
06:11When we push it,
06:13we'll then push it on top.
06:14After we push it on top,
06:14we have to drop it on top.
06:16And we need to pick it on top.
06:17And then, if we pick it on top,
06:18we will pick the last index.
06:21After we get the array to stack,
06:23then we'll check out whether we need to make the stack full.
06:27If it's full then,
06:28the other elements can be not a full head.
06:30When array is fixed size,
06:31our stack will need an element for n elements.
06:33So, we don't prefer the array to stack.
06:34we don't prefer to create a list. Then, let's add our array list to our list.
06:39Array list is variable size, so here the problem is solved. Now, our link list is variable size,
06:45so here the problem is solved. So, we can use both a good stack.
06:51Array list is how to create a stack? We already know that the array list is an array
06:57which is an array, which is the size, which we can add one more.
07:02We can create an array in this way. This will be our top.
07:07But, the other elements are added and the other will be filled.
07:10Here we have 4, 5, 6 and top here.
07:13We will copy the array size and all of these elements.
07:22We will implement the array list.
07:26We will talk about the stack in the head.
07:29we already know that we have a lot of nodes in this area here
07:37here is node number one here is node number two here is node number three
07:41after one point and this is our head
07:47this is our top link list
07:53we know that we have a push and pop and peak
07:58and in the link list there is a head that we have a big of one
08:07if we have a head to delete then it is big of one
08:10if we have a head to change then it is big of one
08:12and the head of value then it is big of one
08:15so we have a head to satisfy our head
08:19so this is why our stack is top
08:20it will always be our head
08:23and this is the logic we have to apply
08:25when we are sitting in these companies
08:27and asked us to make a stack
08:30so these three data structures
08:33we have seen what is the most efficient
08:34we have to do our array list
08:36and link list
08:37now we have both code
08:39how can we make our stack
08:42and allow us to make our stack
08:42and object
08:42you can download the map