File size: 2,287 Bytes
eca5751
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Algorithm Design Skill - Thiết kế thuật toán."""
from __future__ import annotations
from typing import List
from .base import Skill, SkillResult, SkillContext, SkillCategory, SkillPriority


class AlgorithmDesignSkill(Skill):
    """Thiết kế thuật toán: complexity analysis, optimization, data structure selection."""
    
    category = SkillCategory.REASONING
    priority = SkillPriority.MEDIUM
    keywords: List[str] = [
        "algorithm", "thuật toán", "complexity", "độ phức tạp",
        "big o", "big-o", "optimize", "tối ưu",
        "data structure", "cấu trúc dữ liệu", "sort", "sắp xếp",
        "search", "tìm kiếm", "graph", "đồ thị", "tree", "cây",
        "dynamic programming", "quy hoạch động",
    ]
    
    @property
    def name(self) -> str:
        return "algorithm_design"
    
    @property
    def description(self) -> str:
        return (
            "Thiết kế thuật toán: chọn data structure, phân tích complexity, "
            "optimize time/space, so sánh approaches, implement clean."
        )
    
    def execute(self, context: SkillContext) -> SkillResult:
        approaches = [
            "Brute force (baseline)",
            "Greedy algorithm",
            "Divide and conquer",
            "Dynamic programming",
            "Backtracking",
            "Branch and bound",
            "Graph algorithms (BFS, DFS, Dijkstra, A*)",
            "Two pointers / Sliding window",
            "Binary search",
            "Monotonic stack / queue",
            "Topological sort",
            "Union-Find (Disjoint Set)",
            "Segment tree / Fenwick tree",
            "Sparse table",
        ]
        return SkillResult(
            success=True,
            output=f"[AlgorithmDesign] Considering {len(approaches)} approaches.",
            metadata={
                "skill": self.name,
                "approaches": approaches,
                "complexity_targets": ["O(1)", "O(log n)", "O(n)", "O(n log n)", "O(n²)"],
            },
            suggestions=[
                "Start with brute force, then optimize",
                "Analyze time AND space complexity",
                "Consider edge cases (empty, single, large inputs)",
            ],
        )