Detailed Data Structures Notes
Detailed Data Structures Notes
A data structure is a way of organizing and storing data efficiently to perform operations like
searching, sorting, insertion, and deletion. Choosing the right data structure improves algorithm
efficiency and reduces memory usage.
- **Non-Linear Structures:**
- Trees: Hierarchical representation of data.
- Graphs: Collection of nodes and edges.
Linked List
A **linked list** is a dynamic data structure where elements, called nodes, are connected using
pointers. Each node contains:
1. **Singly Linked List:** Each node has a pointer to the next node.
2. **Doubly Linked List:** Each node has pointers to both the previous and next nodes.
3. **Circular Linked List:** The last node links back to the first node.
### Disadvantages:
- Extra memory needed for pointers.
- Sequential access is slower than arrays.
Garbage Collection
Garbage collection is an automatic memory management process that removes unused objects to
free up memory.
### Advantages:
- Prevents memory leaks.
- Automates memory management.
### Disadvantages:
- Can slow down program execution.
- Less control for programmers.
### Applications:
- Java and Python use automatic garbage collection.
- Operating systems manage process memory using garbage collection.
Binary Tree
A **binary tree** is a hierarchical data structure where each node has at most two children.
### Advantages:
- Fast searching and sorting.
- Efficient hierarchical data representation.
### Disadvantages:
- Unbalanced trees can be inefficient.
### Applications:
- Used in databases for indexing.
- Binary search trees are used in search engines.
Queue
A **queue** is a linear data structure that follows the FIFO (First In, First Out) principle.
### Advantages:
- Used in scheduling tasks.
- Helps in order processing.
### Disadvantages:
- Fixed size in arrays.
- Limited access to elements.
### Applications:
- Process scheduling in OS.
- Used in breadth-first search algorithms.
Array
An **array** is a collection of elements of the same type stored in contiguous memory locations.
### Advantages:
- Fast access to elements using index.
- Used for matrix operations.
### Disadvantages:
- Fixed size.
- Costly insertion and deletion.
### Applications:
- Used in database indexing.
- Matrix operations in scientific computing.
File Handling
File handling is a process that allows a program to read and write data to files.
### File Modes:
### Advantages:
- Stores large amounts of data permanently.
- Data can be easily shared between programs.
### Disadvantages:
- Risk of data corruption.
- Slower access compared to memory storage.
### Applications:
- Storing user data in applications.
- Logging system activities in software.
Comprehensive Data Structures Notes
A data structure is a way of organizing and storing data efficiently to perform operations like
searching, sorting, insertion, and deletion. Choosing the right data structure improves algorithm
efficiency and reduces memory usage.
- **Non-Linear Structures:**
- Trees: Hierarchical representation of data.
- Graphs: Collection of nodes and edges.
Linked List
A **linked list** is a dynamic data structure where elements, called nodes, are connected using
pointers. Each node contains:
1. **Singly Linked List:** Each node has a pointer to the next node.
2. **Doubly Linked List:** Each node has pointers to both the previous and next nodes.
3. **Circular Linked List:** The last node links back to the first node.
### Disadvantages:
- Extra memory needed for pointers.
- Sequential access is slower than arrays.
Garbage Collection
Garbage collection is an automatic memory management process that removes unused objects to
free up memory.
### Advantages:
- Prevents memory leaks.
- Automates memory management.