0% found this document useful (0 votes)
28 views13 pages

5615-1700040351707-HND - APDD - W9 - User-Defined Data Structures in Python

Uploaded by

Anojan Anoj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views13 pages

5615-1700040351707-HND - APDD - W9 - User-Defined Data Structures in Python

Uploaded by

Anojan Anoj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT 20 -Applied Programming and

Design Principles
Week [09] – User-Defined Data Structures in
Python

1
Overview of Data Structures in Python
 Data structures are specialized formats for organizing and
storing data to perform operations efficiently.
 In Python, both built-in and user-defined data structures are
available.
 Importance of Choosing the Right Data Structure
 The choice of data structure impacts the efficiency of algorithms
and operations.
 Understanding the nature of operations helps in selecting the
most suitable data structure.
2
Python's Built-in Data Structures (Brief Mention)
 Lists, Tuples, Sets, Dictionaries
 While Python provides versatile built-in structures, deeper understanding
involves exploring user-defined structures.

Focus on User-Defined Data Structures for Deeper


Understanding
 User-defined data structures allow customization for specific application
needs.
 We'll delve into key user-defined data structures like Stack, Queue, Tree,
Linked List, and Graph.
3
4
User-Defined Data Structures - Stack
A stack is a linear data structure that adheres to the LIFO (Last In, First Out)
principle. Elements are inserted and removed from the top of the stack,
resembling a pile of plates. Stacks are commonly used for implementing
undo/redo functionality, parsing expressions, and backtracking algorithms.

Operations:
push(): Inserts an element onto the stack.
pop(): Removes the topmost element from the stack and returns it.
peek(): Returns the topmost element without removing it.
isEmpty(): Checks whether the stack is empty.
5
Applications
 Undo/redo functionality in text editors and graphical applications.
 Expression parsing and evaluation in compilers and interpreters.
 Backtracking algorithms for maze solving and puzzle solving.

6
7
User-Defined Data Structures - Queue
 A queue follows the FIFO (First In, First Out) principle, similar to a line
of people waiting for service. Elements are inserted at the rear of the
queue and removed from the front. Queues are frequently employed
in task scheduling, buffering data, and handling asynchronous
processes.
 Operations:
 enqueue(): Inserts an element into the rear of the queue.
 dequeue(): Removes the frontmost element from the queue and returns it.
 front(): Returns the frontmost element without removing it.
 isEmpty(): Checks whether the queue is empty.

8
Applications
 Task scheduling in operating systems and multithreaded applications.
 Buffering data in network communication and file I/O.
 Handling asynchronous processes in event-driven programming.

9
10
User-Defined Data Structures - Tree
 A tree is a hierarchical data structure composed of nodes
interconnected by edges. Each node can have zero or more child
nodes, forming a parent-child relationship. Trees are often used
for representing hierarchical data, such as file systems,
organizational structures, and decision trees.
 Operations:
 insert(): Inserts a new node into the tree.
 search(): Searches for a specific node or data within the tree.
 delete(): Removes a node from the tree.
 traverse(): Visits each node in the tree in a systematic manner.
11
Applications
 File systems and directory structures in operating systems.
 Organizational charts and decision trees.
 Parsing expressions and evaluating arithmetic expressions.

12
Lesson Summary

 Overview of Data Structures in Python


 Python's Built-in Data Structures (Brief Mention)
 Focus on User-Defined Data Structures for Deeper
Understanding
 User-Defined Data Structures –
 Stack
 Queue
Thank You
 Tree
Mahesh Madhushan – BSc. in ICT (RUSL), BEng. In SE Hons (UK), MSc IT (UOP)
13

You might also like