Computer Science Notes: Data Structures
1. Introduction to Data Structures
A data structure is a way of organizing, managing, and storing data efficiently.
It enables efficient access and modification.
2. Types of Data Structures
Linear Data Structures: Elements are arranged sequentially (e.g., Array, Linked List, Stack,
Queue).
Non-Linear Data Structures: Elements are arranged in hierarchical order (e.g., Tree, Graph).
3. Arrays
Fixed-size, homogeneous collection of elements.
Direct access using index.
Time complexity:
Access: O(1)
Insertion/Deletion: O(n)
4. Linked List
Collection of nodes where each node contains data and a reference to the next node.
Types: Singly, Doubly, Circular
Time complexity:
Access: O(n)
Insertion/Deletion: O(1) at the beginning
5. Stack
Follows LIFO (Last In First Out).
Operations: push, pop, peek
Applications: Recursion, expression evaluation, undo mechanisms
6. Queue
Follows FIFO (First In First Out).
Types: Simple Queue, Circular Queue, Deque, Priority Queue
Applications: CPU scheduling, IO buffers, print queues
7. Trees
Hierarchical data structure.
Binary Tree: Each node has up to 2 children.
Binary Search Tree (BST): Left < Root < Right
AVL Tree: Self-balancing BST
B-Trees: Used in databases for balanced multi-level indexing
8. Graphs
Collection of nodes (vertices) connected by edges.
Types: Directed, Undirected, Weighted, Unweighted
Representation: Adjacency Matrix, Adjacency List
Traversal: BFS (Breadth First Search), DFS (Depth First Search)
9. Hash Table
Stores key-value pairs.
Uses a hash function to compute index.
Handles collisions using chaining or open addressing
10. Applications
Data structures are used in real-world applications like:
Search engines
Social media (Graph algorithms)
Compilers (Stack, Parse Trees)
Databases (B-Trees, Hash Tables)
Summary
Choosing the right data structure can significantly impact performance and efficiency.
Understanding complexity and use-cases is crucial for real-world application design.