Basic Overview of DSA
-
Arrays: Linear data structure with a fixed size, allowing random access to elements.
- Best for: Static datasets with frequent element access.
- Complexity:
- Access: O(1)
- Search: O(n)
- Insertion/Deletion: O(n) Array
-
Linked Lists: Linear structure of nodes, where each node points to the next.
- Types: Singly, Doubly, Circular.
- Best for: Dynamic datasets with frequent insertions/deletions.
- Complexity:
- Access/Search: O(n)
- Insertion/Deletion: O(1) (at head/tail with pointer)
-
Hash Maps (or Hash Tables): Key-value pair storage with a hash function.
- Best for: Quick lookup and insertion.
- Complexity:
- Average: O(1)
- Worst-case: O(n)(due to hash collisions)
-
Stacks: LIFO (Last In, First Out) structure.
- Operations: Push, Pop, Peek.
- Best for: Recursive problems, expression evaluation.
- Complexity:
- Push/Pop/Peek: O(1)
-
Queues: FIFO (First In, First Out) structure.
- Variants: Circular Queue, Deque, Priority Queue.
- Best for: Scheduling, buffering.
- Complexity:
- Enqueue/Dequeue: O(1)
-
Trees: Hierarchical structure with nodes (root, parent, children).
- Types: Binary, Binary Search Tree (BST), AVL, Red-Black, etc.
- Best for: Hierarchical data, searching/sorting.
- Complexity:
- Search/Insert/Delete: O(h), where h is the tree height.
- Balanced trees maintain h=O(logn).
-
Graphs: Collection of nodes (vertices) connected by edges.
- Types: Directed, Undirected, Weighted, Unweighted.
- Representation: Adjacency Matrix/List.
- Best for: Network problems, pathfinding.
- Algorithms: DFS, BFS, Dijkstra’s, Prim’s, Kruskal’s.