Dataa Structures Cs
Dataa Structures Cs
syllabus
2020-21
Chapter 7
Data-structures:
lists,stack,queue
Computer Science
Class XII ( As per CBSE Board)
Visit : python.mykvs.in for regular updates
Data-structures
It a way of organizing and storing data in such a manner so that it can be accessed
and work over it can be done efficiently and less resources are required. It define the
relationship between the data and the operations over those data. There are many
various types of data structures defined that make it easier for the computer
programmer,to concentrate on the main problems rather than getting lost in the
details of data description and access.
Python Data Structure
List
It is a collections of items and each item has its own index value.
Index of first item is 0 and the last item is n-1.Here n is number of items in a list.
Indexing of list
Creating a list
Lists are enclosed in square brackets [ ] and each item is separated by a comma.
e.g.
list1 = [‘English', ‘Hindi', 1997, 2000];
list2 = [11, 22, 33, 44, 55 ];
list3 = ["a", "b", "c", "d"];
Visit : python.mykvs.in for regular updates
Data-structures
list =[3,5,9]
for i in range(0, len(list)):
print(list[i])
Output
3
5
9
Visit : python.mykvs.in for regular updates
Data-structures
Stack:
A stack is a linear data structure in which all the insertion and
deletion of data / values are done at one end only.
It is type of linear data structure.
It follows LIFO(Last In First Out)
property.
Insertion / Deletion in stack can
only be done from top.
Insertion in stack is also known as
a PUSH operation.
Deletion from stack is also known
as POP operation in stack.
Applications of Stack:
• Expression Evaluation: It is used to evaluate prefix, postfix and infix
expressions.
• Expression Conversion: It can be used to convert one form of
expression(prefix,postfix or infix) to one another.
• Syntax Parsing: Many compilers use a stack for parsing the syntax of
expressions.
• Backtracking: It can be used for back traversal of steps in a problem
solution.
• Parenthesis Checking: Stack is used to check the proper opening
and closing of parenthesis.
• String Reversal: It can be used to reverse a string.
• Function Call: Stack is used to keep information about the active
functions or subroutines.
Visit : python.mykvs.in for regular updates
Data-structures
stack = [5, 9, 3]
stack.append(7)
stack.append(11) OUTPUT
print(stack) [5, 9, 3, 7, 11]
print(stack.pop()) 11
print(stack) [5, 9, 3, 7]
print(stack.pop()) 7
print(stack) [5, 9, 3]
Queue:
Queue is a data structures that is based on First In First Out
(FIFO) stretagy ,i.e. the first element that is added to the queue
is the first one to be removed.
• Queue follows the FIFO (First - In -
First Out) structure.
• According to its FIFO structure,
element inserted first will also be
removed first.
• In a queue, one end is always used
to insert data (enqueue) and the
other is used to delete data
(dequeue), because queue is open
at both its ends.
Visit : python.mykvs.in for regular updates
Data-structures
Applications of Queue:
Synchronization : When data are transferred to asynch
devices then it is used to synchronized.
Scheduling : When a resource is shared among
multiple consumers.
Searching : Like breadth first search in graph theory.
Interrupt handling : Handling of multiple interrupt as
the order they arrive.