TGViewer
Coding Interview Resources Coding Interview Resources @crackingthecodinginterview · 52.2K subscribers
Post #2675 4.23K
✅ DSA Interview Questions & Answers – Part 2 🧠💻

1️⃣ What is a Graph?
A: A non-linear data structure with nodes (vertices) connected by edges representing relationships.
⦁ Types: Directed (one-way edges, like Twitter follows), Undirected (bidirectional, like friendships), Weighted (edges with costs, e.g., distances), Unweighted.
⦁ Example: Social networks (users as nodes, connections as edges) or maps (cities and routes)—BFS/DFS traversal is key for shortest paths.

2️⃣ Difference between Tree and Graph?
A:
⦁ Tree: Acyclic (no loops), connected graph with exactly one path between nodes, hierarchical with a root and N-1 edges for N nodes—great for file systems.
⦁ Graph: Can have cycles, multiple paths, disconnected components, and more edges—more flexible but needs cycle detection algorithms like DFS.

3️⃣ What is a Heap?
A: A complete binary tree satisfying the heap property for fast min/max access.
⦁ Max Heap: Parent nodes ≥ children (root is maximum).
⦁ Min Heap: Parent ≤ children (root is minimum).
⦁ Uses: Priority queues (e.g., task scheduling), Heap Sort (O(n log n))—implemented via arrays for efficiency.

4️⃣ What is Recursion? Example?
A: A technique where a function solves a problem by calling itself on smaller inputs until a base case stops it, using implicit stack.
⦁ Example: Factorial: def fact(n): return 1 if n <= 1 else n * fact(n-1). Also Fibonacci or tree traversals—watch for stack overflow on deep calls.

5️⃣ Difference between Recursion and Iteration?
A:
⦁ Recursion: Self-calling with base case, elegant for tree/graph problems but uses call stack (risk of overflow), O(n) space.
⦁ Iteration: Uses loops (for/while), explicit control, lower memory, faster execution—convert recursion via tail optimization for interviews.

6️⃣ What is a Trie?
A: A prefix tree for storing strings in a tree where each node represents a character, enabling fast lookups and prefixes.
⦁ Use Case: Autocomplete (search engines), spell checkers, IP routing—O(m) time for m-length word, space-efficient for common prefixes.

7️⃣ Difference between Linear Search & Binary Search?
A:
⦁ Linear Search: Scans sequentially, O(n) time, works on unsorted data—simple but inefficient for large lists.
⦁ Binary Search: Divides sorted array in half repeatedly, O(log n) time—requires sorted input, ideal for databases or sorted arrays.

8️⃣ What is a Circular Queue?
A: A queue implementation where the rear connects back to front, reusing space to avoid linear queue's "wasted" slots after dequeues.
⦁ Efficient memory usage (no shifting), fixed size, handles wrap-around with modulo—common in buffering systems like OS task queues.

9️⃣ What is a Priority Queue?
A: An abstract data type where elements have priorities; dequeue removes highest/lowest priority first (not FIFO).
⦁ Implemented using: Heaps (binary for O(log n) insert/extract), also arrays or linked lists—used in Dijkstra's algorithm or job scheduling.

🔟 What is Dynamic Programming (DP)?
A: An optimization technique for problems with overlapping subproblems and optimal substructure, solving bottom-up or top-down with memoization to avoid recomputation.
⦁ Example: Fibonacci (store fib(n-1) + fib(n-2)), 0/1 Knapsack (max value without exceeding weight)—reduces exponential to polynomial time.

💬 Double Tap ❤️ if this helped you!
  • ❤ 9
More from @crackingthecodinginterview
  1. Oct 9, 2026🔥 SQL Interview Case Studies (Advanced Business Scenarios) 💯 🧠 Case Study 1: Find Repea…
  2. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
  3. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  4. Oct 7, 2026🚀 DSA Topics Every Programmer Should Know 💻🔥 📦 1. Arrays ✔ Traversal ✔ Searching ✔ Sor…
  5. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  6. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →