Class XI Computer Science Lesson 9 Stack Data Structure Session 2021-'22
Class XI Computer Science Lesson 9 Stack Data Structure Session 2021-'22
Class XI
Computer Science
Lesson 9
Stack Data Structure
Session 2021-‘22
Video Tutorial:
A data structure is a way of storing and organizing data in a computer so that it can be used
efficiently. It provides a means to manage large amounts of data efficiently. And efficient
data structures are key to designing efficient algorithms. Some examples of Data Structures
are arrays, Linked List, Stack, Queue, etc.
Efficiency: Efficiency of a program depends upon the choice of data structures. For example:
suppose, we have some data and we need to perform the search for a perticular record. In
that case, if we organize our data in an array, we will have to search sequentially element by
element. hence, using array may not be very efficient here. There are better data structures
which can make the search process efficient like ordered array or binary search tree.
Reusability: Data structures are reusable, i.e. once we have implemented a particular data
structure, we can use it at any other place.
Abstraction: Data structure is specified by the ADT which provides a level of abstraction.
The client program uses the data structure through interface only, without getting into the
implementation details.
Page 1 of 6
`
Class XI
Computer Science
Lesson 9
Stack Data Structure
Session 2021-‘22
• Traversing
• Insertion
• Deletion
• Searching
• Sorting
• Merging
Page 2 of 6
`
Class XI
Computer Science
Lesson 9
Stack Data Structure
Session 2021-‘22
Stack is a linear data structure predefined capacity. It is a simple data structure that allows
adding and removing elements in a particular order. Every time an element is added, it goes
on the top of the stack and the only element that can be removed is the element that is at
the top of the stack, just like a pile of objects.
Page 3 of 6
`
Class XI
Computer Science
Lesson 9
Stack Data Structure
Session 2021-‘22
Stack can be easily implemented using an Array or a Linked List. Arrays are quick, but are
limited in size and Linked List requires overhead to allocate, link, unlink, and deallocate, but
is not limited in size. Here we will implement Stack using array.
Page 4 of 6
`
Class XI
Computer Science
Lesson 9
Stack Data Structure
Session 2021-‘22
Below mentioned are the time complexities for various operations that can be performed
on the Stack data structure.
Push Operation : O(1)
Pop Operation : O(1)
The time complexities for push() and pop() functions are O(1) because we always have to
insert or remove the data from the top of the stack, which is a one step process.
Worksheet
Q1. WordPile is an entity which can hold maximum of 20 characters. The restriction is that a
character can be added or removed from one end only.Some of the members of the class
are given below:
Page 5 of 6
`
Class XI
Computer Science
Lesson 9
Stack Data Structure
Session 2021-‘22
Methods/Member functions:
WordPile(int cap): constructor to initialize the data member capacity = cap, top = -1 and
create the WordPile.
void pushChar(char v): adds the character to the top of WordPile if possible, otherwise
output a message “WordPile is full”
char popChar(): returns the deleted character from the top of the WordPile if possible,
otherwise it returns ‘\\’.
Specify the class WordPile giving the details of the constructor, void pushChar(char) and
char popChar(). The main function and algorithm need not be written.
Page 6 of 6