Loading...
Loading...
Self-balancing BST. Balance factor = height(left) - height(right) ∈ 1
Rotations to restore balance:
All operations O(log n) guaranteed
Self-balancing BST used in Java TreeMap, C++ std::map.
Properties:
All operations O(log n) but less rotations than AVL → better for insertions.
Used in databases and file systems (MySQL uses B+ Tree).
Properties for B-Tree of order m:
B+ Tree: All data in leaf nodes; internal nodes only for navigation; leaves linked for range queries.
Complete binary tree where parent ≥ children (max-heap) or parent ≤ children (min-heap).
Operations:
Heap Sort: Build max-heap, extract max n times → O(n log n)
Tree where each path from root represents a string prefix. Used for: autocomplete, spell check, IP routing.
Operations: Insert, Search, StartsWith — all O(L) where L = string length
Hash Function: Maps keys to array indices. Good hash function: Uniform distribution, fast to compute, deterministic.
Collision Resolution:
All elements stored in hash table itself.
Each slot has a linked list of elements.
Universal Hashing: Randomly select hash function → good average case.
Finds all occurrences of pattern P in text T efficiently.
Failure Function: For each position, length of longest proper prefix that is also suffix. Pattern "ABABC": failure = [0,0,1,2,0]
Uses hashing for pattern matching.
Z[i] = length of longest substring starting at position i that is also prefix of string. Time: O(n)
Articulation point: Removing it disconnects the graph. Bridge: Removing it disconnects the graph. Found using DFS with discovery times and low values.
Kosaraju's Algorithm:
Tarjan's Algorithm: Single DFS pass using stack and low values.
Linear ordering of vertices such that for every edge u→v, u comes before v. Conditions: Only valid for DAGs (Directed Acyclic Graphs)
Kahn's Algorithm (BFS-based):
Max-Flow Min-Cut Theorem: Maximum flow = Minimum cut capacity. Ford-Fulkerson: Find augmenting path, increase flow. O(E × max_flow). Edmonds-Karp (BFS-based Ford-Fulkerson): O(VE²)
def lcs(X, Y):
m, n = len(X), len(Y)
dp = [[0]*(n+1) for _ in range(m+1)]
for i in range(1, m+1):
for j in range(1, n+1):
if X[i-1] == Y[j-1]:
dp[i][j] = dp[i-1][j-1] + 1
else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
return dp[m][n]
O(n²) DP or O(n log n) with patience sorting/binary search.
Find optimal parenthesization to minimize matrix multiplications. dp[i][j] = minimum multiplications for Aᵢ...Aⱼ dp[i][j] = min(dp[i][k] + dp[k+1][j] + pᵢ₋₁×pₖ×pⱼ) for all k from i to j-1
Minimum operations (insert, delete, replace) to convert string A to B.
if A[i]==B[j]: dp[i][j] = dp[i-1][j-1]
else: dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])
Amortized Analysis: Average time per operation over worst-case sequence.
P vs NP:
Common NP-Complete Problems: SAT, 3-SAT, Vertex Cover, Clique, Hamilton Path, Travelling Salesman Decision.
Q1 (MCA Entrance): What is the time complexity of building a heap from n elements? O(n) — not O(n log n). Heapify is called on n/2 nodes, but most nodes are near leaves (small subtrees). The mathematical sum converges to O(n).
Q2 (2023): Find LCS of "ABCBDAB" and "BDCAB". Build DP table systematically. LCS length = 4 ("BCAB" or "BDAB")
Q3 (2024): Prove that Dijkstra's algorithm doesn't work with negative weights. Counter-example: A→B cost 2, A→C cost 3, C→B cost -2. Dijkstra: B has cost 2. But A→C→B = 1 < 2. Dijkstra settles B too early before considering path through C.
Complete DSA notes for MCA — advanced data structures, algorithm design, graph algorithms, dynamic programming, string algorithms, and complexity analysis with solved problems.
62 pages · 3.1 MB · Updated 2026-03-11
AVL Trees, Red-Black Trees, B-Trees, Heaps (priority queues), Hash Tables with collision handling, Segment Trees, and Tries are most important for MCA-level problems.
Focus on time complexity analysis, sorting algorithms, graph algorithms (BFS/DFS/Dijkstra), dynamic programming (knapsack, LCS, LIS), and hashing. Practice at least 5 problems per topic.
Python Programming for MCA — Complete Notes with Programs
Python Programming
Python Advanced Programming — Complete MCA Notes
Python Programming
Advanced Machine Learning & Deep Learning — MTech/MCA Complete Notes
Machine Learning
DBMS Complete Notes — B.Tech CS Sem 4
Database Management Systems
Compiler Design — Complete Notes CS Sem 6
Compiler Design
Your feedback helps us improve notes and tutorials.