layout: true class: typo, typo-selection --- count: false class: nord-dark, center, middle # Lexicographical order Wai-Shing Luk 2018-09-12 📅 --- What is Lexicographical order ----------------------------- - Given two partially ordered sets $A$ and $B$ - The lexicographical order on the Cartesian product $A \times B$ is defined as: - $(a,b) \le (a',b')$ iff $a < a'$ or ($a = a'$ and $b \le b'$). --- How ------- - `std::tuple<>` and `std::make_turple()` - `std::valarray<>` for vector space --- Properties ---------- - Preserve order (min, max, sorting) - Work with many algorithms in standard library: - `std::max_element()` - `std::sort()` - Triangle inequality - Dijkstra's algorithm - Convexity - duality - orthogonality --- Applications ------------ - break tie - leftmost point - plane sweeping - multiobjective optimization --- 📚 Example ----------- ```cpp template
struct Point { T _x, _y; }; template
ostream& operator<<(ostream& os, const Point
& p) { os << '(' << p._x << ", " << p._y << ')'; return os; } template
inline auto Leftmost(const std::vector
& P) { return std::min_element(std::begin(P), std::end(P), [](auto& p1, auto& p2){ // c++14 return tie(p1._x, p1._y) < tie(p2._x, p2._y); }); } ``` --- 📚 Example (cont'd) ---------------- ```cpp #include
#include
#include
#include
using namespace std; int main() { std::vector
> Poly = { {3, 4}, {5, -2}, {2, 10}, {8, 7}, {5, -9} }; std::cout << *Leftmost(Poly) << std::endl; } ``` --- class: nord-dark, center, middle # Q&A 🎤