Introduction to Data Structures
Data Structures are ways of **organizing, storing, and managing data efficiently** in memory so that they can be used effectively in a program.
They help in improving **performance, speed, and memory usage**.
What are Data Structures?
A Data Structure is a particular way of storing and arranging data in a computer so it can be accessed and modified efficiently.
- Defines how data is stored
- Defines how data is accessed
- Defines how data is manipulated
- Improves performance of algorithms
Why Do We Need Data Structures?
- To store large amounts of data efficiently
- To perform operations quickly
- To reduce memory usage
- To increase program performance
- To handle complex problems easily
Without proper data structures, even a simple program may become slow, heavy, and inefficient.
Types of Data Structures
Data structures are mainly divided into two categories:
- 1. Primitive Data Structures → int, float, char, double
- 2. Non-Primitive Data Structures
Includes:
- Arrays
- Strings
- Structures
- Linked Lists
- Stacks
- Queues
- Trees
- Graphs
Linear vs Non-linear Data Structures
Linear Data Structures
Elements arranged in a sequence.
- Array
- String
- Linked List
- Stack
- Queue
Non-Linear Data Structures
Elements arranged hierarchically.
- Tree
- Graph
Applications of Data Structures
- Searching and Sorting
- Databases and File System organization
- Compiler design
- Operating system (process management)
- Networking (routing tables)
- Artificial Intelligence and Machine Learning
- Game development
Basic Example: Array as a Data Structure
#include <stdio.h>
int main() {
int marks[5] = {90, 85, 92, 88, 95};
for(int i = 0; i < 5; i++){
printf("%d ", marks[i]);
}
return 0;
}
Basic Example: Linked List Node
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
int main() {
struct Node* head = (struct Node*) malloc(sizeof(struct Node));
head->data = 10;
head->next = NULL;
printf("Node value: %d", head->data);
free(head);
return 0;
}
Practice Questions
- What is a data structure? Explain with examples.
- Difference between linear and non-linear data structures.
- List five real-life applications of data structures.
- Explain the importance of data structures in programming.
- What is the difference between primitive and non-primitive data structures?
Practice Task
Create an array of 10 numbers and print:
✔ Maximum value
✔ Minimum value
✔ Sum of all numbers
✔ Average
✔ Count numbers > 50