Day 92 of my #100DaysOfCode journey 🚀 Today I implemented Cycle Detection in an Undirected Graph using DFS. Earlier I solved this using BFS, and today I explored the DFS approach, which is equally important for interviews. Problem intuition: A cycle exists if during traversal we encounter a visited node that is not the parent. Approach: • Traverse all components of the graph • Use DFS (recursive traversal) • Keep track of the parent node • If a visited neighbor is found and it's not the parent → cycle detected Key insight: In undirected graphs: • Visiting parent again → normal • Visiting any other visited node → cycle Concepts reinforced: • DFS traversal on graphs • Recursion with parent tracking • Handling disconnected components Time Complexity: • O(V + E) Now I’ve covered cycle detection using both: • BFS (queue + parent tracking) • DFS (recursion + parent tracking) Understanding both approaches builds strong graph intuition and flexibility in problem-solving. Step by step, mastering graph patterns. 🌱 #100DaysOfCode #DSA #Graphs #DFS #CycleDetection #Algorithms #Python #CodingJourney #ProblemSolving #SoftwareEngineering
Implementing Cycle Detection in Undirected Graphs with DFS
More Relevant Posts
-
Day 93 of my #100DaysOfCode journey 🚀 Today I implemented Cycle Detection in an Undirected Graph using DFS. Earlier I solved this using BFS, and today I explored the DFS approach, which is equally important for interviews. Problem intuition: A cycle exists if during traversal we encounter a visited node that is not the parent. Approach: • Traverse all components of the graph • Use DFS (recursive traversal) • Keep track of the parent node • If a visited neighbor is found and it's not the parent → cycle detected Key insight: In undirected graphs: • Visiting parent again → normal • Visiting any other visited node → cycle Concepts reinforced: • DFS traversal on graphs • Recursion with parent tracking • Handling disconnected components Time Complexity: • O(V + E) Now I’ve covered cycle detection using both: • BFS (queue + parent tracking) • DFS (recursion + parent tracking) Understanding both approaches builds strong graph intuition and flexibility in problem-solving. Step by step, mastering graph patterns. 🌱 #100DaysOfCode #DSA #Graphs #DFS #CycleDetection #Algorithms #Python #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 30/100 — Solved “Maximum Depth of N-ary Tree” . today, A simple problem on the surface, but a great exercise to reinforce recursive thinking and traversal strategies. Approach 1: Depth-First Search (DFS) Used recursion to explore each branch of the tree as deep as possible. For every node, I computed the depth of all its children and took the maximum among them. The final answer for each node becomes 1 + max depth of its children. Base cases handled: If the node is null → depth = 0 If the node has no children → depth = 1 This approach is intuitive and closely follows the definition of depth itself. Approach 2: Breadth-First Search (BFS) Traversed the tree level by level using a queue. Each iteration processes one full level of nodes, and the depth counter increments after finishing each level. This approach is useful when thinking in terms of layers rather than paths. Complexity: Both approaches run in O(n) time since every node is visited once. Space complexity differs based on recursion depth (DFS) vs queue size (BFS). Key takeaway: Understanding both DFS and BFS gives flexibility in tackling tree problems from different perspectives—path-based vs level-based thinking. #Day30 #100DaysOfCode #DSA #LeetCode #Python #CodingJourney #Algorithms #DataStructures #ProblemSolving
To view or add a comment, sign in
-
-
Day 22/100 – DSA Journey Problem: Find Mode in Binary Search Tree (BST) Today’s problem focused on understanding how Binary Search Trees (BST) behave and how we can efficiently extract useful insights from them. Understanding the BST A Binary Search Tree follows a structured property: Left subtree → values ≤ root Right subtree → values ≥ root Because of this, when we perform an Inorder Traversal (Left → Root → Right), the values are visited in sorted order. Why Inorder Traversal? Since duplicates appear consecutively in a sorted sequence, inorder traversal allows us to: Track frequency without using extra space Compare current value with previous value Efficiently determine the most frequent element (mode) Approach Used Traverse the BST using inorder traversal Maintain: Previous value Current count Maximum frequency Update result list whenever a new maximum frequency is found Key Learning This problem highlights how leveraging tree properties can help optimize solutions. Instead of using extra space (like hashmaps), we used traversal behavior to achieve an efficient solution. Conclusion Understanding the underlying structure of data (like BST properties) is often more powerful than brute-force approaches. Smart traversal choices can significantly reduce space complexity and improve performance. #Day22 #100DaysOfCode #DSA #BinarySearchTree #Python #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Your dataset has 500 features. Your model only needs 20. The other 480 are noise, redundancy, or both — slowing down training and hurting accuracy. We broke down the 3 algorithms you actually need: Slide 1: PCA — linear, interpretable, fast. Your default. Slide 2: t-SNE — nonlinear, beautiful for visualization, slow on large data Slide 3: UMAP — modern, 10x faster than t-SNE, preserves local + global structure Slide 4: When to use which (decision tree with 4 questions) Slide 5: The common trap: t-SNE axes are NOT features. You can't use them as inputs to a model. Slide 6: Free notebook with all 3 on the same dataset — see the differences yourself Free notebook with side-by-side code for all three: https://lnkd.in/gcbS7m-m If you've been using PCA as a black box, this upgrades you. #MachineLearning #DataScience #PCA #UMAP #DimensionalityReduction #UnsupervisedLearning #Python #Sklearn
To view or add a comment, sign in
-
A Renko forecasting pipeline was tested on EURUSD using MetaTrader 5 tick/time-bar data converted into 11,578 Renko bars with ATR-derived brick size 0.00028. Training used 60 days of M5 history and 14 engineered features covering direction sequences and volume stats. CatBoost delivered 59.27% test accuracy. Feature importance was led by volume: last_volume (18.36), avg_volume (14.23), volume_ratio (12.81), followed by consecutive-move metrics, challenging price-pattern-heavy rule sets. Implementation stack: Python, numpy, pandas, MetaTrader5 API, catboost. Modules cover data ingest, Renko conversion, feature generation, cross-validated training, and probability-based signaling with a 75% confidence threshold. #MQL5 #MT5 #AlgoTrading #AITrading https://lnkd.in/dAGfEC7K
To view or add a comment, sign in
-
-
Day 14/100 – Data Structures & Algorithms Today, I worked on the problem “First Unique Character in a String.” Overview The task is to identify the first non-repeating character in a string and return its index. If no such character exists, the result is -1. Approach I used a two-pass strategy: • First pass to store character frequencies using a hashmap • Second pass to identify the first character with a frequency of one Complexity • Time Complexity: O(n) • Space Complexity: O(1) Key Takeaway This problem reinforces how effective hashmaps are for frequency-based problems and how a simple two-pass approach can lead to optimal solutions. Staying consistent and building problem-solving intuition step by step. #Day14 #100DaysOfCode #DSA #Python #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Every data project starts the same way: "What does this data actually look like?" This free notebook is a complete EDA framework: → Loading and initial inspection (shape, dtypes, head) → Summary statistics for numerical and categorical variables → Missing value analysis (patterns, not just counts) → Univariate analysis — distributions, histograms, value counts → Categorical variable exploration with visualizations → Outlier detection using statistical methods (IQR, z-scores) → Bivariate analysis — correlations, scatter plots, cross-tabs It's not theory. Every section has runnable code on a real dataset. Messy data, not textbook clean. This is the workflow I use on every single project. Free: https://lnkd.in/gecPBR9P Day 3/7. #DataCleaning #EDA #DataAnalyst #Python #Pandas #DataScience #ExploratoryDataAnalysis #FreeResources
To view or add a comment, sign in
-
𝐌𝐚𝐩𝐩𝐢𝐧𝐠 𝐌𝐲 𝐂𝐚𝐫 𝐓𝐫𝐢𝐩𝐬 – 𝐕𝐢𝐬𝐮𝐚𝐥𝐢𝐳𝐢𝐧𝐠 𝐚 𝐘𝐞𝐚𝐫 𝐨𝐟 𝐓𝐫𝐚𝐯𝐞𝐥 𝐏𝐚𝐭𝐡𝐬 𝐢𝐧 𝐏𝐲𝐭𝐡𝐨𝐧 Day 4 of the 2025 challenge comes with our own personal data this year, where I decided to visualize my own mobility data. In the tutorial, I will teach you how to: - Convert addresses to coordinates with OSM geocoding, - Generate road paths using a simple route planner, and - Visualize the results with vivid yellow lines on a dark basemap - a design that almost looks like a glowing electronic motherboard. 𝐖𝐚𝐥𝐤-𝐭𝐡𝐫𝐨𝐮𝐠𝐡 𝐨𝐧 𝐘𝐨𝐮𝐭𝐮𝐛𝐞: https://zurl.co/AeBfV 𝐂𝐨𝐝𝐞 𝐨𝐧 𝐒𝐮𝐛𝐬𝐭𝐚𝐜𝐤: https://zurl.co/E0J9c 𝐅𝐮𝐥𝐥 𝐜𝐨𝐮𝐫𝐬𝐞: https://zurl.co/vFaS3 #30DayMapChallenge #Python #GeospatialData #DataVisualization #Mapping #OSM #MobilityData #Commute #GIS
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 199 Problem: All Paths From Source to Target 🛣️📍 Today’s problem is a classic DFS + Backtracking question on Directed Acyclic Graphs (DAGs). 🧠 Problem Summary You are given: 👉 A DAG represented as an adjacency list graph 👉 Nodes labeled from 0 → n-1 🎯 Goal: Return all possible paths from: ➡️ Source node 0 ➡️ Target node n-1 💡 Key Insight Since the graph is a DAG: 👉 No cycles → safe to explore all paths using DFS This becomes a path generation problem. ⚙️ Approach 1️⃣ Use DFS (Depth First Search) 2️⃣ Maintain a current path list 3️⃣ Start from node 0 4️⃣ For each node: Add it to the path Explore all neighbors recursively 5️⃣ If you reach node n-1: ✅ Add the current path to result 6️⃣ Backtrack: Remove last node and explore other paths 📌 Why Backtracking? 👉 We reuse the same path list 👉 Undo choices after exploring each branch 📈 Complexity Time Complexity: O(2ⁿ × n) (in worst case) Space Complexity: O(n) (recursion stack) ✨ Why This Problem Is Important This problem builds a strong foundation in: 🔥 DFS traversal 🔥 Backtracking patterns 🔥 Path exploration in graphs 💡 Key Learnings: ➡️ DAG ensures no infinite loops ➡️ Backtracking helps explore all possibilities efficiently ➡️ Path problems = build → explore → undo This pattern appears in: ➡️ All root-to-leaf paths ➡️ Word Ladder variations ➡️ Path sum problems ➡️ Graph traversal with constraints 🔖 #DSA #100DaysOfCode #Day199 #DFS #Backtracking #Graphs #DAG #LeetCode #Algorithms #ProblemSolving #CodingChallenge #InterviewPrep #Python #SoftwareEngineering #DeveloperJourney #TechCommunity #CodingLife
To view or add a comment, sign in
-
-
🚀 𝗗𝗮𝘆 𝟯 : 𝗧𝗼𝗱𝗮𝘆 𝗜 𝗲𝘅𝗽𝗹𝗼𝗿𝗲𝗱 𝘀𝗼𝗺𝗲 𝗯𝗮𝘀𝗶𝗰 𝗯𝘂𝘁 𝘃𝗲𝗿𝘆 𝗶𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 𝗶𝗻 𝗣𝗮𝗻𝗱𝗮𝘀 𝗳𝗼𝗿 𝗱𝗮𝘁𝗮 𝘂𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 📊 🔍 1. head() Shows the first 5 rows of the dataset df.head() 🔍 2. tail() Shows the last 5 rows df.tail() 📏 3. shape Returns number of rows and columns df.shape ℹ️ 4. info() Provides summary of dataset (data types, null values) df.info() 📊 5. describe() Gives statistical summary (mean, min, max, etc.) df.describe() 📌 6. columns Shows all column names df.columns 💡 Key Learning: Understanding your dataset is the first step before doing any analysis. #Day3 #Pandas #Python #DataAnalytics #LearningJourney #DataExploration
To view or add a comment, sign in
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