Data Models and Data Structures LECTURE5
Data Models and Data Structures LECTURE5
Structures
LECTURE 5
WHAT IS DATA?
When data becomes information?
• DATA : nhoj si eman my
• INFORMATION: My name is John
If data is arranged in a systematic way then it gets a structure and
become meaningful
Therefore, meaningful or processed data is called INFORMATION.
However, data needs to be managed in such a way so that it can
produce some meaningful information.
Therefore,
• A data model defines how data is structured, stored, and manipulated in
a database or system.
• It represents the logical structure of the data and the relationships
between different data elements.
Types of Data Models:
1. Hierarchical Model:
•Data is organized in a tree-like structure with parent-child
relationships.
•Example: File systems, where folders can contain other folders and
files.
Example
2. Network Model
Emerged from the Hierarchical Model to overcome the
disadvantages of the hierarchical Model for representing
complex data relationships to improve database performance
3. Relational Model:
•Data is organized into tables (relations) where each row represents a
record, and columns represent attributes.
•Example: A database table storing student information (name, ID,
course).
TABLE
Types:
•Singly Linked List: Nodes contain data and a reference to the next node.
•Doubly Linked List: Nodes contain data and references to both the next and previous
nodes.
• Example of Operations in a Linked List:
• Insert: Add a node at the beginning, middle, or end.
• Delete: Remove a node by updating links.
• Search: Find a node by traversing from the head node.
3. Stacks:
•A collection of elements that follows the Last In, First Out (LIFO) principle.
Operations:
•Push: Add an element to the top of the stack.
•Pop: Remove the top element.
•Peek: View the top element without removing it.
•Example: Undo function in text editors.
4. Queues:
•A collection of elements that follows the First In, First Out (FIFO) principle.
Operations:
•Enqueue: Add an element to the back of the queue.
•Dequeue: Remove an element from the front of the queue.
•Example: Printer task scheduling.
5. Trees:
Types:
•Binary Tree: A tree where each node has at most two children.
•Binary Search Tree (BST): A binary tree where the left child is smaller than the parent, and the right
child is greater.
6. Graphs:
•Example: Social networks, where users are nodes, and friendships are edges.
Operations on Data Structures
• Common Operations:
1. Traversal: Visiting every element in the data structure.
• Example: In a tree, traversing each node from top to bottom (pre-order, in-
order, post-order).
2. Insertion: Adding an element to the data structure.
3. Deletion: Removing an element from the data structure.
4. Searching: Finding an element in the data structure (e.g., linear
search in an array, binary search in a sorted array).
5. Sorting: Arranging elements in a particular order (e.g., ascending or
descending).
Application of Data Structures
• Choosing the Right Data Structure:
• The choice of data structure depends on the problem you’re solving:
• For searching: Use arrays, linked lists, or hash tables.
• For hierarchical data: Use trees.
• For relationships between entities: Use graphs.
• Real-World Applications:
1. Arrays: Storing multiple variables like employee records in a database.
2. Stacks: Implementing undo/redo functionality in applications.
3. Queues: Managing tasks in a print queue or customer support system.
4. Trees: Representing folder hierarchies or performing fast
lookups in databases (binary search trees).
5. Graphs: Modeling social networks, cities connected by roads,
or computer networks.
Data Structures in Programming
• Implementing Data Structures:
• Most programming languages provide built-in data structures (e.g.,
lists, dictionaries in Python, arrays in Java).
• For custom applications, you may need to implement your own data
structures to optimize performance or meet specific requirements.