SlideShare ist ein Scribd-Unternehmen logo
1 von 36
PACKAGES &
DATASTRUCTURES in
PYTHON
1
By
B.Hemalatha
Assistant Professor
VEC
PACKAGES / LIBRARY
 In Computer we store files in organized hierarchies
 Subdirectories
 Files
 Large projects in Python are organized as Packages
which consists of many
 Sub-Packages
 Similar Modules
 Packages makes projects easy to manage and conceptually clear
2
PACKAGES / LIBRARY
 Python package is a directory containing
 Sub-packages
 Modules
 Along with an __init__.py file
Python module
 Is a . py file
 Contains functions, variables
3
double underscore
Mensuration
Square.py
Rectangle.py
Circle.py
Eg 1. PACKAGE
4
M
O
D
U
L
E
S
Directory
Package
• Game Development Package Organization
Eg 2.PACKAGES / LIBRARY
5
PACKAGE
list
SUBPACKAGES
M
O
D
U
L
E
S
• Steps to create a package
– Create a directory with the package name
– Create modules under it
– Create a file __init__.py in the directory
Note : File __init__.py is a simple file required to make python treat the
directory on the disk as packages of python
• Access packages and its modules
– from PACKAGE_NAME import MODULE_NAME
• Access functions in modules
– Use dot operator “ . ”
– MODULE_NAME . FUNCTION_NAME
PACKAGES / LIBRARY
6
PACKAGES / LIBRARY
mensuration
square.py rectangle.py
Modules/
Python Files
Directory /
Package
Example:
7
Step1 : Folder/Directory Creation:
Folder/directory named “mensuration”
creation
Step 2: Module Creation - I: “square.py”
# Square Module
def area(side):
return side * side
def peri(side):
return 4 * side
PACKAGES / LIBRARY
8
Step 2 : Module Creation - II: “ rectangle.py”
# Rectangle Module
def area(length,breadth):
return length*breadth
def peri(length,breadth):
return 2*(length+breadth)
Step 3 : file __init__.py Creation
PACKAGES / LIBRARY
9
To Access Packages and its Modules
from mensuration import square,rectangle
To Access functions inside the Modules
square . area (side)
rectangle . area (length,breadth)
PACKAGES / LIBRARY
10
#Rectangle Module
def area(length,breadth):
def peri(length,breadth):
# Square Module
def area(side):
def peri(side):
1. Package in Python is a
– (a) File
– (b) Database
– (c) hierarchical file directory
– (d) hierarchical database directory
»(Ans: c)
11
2. To include a package in python we use
– (a) include statement
– (b) import statement
– (c) package include statement
– (d) package import statement
»(Ans: b)
12
3. A Package contains
– (a) sub-packages
– (b) modules
– (c)__init__.py
– (d) All the above
»(Ans: d)
4. Python supports built in packages
– (a) Yes
– (b) No
»(Ans: a)
13
5. The package folder contains a special file
called__________
– (a) __init__.py,
– (b) Pack_.py
– (c)_pack_,py
– (d)_init_pack_.py
»(Ans: a)
14
INTRODUCTION TO
DATA STRUCTURES
15
Data structure
 way to store and organize data
 helps in writing efficient programs in any
language
Python is a high-level, interpreted, interactive
and object-oriented scripting language using
which we can study the fundamentals of data
structure in a simpler way as compared to
other programming languages.
Data structure in Python
16
Data structure in Python
17
Data Structures in Python
Built-in Data Structures User-Defined Data Structures
List
Tuple
Dictionary
Set
Stack
Queue
Tree
Graph
Linked
list
Today we will focus on few Data Structures
1.Stacks
2.Queues
3.Graph
Data structure in Python
18
Stack
Data structure - Stack
19
Stack
 is an ordered collection of items
 addition of new items
 removal of existing items
 this ordering principle is called Last-In First-Out(LIFO)
A Stack of Books A Stack of Primitive Python Objects
Data structure - Stack
20
always takes place at the same end
usually top
Data structure - Stack
21
Stack
Insertion
“PUSH”
Deletion
“POP”
Top
LIFO PRINCIPLE
Stack using LIST in Python
22
Stack LIFO PRINCIPLE
Stack using LIST in Python
Example:
# empty stack
stack = [ ]
# push operation # pop operation
23
OUTPUT
stack.append(10) stack =[10]
stack.append(20) stack =[10,20]
stack.append(30) stack =[10,20,30]
OUTPUT
stack.pop() stack =[10,20,30]
stack.pop() stack =[10,20]
top
top
top
top
top
Data structure - Queue
24
QUEUE
Queue
 is an ordered collection of items
 Addition of new items happens at one end, called the “rear,”
 Removal of existing items occurs at the other end, called the “front.”
 This ordering principle is sometimes called First-In First-Out (FIFO)
