Data Structures Using C++ - Theory Notes
Unit 1: Growth of Functions & Recurrence Relations
UNIT 1: Growth of Functions & Recurrence Relations
1. Time Complexity (Big-O Notation)
It tells how fast a program runs as input grows.
Examples: O(1), O(n), O(n^2), O(log n), O(n log n)
2. Recurrence Relation
Used in recursive algorithms to find time. Example: T(n) = 2T(n/2) + n
3. Master Theorem: T(n) = aT(n/b) + f(n)
Helps solve recurrences quickly by comparing f(n) with n^log_b(a)
Unit 2: Arrays, Linked Lists, Stacks, Queues, Deques
UNIT 2: Arrays, Linked Lists, Stacks, Queues, Deques
1. Arrays: Fixed size, direct indexing. Fast access but resizing is hard.
2. Linked List: Dynamic size. Each node points to next.
- Singly, Doubly, Circular types.
3. Stack (LIFO): Last in, first out. Used in function calls, undo.
4. Queue (FIFO): First in, first out. Used in CPU scheduling.
5. Deque: Double-ended queue. Insert/delete at both ends.
Unit 3: Recursion
UNIT 3: Recursion
Recursion means a function calls itself.
Types:
1. Linear Recursion: Calls once.
2. Binary Recursion: Calls twice (e.g., Fibonacci).
Always has a base case to stop.
Unit 4: Trees, Binary Trees
UNIT 4: Trees, Binary Trees
1. Tree: Non-linear structure with root and children.
2. Binary Tree: Each node has up to 2 children.
Traversals:
- Inorder (Left, Node, Right)
- Preorder (Node, Left, Right)
- Postorder (Left, Right, Node)
Unit 5: Binary Search Trees, Balanced Trees
UNIT 5: Binary Search Trees, Balanced Trees
1. BST: Left child < root < right child. Fast insert, search, delete.
2. Balanced BST: Like AVL tree, maintains height balance.
Used in searching, maps, sets.
Unit 6: Binary Heap, Priority Queue
UNIT 6: Binary Heap, Priority Queue
1. Binary Heap: Complete binary tree with heap property.
- Min Heap: Root is smallest.
- Max Heap: Root is largest.
2. Priority Queue: Based on heap. Highest priority comes out first.