π§© Organize β’ Store β’ Search β’ Sort π
Learn how data is organized, stored, accessed and processed using important data structures and basic algorithms.
A data structure is a way of organizing and storing data so that it can be accessed and processed efficiently.
Data Structure = A method of organizing data.
Array, Linked List, Stack and Queue.
Trees and Graphs.
An array is a collection of elements stored in contiguous memory locations.
The size of a traditional array is generally fixed, so inserting or deleting elements can require shifting other elements.
π» ExampleA linked list consists of nodes where each node contains data and a link to another node.
Nodes can be inserted without shifting all existing elements.
Nodes can be removed by changing links.
Stack follows the LIFO principle: Last In, First Out.
A stack of plates β the last plate placed on top is removed first.
Queue follows the FIFO principle: First In, First Out.
People standing in a queue at a counter. The person who comes first is served first.
A tree is a non-linear data structure that represents hierarchical relationships.
A binary tree is a tree in which each node can have at most two children.
A graph consists of vertices and edges used to represent relationships between objects.
Represents a node or object.
Represents a connection between vertices.
Edges have a direction.
Edges do not have a direction.
Searching means finding a particular element in a collection of data.
Checks elements one by one.
β±οΈ Time Complexity: O(n)
Repeatedly divides a sorted search space into two parts.
β±οΈ Time Complexity: O(log n)
Sorting means arranging data in a particular order, such as ascending or descending order.
Repeatedly compares adjacent elements and swaps them when needed.
Builds the sorted portion one element at a time.
Selects the smallest element and places it in the correct position.
Uses a pivot to divide the data into smaller parts.
| Structure | Type | Main Principle | Example |
|---|---|---|---|
| Array | Linear | Index | Marks list |
| Linked List | Linear | Nodes & Links | Playlist |
| Stack | Linear | LIFO | Plates |
| Queue | Linear | FIFO | Waiting line |
| Tree | Non-Linear | Hierarchy | Folder structure |
| Graph | Non-Linear | Relationships | Social network |
Make sure you can explain these topics and write basic programs for them.