A Queue of Python Data Objects
Data structure - Queue
25
Insertion – Enqueue
Deletion - Dequeue
Data structure - Queue
26
QUEUE
Rear Front
FIFO PRINCIPLE
Queue using LIST in Python
Example:
# empty queue
queue = [ ]
# enqueue operation # dequeue operation
27
OUTPUT
queue.append(10) queue =[10]
queue.append(20) queue =[10,20]
queue.append(30) queue =[10,20,30]
OUTPUT
queue.pop(0) queue =[10,20,30]
queue.pop(0) queue =[20,30]
rear
rear
front
front
rear
QUEUE APPLICATIONS – SHARING PRINTER RESOURCE
Data structure - Queue
28
A
B
C
D
Job 1 Job 2
Job 3
Job 3 Job 2 Job 1
Printer queue
front
Data structure - Graph
Graph
Data is stored in a collection of vertices(nodes)
interconnected by edges (path)
29
Graph using DICTIONARY
Example:
# GRAPH structure
graph = { “a”:[“d”], “b”:[“c”],“c”:[“d”,”e”],
“d”: [“a”,”c”] ,”e”:[“c”]}
30
Application –
Undirected Graph
31
• Social Network – FACEBOOK
Suggest Friends
Application – Directed Graph
32
• World Wide Web
1. Consider the following operation performed on a stack
Push(1);
Pop();
Push(2);
Push(3);
Pop();
Push(4);
Pop();
After the completion of all operation, the number of elements
present in stack are
- (a) 1
- (b) 2
- (c) 3
- (d) 4
»(Ans: a)
33
2. A list of elements in which deletion can be
done from one end (front) and insertion can
take place only at the other end (rear) is known
as
- (a) Queue
- (b) Stack
- (c) Tree
- (d) Linked list
»(Ans: a)
34
3. Google Map is an application of
- (a) Tree
- (b) Stack
- (c) Graph
- (d) Queue
»(Ans: c)
35
Thank you
36

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Linked list
Linked listLinked list
Linked list
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Infix to postfix expression in ds
Infix to postfix expression in dsInfix to postfix expression in ds
Infix to postfix expression in ds
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
 
stack presentation
stack presentationstack presentation
stack presentation
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Queues
QueuesQueues
Queues
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
python Function
python Function python Function
python Function
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
Python Modules
Python ModulesPython Modules
Python Modules
 

Ähnlich wie Packages and Datastructures - Python

Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdfSoumyadityaDey
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and PackagesDamian T. Gordon
 
Wiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programmingWiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programmingAnalyticsConf
 
Revised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdfRevised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdfMohammadImran709594
 
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...Red Hat Developers
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using Ccpjcollege
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfExaminationSectionMR
 
CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)Rubén Izquierdo Beviá
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queueRajkiran Nadar
 

Ähnlich wie Packages and Datastructures - Python (20)

Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 
Python Session - 5
Python Session - 5Python Session - 5
Python Session - 5
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
 
Python libraries
Python librariesPython libraries
Python libraries
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Wiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programmingWiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programming
 
Revised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdfRevised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdf
 
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
 
4 gouping object
4 gouping object4 gouping object
4 gouping object
 
packages.pptx
packages.pptxpackages.pptx
packages.pptx
 
Chapter 7 ds
Chapter 7 dsChapter 7 ds
Chapter 7 ds
 
Queue
QueueQueue
Queue
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
Processing files sequentially in mule
Processing files sequentially in muleProcessing files sequentially in mule
Processing files sequentially in mule
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdf
 
CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 

Kürzlich hochgeladen

Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 

Kürzlich hochgeladen (20)

Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 

