Some problems are too complex to solve in one step, even with Chain of Thought. The solution? Break them down into smaller, manageable sub-problems. In this lesson, you’ll learn systematic decomposition strategies that transform overwhelming challenges into solvable pieces.
Problem: Write a function to find the longest palindromic substring in a string.Let's break this down from least to most complex:Sub-problem 1: How do we check if a string is a palindrome?Solution: Compare the string with its reverse, or check characters from both ends moving inward.Sub-problem 2: How do we generate all possible substrings?Solution: Use nested loops - outer loop for start position, inner loop for end position.Sub-problem 3: How do we find the longest among palindromic substrings?Solution: Track the longest palindrome found while checking each substring.Now, combining these solutions:def longest_palindrome(s): def is_palindrome(substr): return substr == substr[::-1] longest = "" for i in range(len(s)): for j in range(i + 1, len(s) + 1): substr = s[i:j] if is_palindrome(substr) and len(substr) > len(longest): longest = substr return longest
Key Insight: Each sub-problem is simpler than the original, and solving them in order builds toward the complete solution.
Problem: Plan a cross-country road trip from New York to Los Angeles with stops at national parks, staying within a $3000 budget for a family of 4.Let's decompose this from least to most complex:Sub-problem 1: What is the basic route from NY to LA?Answer: I-80 West is the most direct route, approximately 2,800 miles.Sub-problem 2: Which national parks are along or near this route?Answer: - Cuyahoga Valley (Ohio)- Indiana Dunes (Indiana)- Badlands (South Dakota)- Yellowstone (Wyoming)- Grand Teton (Wyoming)- Zion (Utah)- Death Valley (California)Sub-problem 3: How many days will this take?Answer: - Driving: ~40 hours = 5-6 driving days- Park visits: 1-2 days each × 7 parks = 7-14 days- Total: 12-20 days (let's plan for 14 days)Sub-problem 4: What are the major cost categories?Answer:- Gas: ~2,800 miles ÷ 25 mpg × $3.50/gallon = $392- Lodging: 13 nights × $100/night = $1,300- Food: 14 days × $150/day = $2,100- Park fees: ~$200- Total estimated: $3,992Sub-problem 5: How can we reduce costs to meet the $3000 budget?Answer:- Camp instead of hotels: Save $650 (7 nights camping at $30 vs $100)- Pack lunches: Save $400 (reduce food budget)- Skip 2 parks: Save $100 in fees and gas- Revised total: ~$2,942Final Plan:- Route: NY → Cuyahoga → Badlands → Yellowstone → Grand Teton → Zion → LA- Duration: 14 days- Lodging: Mix of camping (7 nights) and budget hotels (6 nights)- Budget: $2,942 (within $3000 limit)
Problem: [COMPLEX PROBLEM]Step 1: Identify the base case (simplest version)Step 2: Solve the base caseStep 3: Show how to build from simpler to more complexStep 4: Apply recursively to reach the solution
Problem: Solve Tower of Hanoi with 3 disks - move all disks from peg A to peg C using peg B.Let's decompose recursively:Base case: Moving 1 diskSolution: Simply move it from source to destinationRecursive case: Moving n disksSolution:1. Move (n-1) disks from source to auxiliary peg2. Move the largest disk from source to destination3. Move (n-1) disks from auxiliary to destinationFor 3 disks (A→C using B):Step 1: Move 2 disks from A to B (using C) - Move 1 disk from A to C - Move disk from A to B - Move 1 disk from C to BStep 2: Move largest disk from A to CStep 3: Move 2 disks from B to C (using A) - Move 1 disk from B to A - Move disk from B to C - Move 1 disk from A to CTotal moves: 7 (which equals 2³ - 1)
Main Question: [COMPLEX QUESTION]Let's break this into sub-questions:Q1: [SIMPLER QUESTION 1]A1: [ANSWER]Q2: [SIMPLER QUESTION 2]A2: [ANSWER]Q3: [SIMPLER QUESTION 3]A3: [ANSWER]Synthesizing answers:[COMBINE TO ANSWER MAIN QUESTION]
Main Question: Should our company invest in developing a mobile app?Let's break this into sub-questions:Q1: Who is our target audience and do they use mobile apps?A1: Our target audience is 25-45 year olds, 89% of whom use smartphones daily and spend average 3.5 hours on mobile apps.Q2: What problems would the app solve for our customers?A2: - Easier access to our services on-the-go- Push notifications for updates- Offline functionality- Faster checkout processQ3: What are the development and maintenance costs?A3:- Initial development: $50,000-$100,000- Annual maintenance: $15,000-$25,000- Marketing: $20,000 first yearQ4: What is the potential ROI?A4:- Expected new customers: 5,000 in year 1- Average customer value: $200/year- Revenue potential: $1,000,000- ROI: ~900% over 3 yearsQ5: What are the risks?A5:- Technical challenges- User adoption uncertainty- Ongoing maintenance commitment- Competition from existing appsSynthesizing answers:Given our mobile-active target audience, clear customer benefits, strong ROI potential ($1M revenue vs $100K investment), and manageable risks, we should invest in the mobile app. The data strongly supports this decision, with the primary risk being user adoption, which we can mitigate through targeted marketing.
Use when: The problem has natural sub-components or layersExample: “Design a complete e-commerce checkout flow” (cart → shipping → payment → confirmation)
Multi-Domain Problems
Use when: The problem spans multiple areas of expertiseExample: “Plan a product launch” (marketing + engineering + sales + support)
Sequential Dependencies
Use when: Later steps depend on earlier stepsExample: “Build a house” (foundation → framing → plumbing → electrical → finishing)
Overwhelming Complexity
Use when: The full problem is too complex to hold in working memoryExample: “Optimize a company’s entire supply chain”
Decompose this problem: “Design an algorithm to find the shortest path between two cities on a map.”
Sample Solution
Copy
Ask AI
Let's decompose from least to most complex:Sub-problem 1: How do we represent the map?Solution: Use a graph where cities are nodes and roads are weighted edges (weight = distance)Sub-problem 2: How do we find all possible paths?Solution: Use graph traversal (BFS or DFS) to explore pathsSub-problem 3: How do we track the shortest path?Solution: Keep track of the minimum distance to each nodeSub-problem 4: How do we handle the complete algorithm?Solution: Implement Dijkstra's algorithm:1. Initialize distances (start = 0, others = infinity)2. Use priority queue to process nodes by distance3. For each node, update distances to neighbors4. Continue until destination is reachedFinal algorithm: Dijkstra's shortest path algorithm
You are a project planning assistant. Help break down complex projects into manageable tasks.Project: [PROJECT DESCRIPTION]Step 1: Understand the GoalWhat is the ultimate objective?What defines success?Step 2: Identify Major PhasesBreak the project into 3-5 major phasesStep 3: Decompose Each PhaseFor each phase, list:- Key deliverables- Required resources- Dependencies- Estimated durationStep 4: Create Task ListBreak each phase into specific, actionable tasksStep 5: Determine Critical PathIdentify which tasks must be completed in sequenceStep 6: Allocate ResourcesAssign team members and resources to tasksStep 7: Create TimelineBuild a realistic schedule with milestonesOutput Format:- Project Overview- Phase Breakdown- Detailed Task List- Timeline with Milestones- Resource Allocation- Risk Assessment