Download presentation
Presentation is loading. Please wait.
1
DATA STRUCTURES IN PYTHON
By : Mrs Sangeeta M Chauhan , Gwalior by Sangeeta M Chauhan By: Sangeeta M Chauhan
2
Data Structure As the name shows It represents how data is stored/organized in Computer’s Memory .
Implementation of Data Structures can be done in two ways. Simple Data Structures : Built from primitive data types (integers, real, charater, BooleanExample: Arrays or Linear List Compound Data Structures: Simple Data structures are used to form more complex data structure. They are classified into two types Linear: means elements are stored in sequential order Example: Stack, Queue, Linked List Non Linear : Data can be stored as multilevel Structure Example Trees , Graphs by Sangeeta M Chauhan
3
Introduction of Stack Items stored in the order same as Stack Order (Last In First Out also called LIFO) means item stored one above another and when we want to remove any element from the Stack, as it is picked from the Top of the Stack i.e. the item that is added at last will remove first. by Sangeeta M Chauhan
4
Have a look on different types of Stack in the real World
Stack of pebbles Stack of Chapati/Roti Stack of Coins by Sangeeta M Chauhan
5
There are mainly Two types of Operations that can be done with Stack
push and pop. Push: Insertion of an element on top of the stack is called Push Pop: Removal an element from the top of the stack is called POP Push and Pop Operations are done from single end called TOP by Sangeeta M Chauhan
6
24 56 4 9 2 Let’s understand it with an Example
Suppose we have a list of items which is to be inserted in the Stack of Size 5 24 56 4 9 2 by Sangeeta M Chauhan
7
Application of Stacks Expression Evaluation and Conversion
Stack is used to evaluate prefix, postfix and infix expressions. Stack can also be used to convert one form of expression to another. ii. Backtracking Suppose we are finding a path for solving a particular problem and we have chosen a path and after following it later we realize that we have chosen wrong path. Now we need to go back to the beginning of the path to start with new path. This can be done with the help of stack. iii.Recursion When a Function call itself this process is called recursion. In each recursive call, there is need to save the current values of parameters, local variables and the return address (the address where the control has to return from the call). Whenever a function calls to another function, first its arguments, then the return address and finally space for local variables is pushed onto the stack. iv. To Reverse String Stack is used to reverse a string. We push the characters of string one by one into stack and then pop character from stack. v. Function Call Stack is also used to keep all information about the active functions or subroutines. by Sangeeta M Chauhan
8
Introduction of Queue Items stored in the order same as Queue (Fast In First Out also called FIFO) means item stored one after another and the when we want to remove an item from the Queue the Item inserted first will remove first . As if waiting in a queue for the train tickets, the first one to stand in line is the first one to buy a ticket and get the reservation. by Sangeeta M Chauhan
9
Queue is just like as queue in
Queue examples Queue is just like as queue in Cinema Hall Railway Booking Counter In Bank Counter etc. by Sangeeta M Chauhan
10
Application of Queue Queue, as the name suggests is used whenever we need to manage any group of tasks/objects in an First Come First Serve order for Example: Serving multiple requests on a single shared resource, like a printer, CPU task scheduling etc. Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive i.e First come first served. In real life scenario, Call Center phone systems uses Queues to hold the calls of people , in an order, until a service representative is free. by Sangeeta M Chauhan
11
Insertion is done in the Queue from REAR end and Deletion Operations are done from FRONT end.
In Queue there are mainly two types of operations Insertion : Insertion of an element is done at REAR end, Insertion operation is also called ENQUEUE and Deletion: Deletion of an element is done at FRONT end, Deletion operation is also called DEQUEUE by Sangeeta M Chauhan
12
Lets Understand through an Example.
Suppose we have a list of items which is to be inserted in the Queue of Size 5 24 56 4 9 2 by Sangeeta M Chauhan
13
Some functions of list that are required to implement stacks/queues
Python List .append() Add Single Element to The List Python List .pop(index) Removes Element at Given Index Python List .pop() Removes last element by Sangeeta M Chauhan
14
PRACTICAL IMPLEMENTATION OF STACK
by Sangeeta M Chauhan
15
www.pythonclassroomdiary.wordpress.com by Sangeeta M Chauhan
16
PRACTICAL IMPLEMENTATION OF QUEUE
by Sangeeta M Chauhan
17
www.pythonclassroomdiary.wordpress.com by Sangeeta M Chauhan
18
Stack using class by Sangeeta M Chauhan
19
QUEUE using class by Sangeeta M Chauhan
20
www.pythonclassroomdiary.wordpress.com by Sangeeta M Chauhan
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.