Packages and Datastructures - Python

  • 2. PACKAGES / LIBRARY  In Computer we store files in organized hierarchies  Subdirectories  Files  Large projects in Python are organized as Packages which consists of many  Sub-Packages  Similar Modules  Packages makes projects easy to manage and conceptually clear 2
  • 3. PACKAGES / LIBRARY  Python package is a directory containing  Sub-packages  Modules  Along with an __init__.py file Python module  Is a . py file  Contains functions, variables 3 double underscore
  • 5. • Game Development Package Organization Eg 2.PACKAGES / LIBRARY 5 PACKAGE list SUBPACKAGES M O D U L E S
  • 6. • Steps to create a package – Create a directory with the package name – Create modules under it – Create a file __init__.py in the directory Note : File __init__.py is a simple file required to make python treat the directory on the disk as packages of python • Access packages and its modules – from PACKAGE_NAME import MODULE_NAME • Access functions in modules – Use dot operator “ . ” – MODULE_NAME . FUNCTION_NAME PACKAGES / LIBRARY 6
  • 7. PACKAGES / LIBRARY mensuration square.py rectangle.py Modules/ Python Files Directory / Package Example: 7
  • 8. Step1 : Folder/Directory Creation: Folder/directory named “mensuration” creation Step 2: Module Creation - I: “square.py” # Square Module def area(side): return side * side def peri(side): return 4 * side PACKAGES / LIBRARY 8
  • 9. Step 2 : Module Creation - II: “ rectangle.py” # Rectangle Module def area(length,breadth): return length*breadth def peri(length,breadth): return 2*(length+breadth) Step 3 : file __init__.py Creation PACKAGES / LIBRARY 9
  • 10. To Access Packages and its Modules from mensuration import square,rectangle To Access functions inside the Modules square . area (side) rectangle . area (length,breadth) PACKAGES / LIBRARY 10 #Rectangle Module def area(length,breadth): def peri(length,breadth): # Square Module def area(side): def peri(side):
  • 11. 1. Package in Python is a – (a) File – (b) Database – (c) hierarchical file directory – (d) hierarchical database directory »(Ans: c) 11
  • 12. 2. To include a package in python we use – (a) include statement – (b) import statement – (c) package include statement – (d) package import statement »(Ans: b) 12
  • 13. 3. A Package contains – (a) sub-packages – (b) modules – (c)__init__.py – (d) All the above »(Ans: d) 4. Python supports built in packages – (a) Yes – (b) No »(Ans: a) 13
  • 14. 5. The package folder contains a special file called__________ – (a) __init__.py, – (b) Pack_.py – (c)_pack_,py – (d)_init_pack_.py »(Ans: a) 14
  • 16. Data structure  way to store and organize data  helps in writing efficient programs in any language Python is a high-level, interpreted, interactive and object-oriented scripting language using which we can study the fundamentals of data structure in a simpler way as compared to other programming languages. Data structure in Python 16
  • 17. Data structure in Python 17 Data Structures in Python Built-in Data Structures User-Defined Data Structures List Tuple Dictionary Set Stack Queue Tree Graph Linked list
  • 18. Today we will focus on few Data Structures 1.Stacks 2.Queues 3.Graph Data structure in Python 18
  • 20. Stack  is an ordered collection of items  addition of new items  removal of existing items  this ordering principle is called Last-In First-Out(LIFO) A Stack of Books A Stack of Primitive Python Objects Data structure - Stack 20 always takes place at the same end usually top
  • 21. Data structure - Stack 21 Stack Insertion “PUSH” Deletion “POP” Top LIFO PRINCIPLE
  • 22. Stack using LIST in Python 22 Stack LIFO PRINCIPLE
  • 23. Stack using LIST in Python Example: # empty stack stack = [ ] # push operation # pop operation 23 OUTPUT stack.append(10) stack =[10] stack.append(20) stack =[10,20] stack.append(30) stack =[10,20,30] OUTPUT stack.pop() stack =[10,20,30] stack.pop() stack =[10,20] top top top top top
  • 24. Data structure - Queue 24 QUEUE
  • 25. Queue  is an ordered collection of items  Addition of new items happens at one end, called the “rear,”  Removal of existing items occurs at the other end, called the “front.”  This ordering principle is sometimes called First-In First-Out (FIFO) A Queue of Python Data Objects Data structure - Queue 25
  • 26. Insertion – Enqueue Deletion - Dequeue Data structure - Queue 26 QUEUE Rear Front FIFO PRINCIPLE
  • 27. Queue using LIST in Python Example: # empty queue queue = [ ] # enqueue operation # dequeue operation 27 OUTPUT queue.append(10) queue =[10] queue.append(20) queue =[10,20] queue.append(30) queue =[10,20,30] OUTPUT queue.pop(0) queue =[10,20,30] queue.pop(0) queue =[20,30] rear rear front front rear
  • 28. QUEUE APPLICATIONS – SHARING PRINTER RESOURCE Data structure - Queue 28 A B C D Job 1 Job 2 Job 3 Job 3 Job 2 Job 1 Printer queue front
  • 29. Data structure - Graph Graph Data is stored in a collection of vertices(nodes) interconnected by edges (path) 29
  • 30. Graph using DICTIONARY Example: # GRAPH structure graph = { “a”:[“d”], “b”:[“c”],“c”:[“d”,”e”], “d”: [“a”,”c”] ,”e”:[“c”]} 30
  • 31. Application – Undirected Graph 31 • Social Network – FACEBOOK Suggest Friends
  • 32. Application – Directed Graph 32 • World Wide Web
  • 33. 1. Consider the following operation performed on a stack Push(1); Pop(); Push(2); Push(3); Pop(); Push(4); Pop(); After the completion of all operation, the number of elements present in stack are - (a) 1 - (b) 2 - (c) 3 - (d) 4 »(Ans: a) 33
  • 34. 2. A list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as - (a) Queue - (b) Stack - (c) Tree - (d) Linked list »(Ans: a) 34
  • 35. 3. Google Map is an application of - (a) Tree - (b) Stack - (c) Graph - (d) Queue »(Ans: c) 35