Data structures help store, organise, and manage data. They are very important for computer science and programming. Different data structures are used for different purposes.
Examples of Data Structure
The following Examples of Data Structure
1. Array
An array is a simple data structure that stores multiple values in a variable. It stores the data in a fixed order. Each element has an index number, with the help of which it can be easily accessed.
Example
If we want to store the marks of a student, we can store them in an array like this:
`marks = [85, 90, 78, 92]`
Arrays are useful in places where the amount of data is known in advance and it is necessary to retrieve it quickly.
2. Linked List
A linked list is a data structure that stores data in the form of nodes. Each node contains two things:
- Avalue (data)
- Apointer that points to the next node
It does not have a fixed size like an array, but can be expanded or reduced as needed.
Usages
- To-do list in task manager
- Memory management
3. Stack
A stack works on theLast In, First Out (LIFO) principle, meaning that the last item added is the first to be removed.
Example
Look at a stack of plates, the plate placed at the end will be removed first.
Uses
- Undo button in a text editor
- Function calls in programming
- Reversing words in a sentence
4. Queue
Queue works on theFirst In, First Out (FIFO) principle, meaning that the first thing added is the first thing taken out.
Example
People in line at a bus stop, whoever comes first gets on the bus first.
Usages
- Process scheduling in computers
- Customer service systems
- Printer job management
5. Hash Table
Hash tables store data inKey-Value pairs. Searching for data in them is very fast.
Example
Storing a name and number in a phone book:
phone_book = {“Ali”: 12345, “Ahmed”: 67890}
If we need to find the number of “Ali”, we can get it immediately.
Usages
- Databases
- Caching systems
- Password storage
6. Tree
A tree is a hierarchical data structure. It has nodes connected to each other.
Example
A file system has folders within folders in the form of a tree.
Usages
- Search engines
- Artificial intelligence
- Game development
7. Graph
A graph is a data structure that shows the relationship between objects. It consists of two things:
- Nodes – represent objects
- Edges – represent connections between nodes
Example
Each user on Facebook is a node, and the connection between friends is an edge.
Usages
- Social media networks
- Finding directions in Google Maps
- Links to websites
8. Heap
A heap is a special type of tree that supports Priority-based tasks.
Example
- InMin-Heap, the smallest number is at the top.
- InMax-Heap, the largest number is at the top.
Usages
- Task scheduling
- Memory management
- Shortening algorithms
9. Trie
A trie is a tree-like data structure that helps in finding words quickly.
Example
Theautocomplete feature in search engines uses tries.
Usages
- Spell checker
- Search engines
- Dictionaries
10. Matrix
A matrix is atwo-dimensional (2D) array that stores data in rows and columns.
Example
An image is stored in a matrix of pixels:
1 0 1
0 1 0
1 0 1
This method helps in image processing.
Usages
- Game development
- Scientific computing
- Image processing