📖 Chapters
- 1. Introduction to DSA and Its Importance
- 2. Time and Space Complexity (Big O, Θ, Ω)
- 3. Recursion and Stack Memory
- 4. Mathematics for DSA (GCD, LCM, Modulo Arithmetic)
- 5. Arrays: Basics and Operations
- 6. Strings: Manipulation & Inbuilt Functions
- 7. Structures and Unions with Arrays
- 8. Linked Lists (Singly, Circular, Doubly)
- 9. Stack (Using Array & Linked List)
- 10. Queue (Simple, Circular, Deque)
- 11. Linear Search & Binary Search
- 12. Sorting Basics: Bubble, Selection, Insertion
- 13. Merge Sort
- 14. Quick Sort
- 15. Counting Sort, Radix Sort, Bucket Sort
- 16. Heap Sort
- 17. Binary Trees & Representations
- 18. Binary Tree Traversals (Pre, In, Post)
- 19. Binary Search Tree (BST)
- 20. AVL Trees (Self-balancing BST)
- 21. Trie (Prefix Tree)
- 22. Segment Tree (Range Queries)
- 23. Fenwick Tree / Binary Indexed Tree (BIT)
- 24. Heap & Priority Queues (Min-Heap, Max-Heap)
- 25. Hashing and Hash Tables
- 26. Disjoint Set Union (Union-Find, Path Compression)
- 27. Sparse Tables
- 28. Sliding Window Technique
- 29. Two Pointers Technique
- 30. Graph Representations (Adjacency Matrix & List)
- 31. BFS and DFS (Traversal & Search)
- 32. Topological Sort (Kahn’s & DFS)
- 33. Shortest Path Algorithms (Dijkstra, Bellman-Ford)
- 34. Minimum Spanning Tree (Kruskal, Prim)
- 35. Cycle Detection in Graphs
- 36. Bridges and Articulation Points
- 37. Greedy Algorithms (Activity Selection, Huffman Coding)
- 38. Backtracking (N-Queens, Sudoku Solver)
- 39. Dynamic Programming (Intro, Memoization, Tabulation)
- 40. Advanced DP (LIS, Knapsack, DP on Trees/Grids)
- 41. Bit Manipulation and XOR Tricks
- 42. Interview Problems from FAANG Companies
- 43. Competitive Coding Patterns
- 44. Building Mini Projects Using DSA (Menu-driven)
- 45. Final Quiz + Problem Sheet (100+ questions)
- 46. Next Steps: Competitive Programming or System Design?
Data Structures and Algorithms in C (DSA)
Category: IT Fundamentals & Programming
This course is designed to help learners master the core concepts of Data Structures and Algorithms (DSA) using the C programming language. Starting from the basics and advancing to complex topics like graphs, dynamic programming, and memory optimization, this course …
Mathematics for DSA (GCD, LCM, Modulo Arithmetic)
📘 Mathematics for DSA (GCD, LCM, Modulo Arithmetic)
Mathematics is the backbone of efficient algorithms in Data Structures. In this chapter, we cover essential concepts such as GCD, LCM, and Modulo Arithmetic that are frequently used in number theory, combinatorics, and optimization problems.
🧮 GCD (Greatest Common Divisor)
GCD of two numbers is the largest number that divides both numbers without leaving a remainder.
Example: GCD of 12 and 18 is 6.
🔁 Euclidean Algorithm
Efficient method to compute GCD:
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }
🔗 LCM (Least Common Multiple)
LCM of two numbers is the smallest number divisible by both numbers.
Formula: LCM(a, b) = (a × b) / GCD(a, b)
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
➗ Modulo Arithmetic
Modulo (%) returns the remainder of a division. Used heavily in competitive programming to avoid overflow and in cyclic behavior problems (like clocks, circular arrays).
// Examples 7 % 3 = 1 10 % 5 = 0 -5 % 3 = -2 (in C)
⚠️ Modulo Tips
(a + b) % m = ((a % m) + (b % m)) % m
(a * b) % m = ((a % m) * (b % m)) % m
(a - b + m) % m
handles negative results
🧠 Modular Inverse (Advanced)
For solving equations like (a / b) % m
, we use the Modular Inverse of b under m:
Use Fermat's Theorem when m is prime: b⁻¹ ≡ b^(m-2) mod m
// Fast Power to compute (base^exp) % mod int power(int base, int exp, int mod) { int res = 1; base %= mod; while (exp > 0) { if (exp % 2) res = (1LL * res * base) % mod; base = (1LL * base * base) % mod; exp /= 2; } return res; }
📚 Practice Problems
- Find GCD of 270 and 192
- LCM of 8 and 14
- Compute (123456 * 98765) % 1000000007
- Find modular inverse of 5 mod 13
✅ Summary
- Use GCD to simplify fractions, find common factors.
- LCM is used for scheduling and synchronization problems.
- Modulo is essential for safe arithmetic operations in large inputs.
- Modular inverse helps in division under modulo.
📤 Coming Next
In the next chapter, we’ll cover Arrays: Basics and Operations — the foundational structure for storing collections of data in DSA.