5615-1700040351707-HND - APDD - W9 - User-Defined Data Structures in Python
5615-1700040351707-HND - APDD - W9 - User-Defined Data Structures in Python
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.
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