Most coding problems look different… until you realize they are just graphs in disguise. That’s where Graphs come in. A graph represents relationships using nodes (vertices) and edges (connections). You’ll find them everywhere from Google Maps finding routes to social media suggesting connections. Understanding Graphs Graphs can take different forms depending on the problem: • Directed and Undirected (based on direction) • Weighted and Unweighted (based on cost or distance) • Cyclic and Acyclic (DAG) These variations help model real-world scenarios more accurately. How Graphs Are Stored There are two main ways: • Adjacency Matrix → fast lookup but uses more space • Adjacency List → space efficient and used in most systems Core Traversal Techniques 🔹 BFS (Breadth-First Search) Moves level by level and helps find shortest paths in unweighted graphs 🔹 DFS (Depth-First Search) Goes deep into nodes and is useful for cycle detection and backtracking Important Algorithms Once basics are clear, these are must-know: • Dijkstra → shortest path • Bellman-Ford → handles negative weights • Kruskal & Prim → minimum spanning tree • Topological Sort → ordering in DAG How to Approach Graphs Start with basics, master BFS and DFS, then move to problems like cycle detection and shortest paths. With practice, patterns become clear. Graphs are not just a topic, they help you think in terms of connections and dependencies. 💬 Comment what kind of notes or topic you want next, and I will cover it in detail👇. #DSA #Algorithms #Java #Coding #InterviewPrep
Graphs in Disguise: Understanding Relationships and Algorithms
More Relevant Posts
-
I just learned something that no LeetCode problem ever taught me. How do you sort 200 GB of data when your RAM is only 5 GB? 🤯 I came across this in a real interview question today — and honestly, I had no clue. The answer? External Merge Sort. Here's how it works in simple terms 👇 📦 Phase 1 — Break it down: • Read 5 GB of data into RAM • Sort it using QuickSort • Write it back to disk as a sorted "chunk" • Repeat 40 times → now you have 40 sorted files 🔀 Phase 2 — Merge using a Min-Heap: • Open all 40 files at once • Push the first element of each file into a Min-Heap (size = just 40!) • Pop the minimum → write to output → push next element from that file • Repeat until all 200 GB are merged The genius part? The heap never holds more than 40 elements at a time. Not 200 GB. Just 40. All those Heap and Merge Sort problems on LeetCode? This is exactly what they're preparing you for — just at a massive scale. This is why Big Tech companies ask System Design questions. Real-world data doesn't fit in an array. 🌍 📸 Attached the full Python implementation above — Phase 1 (Run Creation) + Phase 2 (K-Way Merge) with comments explaining every step. Drop a 🙋 if you had no idea this concept existed before today! And tell me — what's the most surprising DSA concept YOU'VE come across recently? 👇 #DSA #LeetCode #SystemDesign #SoftwareEngineering #Python #CodingInterview #ExternalSorting
To view or add a comment, sign in
-
-
📅 Date: April 25, 2026 Day 4 of my LeetCode Journey 🚀 ✅ Problem Solved: 9. Palindrome Number 🧠 Approach & Smart Solution: While it's easy to solve this by converting the integer to a string and reversing it, that takes extra memory! I opted for a highly optimized mathematical approach. I reversed the integer by peeling off its digits one by one using modulo and division, keeping the space complexity to an absolute minimum. • Pseudo-code: Handle edge cases: If the number is less than 0, it can't be a palindrome, so return false. Store the original number in a temporary variable for final comparison. Initialize a 'reverse' variable to 0. Loop while the number is greater than 0: Extract the last digit: digit = x % 10. Add it to the reversed number: reverse = (reverse * 10) + digit. Remove the last digit from the original number: x = x / 10. Finally, return true if the original number matches the reversed number. This math-based solution avoids expensive string conversions and runs instantly! ⏱️ Time Complexity: O(log₁₀(n)) (We only iterate through the digits of the number) 📦 Space Complexity: O(1) (Only using a few integer variables) 📊 Progress Update: • Streak: 3 Days 🔥 • Difficulty: Easy • Pattern: Math / Digit Extraction 🔗 LeetCode Profile: https://lnkd.in/gBcDQwtb (@Hari312004) Choosing mathematical operations over string manipulations is a great way to optimize basic algorithms! 💡 #LeetCode #DSA #Math #Java #CodingJourney #ProblemSolving #InterviewPrep #Consistency #BackendDevelopment
To view or add a comment, sign in
-
-
🚀 𝗦𝘁𝗿𝗶𝗻𝗴 𝗖𝗼𝗺𝗽𝗿𝗲𝘀𝘀𝗶𝗼𝗻 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝗼𝗹𝘃𝗲𝗱 𝗶𝗻 𝟯 𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁 𝗪𝗮𝘆𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁: Given an array of characters, compress the string by replacing repeated characters with the character followed by its count. 🔗 𝗚𝗶𝘁𝗛𝘂𝗯 𝗖𝗼𝗱𝗲 👉https://lnkd.in/gap5HkW2 Example: Input: ["a","a","b","b","c","c","c"] Output: ["a","2","b","2","c","3"] 𝗜 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁𝗲𝗱 𝟯 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵𝗲𝘀: 1️⃣ 𝗕𝗿𝘂𝘁𝗲 𝗙𝗼𝗿𝗰𝗲 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 Create a separate result array Count repeated characters Append character and count Time Complexity: O(n) Space Complexity: O(n) 2️⃣ 𝗕𝗲𝘁𝘁𝗲𝗿 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 Use two pointers Cleaner logic with left and right pointers Still uses extra space Time Complexity: O(n) Space Complexity: O(n) 3️⃣ 𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗲𝗱 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 Use in-place modification Maintain a write pointer Most memory efficient solution Time Complexity: O(n) Space Complexity: O(1) 𝗧𝗵𝗲 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗲𝗱 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 𝗶𝘀 𝗯𝗲𝘀𝘁 because it avoids extra memory usage and works directly on the input array. 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴: Always try to solve a problem in multiple ways: First for correctness Then for readability Finally for optimization 𝗧𝗵𝗶𝘀 𝗶𝘀 𝗮 𝗴𝗿𝗲𝗮𝘁 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗽𝗿𝗼𝗯𝗹𝗲𝗺 because it tests: ✔️ Arrays ✔️ Two Pointers ✔️ String Manipulation ✔️ Time and Space Complexity Data Structures and Algorithms and Python are all about improving problem-solving skills step by step. #Python #DSA #CodingInterview #ProblemSolving #Algorithms #100DaysOfCode #SoftwareEngineering #Programming #LeetCode #Coding
To view or add a comment, sign in
-
-
🏗️ Beyond "It Works": Writing Maintainable Python One of the biggest shifts in my coding journey has been moving away from long, "flat" scripts and toward Modular Programming. Instead of writing one giant block of code, I’ve started breaking my logic into small, reusable functions. Why the change? Separation of Concerns: My math logic (calculating totals) is now separate from my formatting logic (adding currency symbols). Readability: The main script now reads like a story. Instead of staring at complex f-strings, I just see format_currency(). Future-Proofing: If I need to change the currency to Euros or update a tax calculation, I only change it in one place, not everywhere in the script. The Refactored Logic: Python import pandas as pd def calculate_total(quantity, price): """Calculate total for a single item""" return quantity * price def format_currency(amount): """Format number as currency for reports""" return f"${amount:,.2f}" # --- Main Workflow --- df = pd.read_csv('data/sales.csv', skipinitialspace=True) # Using our functions to clean and transform data df['total'] = df['quantity'] * df['price'] df['display_total'] = df['total'].apply(format_currency) print(df[['product', 'display_total']]) It’s a small structural change that makes a massive difference as projects scale. High-quality code isn't just about the output; it's about how easy it is for the next person (or "future me") to read and maintain. #Python #CleanCode #ProgrammingTips #DataScience #LearningToCode #SoftwareEngineering #Automation
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟲𝟳/𝟳𝟱 | 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝟳𝟱 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: 338. Counting Bits 𝗗𝗶𝗳𝗳𝗶𝗰𝘂𝗹𝘁𝘆: Easy 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝘂𝗺𝗺𝗮𝗿𝘆: Given an integer n, return an array where each index i (0 ≤ i ≤ n) contains the number of 1’s in the binary representation of i. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: This problem is solved efficiently using Dynamic Programming with bit manipulation. Instead of converting each number to binary separately, we reuse previously computed results. • Key Observation: – Right shifting a number (i >> 1) removes the last bit – (i & 1) tells whether the last bit is 1 or 0 • Transition: – ans[i] = ans[i >> 1] + (i & 1) This means: Take the count of 1’s from i/2 and add 1 if the current number is odd. • Base Case: – ans[0] = 0 • Final answer: – Array ans of size n + 1 This avoids repeated binary conversions and builds the solution in a bottom-up manner. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 𝗔𝗻𝗮𝗹𝘆𝘀𝗶𝘀: • Time Complexity: O(n) • Space Complexity: O(n) 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Problems involving binary representations often have patterns that can be reused. Bit manipulation + DP is a powerful combination for optimizing such computations. 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗟𝗶𝗻𝗸: https://lnkd.in/gydkB_rv #Day67of75 #LeetCode75 #DSA #Java #Python #DynamicProgramming #BitManipulation #MachineLearning #DataScience #ML #DataAnalyst #LearningInPublic #TechJourney #LeetCode
To view or add a comment, sign in
-
-
🔥 Day 140/360 – This Trick Generates All Subsets Instantly 🚀 Most people solve this using recursion… But today I learned how to generate all subsets using Bit Manipulation👇 📌 Topic: Bit Manipulation + Array 🧩 Problem: Subsets (Power Set) 📝 Problem Statement: Given an integer array, return all possible subsets (the power set). 🔍 Example: Input: [1, 2, 3] Output: [[], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3]] 💡 Approach: Bit Masking (Optimized) ✔ Step 1 – Calculate total subsets = 2ⁿ using (1 << n) ✔ Step 2 – Loop from 0 to 2ⁿ - 1 (each number represents a subset) ✔ Step 3 – Use bits to decide whether to include an element ⚡ Key Idea: Each number (mask) represents a subset in binary form. If a bit is ON → include that element. ⏱ Complexity: Time → O(n × 2ⁿ) Space → O(n × 2ⁿ) 📚 What I Learned: Bit manipulation can replace recursion in subset generation and makes the logic easier to visualize in binary. 🚀 Why This Matters: This concept is widely used in backtracking, DP, and interview problems. #DSA #Java #Coding #ProblemSolving #InterviewPrep #LeetCode #BitManipulation #TechJourney #140DaysOfCode
To view or add a comment, sign in
-
-
🚨 34 RAG techniques in one practical guide every Al developer should save today. ➡️A guidebook that breaks down **34 real RAG techniques** with Python examples, pros, cons, and use cases. If you are building Al apps, copilots, internal search, or support bots, this is worth your time. 1. Foundations (Start Here) *Basic RAG *Reliable RAG *RAG with CSV Files *Optimizing Chunk Sizes *Proposition Chunking 2. Better Queries & Better Context *Query Transformations *HYDE *HYPE *Contextual Chunk Headers *Semantic Chunking 3. Smarter Retrieval Layer *Fusion Retrieval * Reranking *Ensemble Retrieval *Hierarchical Indices *Multi-faceted Filtering 4. Long Context Efficiency *Relevant Segment Extraction * Context Window Enhancement *Contextual Compression * Document Augmentation * Dartboard Retrieval 5. Agentic & Iterative Systems * Agentic RAG with Contextual Al *Adaptive Retrieval *Iterative Retrieval *Retrieval with Feedback Loop * Sophisticated Controllable Agent 6. Advanced Architectures *Graph RAG with LangChain * Microsoft GraphRAG *RAPTOR * Self-RAG *Corrective RAG (CRAG) 7. Evaluation & Trust *DeepEval *GroUSE *Explainable Retrieval My biggest takeaway: Most teams stop at Basic RAG. The real gains come from retrieval quality, reranking, evaluation, and feedback loops. That is where production systems win.
To view or add a comment, sign in
-
Solving more problems doesn’t always make you better. Solving them the right way does. While practicing Data Structures & Algorithms, I realized that problem solving is not about writing code quickly - it’s about thinking clearly before coding. The best approach to problem solving: 1. Understand the problem deeply Before writing code, make sure you clearly understand: Input and output Constraints Edge cases 2. Start with brute force First think of the simplest solution, even if it’s not efficient. This helps in building the logic step by step. 3. Identify patterns Instead of solving each problem from scratch, ask: Is this Two Pointers? Sliding Window? Prefix Sum? Recognizing patterns saves time and effort. 4. Optimize step by step Once the brute force is clear, improve it: Reduce time complexity Avoid unnecessary space Use better data structures 5. Write clean and readable code Meaningful variable names Simple logic Minimal complexity 6. Review and learn After solving, revisit the problem: Can it be improved further? Is there a better approach? Focus on solving fewer problems - but understanding them deeply. This shift has made problem solving more structured and effective. Currently strengthening my skills in Python, Data Structures, and algorithm patterns. Consistent practice and the right approach will make a big difference. #DataStructures #Algorithms #DSA #Python #Coding #SoftwareEngineering #ProblemSolving #TechLearning
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟲𝟱/𝟳𝟱 | 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝟳𝟱 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: 72. Edit Distance 𝗗𝗶𝗳𝗳𝗶𝗰𝘂𝗹𝘁𝘆: Medium 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝘂𝗺𝗺𝗮𝗿𝘆: Given two strings word1 and word2, compute the minimum number of operations required to convert word1 into word2. Allowed operations: • Insert a character • Delete a character • Replace a character 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: This is a Dynamic Programming problem. • Define a 2D DP array where dp[i][j] represents the minimum operations needed to convert the first i characters of word1 to the first j characters of word2 • Initialization: – dp[i][0] = i → delete all characters – dp[0][j] = j → insert all characters • Transition: – If characters match: dp[i][j] = dp[i-1][j-1] – If characters differ: dp[i][j] = 1 + min( dp[i-1][j-1], // replace dp[i-1][j], // delete dp[i][j-1] // insert ) • Final answer: dp[m][n] This works because at each step, we choose the optimal operation among insert, delete, or replace based on previously computed subproblems. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 𝗔𝗻𝗮𝗹𝘆𝘀𝗶𝘀: • Time Complexity: O(m × n) • Space Complexity: O(m × n) 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: When transforming one string into another, think in terms of prefix transformations and build solutions bottom-up using DP. Problems involving string edits often reduce to comparing characters and choosing optimal operations. 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗟𝗶𝗻𝗸: https://lnkd.in/g8MzA3Rm #Day65of75 #LeetCode75 #DSA #Java #Python #DynamicProgramming #MachineLearning #DataScience #ML #DataAnalyst #LearningInPublic #TechJourney #LeetCode
To view or add a comment, sign in
-
-
Some problems are not about moving elements, but about understanding structure. Day 22/100 — Data Structures & Algorithms Journey Today’s Problem: Rotate List This problem helped me understand how linked lists behave when we manipulate their structure efficiently. Approach: Instead of rotating the list step by step (which is inefficient), I first calculated the length of the list. Then, I connected the tail to the head to form a circular linked list. By finding the correct breaking point using k % length, I was able to determine the new head and tail of the rotated list. At each step: Convert list into a circular structure Find the new tail position Break the circle to form the rotated list Key Takeaways: Understanding structure is more important than brute force Modulo operation helps avoid unnecessary rotations Linked list problems often become easier when visualized as cycles Efficient thinking leads to cleaner and faster solutions This problem strengthened my understanding of linked list manipulation and optimization techniques. #DSA #LeetCode #LinkedList #ProblemSolving #SoftwareEngineering #CodingJourney #100DaysOfCode #TechLearning #DeveloperJourney #Programming #Python #InterviewPreparation #CodingSkills #ComputerScience #FutureEngineer #TechCareers #SoftwareDeveloper #LearnInPublic #OpenToWork
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development