Data Structures in Python #2 | Using list as Stack | Python Programming Tutorial

Published: 26 April 2018
on channel: CodersArts
184
4

Welcome to the very first video tutorial of data structure in python,

In this video you will learn basic concept of stack and how to perform stack operations using List. So watch this video at the end because

you are about to learn one of the very basic and most useful data structure concepts.



Okay Let's get Started.

​​

In computer science, a stack is an abstract data type that serves as a collection of elements, with two principle operations:

push, which adds an element to the collection, and

pop, which removes the most recently added element.

​​

Stack is a linear data structure which follows a particular order in which the operations are performed. and i'm sure you have heard this popular  order of organizing data or item that   LIFO(Last In First Out) or FILO(First In Last Out).

​​

Stack is Considered as a linear data structure, or more abstractly a sequential collection, the push and pop operations occur only at one end of the stack, referred to as the top of the stack. A stack may be implemented to have a bounded capacity. If the stack is full and does not contain enough space to accept an entity to be pushed, the stack is then considered to be in an overflow state or stack overflow. The pop operation removes an item from the top of the stack.

​​

If you are already familiar with  other languages like C or C++,then you had noticed that implementation of stack might be took some sincere effort  (since you will have to keep track of pointers!) but not with Python. Python is so amazing that you can use lists to easily implement them.



When you hear the word Stack, the first thing that comes to your mind may be a stack of books,

A stack of plates in a cupboard,Undo/Redo operations in Excel or Word,Wearing/Removing Bangles etc.

In all these above examples you would have noticed that they all follow the same common operations like in the case of

a stack of book or plates we can add or remove item from topmost,

in the case of undo you can step back only last performed activity.