Common Data Structures Explained
Common Data Structures Explained
1. Arrays
An array is a collection of items stored at contiguous memory locations. The idea is to store multiple
items of the same type together.
2. Linked List
A linked list is a collection of nodes where each node contains the data and a reference (or pointer)
to the next node.
Example:
css
Copy code
Operations: Insertion and deletion are more efficient than in arrays (O(1) if
inserting/deleting at the beginning).
3. Stack
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. Elements are
added and removed from only one end (the top).
Example: Browser history, where the most recently visited page is at the top.
4. Queue
A queue follows the First In, First Out (FIFO) principle. Elements are added at the rear and removed
from the front.
5. Hash Table
A hash table stores key-value pairs and uses a hash function to compute an index into an array of
buckets or slots.
Example: Dictionary lookup, where the word is the key, and the definition is the value.
1. Sorting Algorithms: Organize data in a specific order (e.g., Bubble Sort, Quick Sort, Merge
Sort).
2. Searching Algorithms: Find specific data in a structure (e.g., Binary Search, Linear Search).
3. Graph Algorithms: Solve problems related to graph data structures (e.g., Dijkstra’s Algorithm,
Breadth-First Search).
Bubble Sort is a simple algorithm that repeatedly steps through the list, compares adjacent elements,
and swaps them if they are in the wrong order. This process continues until the list is sorted.
Pass 1:
Pass 2:
Binary Search works on sorted arrays. It divides the array into two halves, compares the target value
with the middle element, and eliminates half of the array in each step.
1. Efficiency: Well-chosen data structures and algorithms reduce time and memory usage.
2. Problem Solving: Essential for solving complex computational problems and optimizing
performance.