Wai-Shing Luk

layout: true class: typo, typo-selection


class: nord-dark, middle, center

Lecture 2e: Algorithmic Paradigms

@luk036 πŸ‘¨β€πŸ’» Β· 2026 πŸ“…


Overview πŸ“‹


Algorithm Paradigms Flowchart

.mermaid[

graph TD
    A[Algorithmic Paradigms] --> B[Greedy Approach]
    A --> C[Mathematical Programming]
    A --> D[Primal-Dual Algorithm]
    A --> E[Randomized Method]
    A --> F[Dynamic Programming]
    A --> G[Local Search]
    A --> H[Simulated Annealing]
    style A fill:#2196f3,color:#fff
    style B fill:#4caf50,color:#fff
    style C fill:#ff9800,color:#fff
    style D fill:#9c27b0,color:#fff
    style E fill:#f44336,color:#fff
    style F fill:#2196f3,color:#fff
    style G fill:#4caf50,color:#fff
    style H fill:#ff9800,color:#fff

]


πŸ€‘ Greedy Approach


Knapsack πŸŽ’ Problem

.pull-left[

] .pull-right[

knapsack

]


πŸ€‘ Greedy Approach


Program 1: Greedy Knapsack


C++ code πŸ…’

template <class InputIt, typename T, typename F1, typename F2>
InputIt greedy_knapsack(InputIt first, InputIt last,
                        const T& b, F1&& price, F2&& weight)
{
    using Item = typename InputIt::value_type;
    std::sort(first, last, [&](const Item& i1, const Item& i2) {
        return weight(i1) * price(i2) < weight(i2) * price(i1);
    });
    T init(0);
    InputIt it = std::find_if(first, last, [&](Item& i) {
        return (init += weight(i)) > b;
    });
    return it;
}

Can the thief do better?


Linear Programming Relaxation


Weighted Vertex Cover


Program 2.6 Rounding WVC


Linear Programming


☯ Primal-dual WVC


☯ Primal-dual WVC


Program - Random WVC


🎲 Randomized Algorithms


Dynamic Programming (I)


Dynamic Programming (II)


Dynamic Programming (III)



Simulated Annealing


Other Heuristic Methods


πŸ“š Books and Online Resources


count: false class: nord-dark, middle, center

.pull-left[

Q&A 🎀

] .pull-right[

image

]