<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Subjects | Portfolio</title><link>https://ansangah.github.io/en/blog/subjects/</link><atom:link href="https://ansangah.github.io/en/blog/subjects/index.xml" rel="self" type="application/rss+xml"/><description>Subjects</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en</language><lastBuildDate>Mon, 20 Oct 2025 00:00:00 +0000</lastBuildDate><image><url>https://ansangah.github.io/media/sharing.png</url><title>Subjects</title><link>https://ansangah.github.io/en/blog/subjects/</link></image><item><title>Machine Learning</title><link>https://ansangah.github.io/en/blog/subjects/ml/</link><pubDate>Mon, 20 Oct 2025 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/ml/</guid><description>&lt;h2 id="1-introduction"&gt;1. Introduction&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Machine learning automatically learns patterns from data to make predictions or decisions.&lt;/li&gt;
&lt;li&gt;Main paradigms: supervised (classification/regression), unsupervised (clustering/dimensionality reduction), reinforcement learning.&lt;/li&gt;
&lt;li&gt;Key challenges: generalisation, data quality, computational efficiency, interpretability.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-formalising-inductive-machine-learning"&gt;2. Formalising Inductive Machine Learning&lt;/h2&gt;
&lt;h3 id="21-problem-setup"&gt;2.1 Problem Setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Assume input space $\mathcal{X}$, output space $\mathcal{Y}$, and an unknown data distribution $\mathcal{D}$.&lt;/li&gt;
&lt;li&gt;Training set $S={(x_i, y_i)}_{i=1}^{n}$ is drawn i.i.d. from $\mathcal{D}$.&lt;/li&gt;
&lt;li&gt;Goal: pick a hypothesis $h \in \mathcal{H}$ that minimises the &lt;strong&gt;risk&lt;/strong&gt;
$$R(h) = \mathbb{E}_{(x,y)\sim\mathcal{D}}[\ell(h(x), y)]$$
Since $\mathcal{D}$ is unknown, we minimise the &lt;strong&gt;empirical risk&lt;/strong&gt;
$$\hat{R}&lt;em&gt;S(h) = \frac{1}{n}\sum&lt;/em&gt;{i=1}^{n} \ell(h(x_i), y_i)$$
possibly with regularisation (RERM).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-inductive-bias"&gt;2.2 Inductive Bias&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The No Free Lunch theorem states no learner dominates across all distributions.&lt;/li&gt;
&lt;li&gt;We encode prior knowledge as &lt;strong&gt;bias&lt;/strong&gt; and learn the &lt;strong&gt;weights&lt;/strong&gt; from data.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-limits-of-learning-and-generalisation"&gt;3. Limits of Learning and Generalisation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;VC dimension:&lt;/strong&gt; Measures expressive power of $\mathcal{H}$ and bounds generalisation error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bias–variance trade-off:&lt;/strong&gt; Complex models have high variance; simple models incur high bias.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Overfitting:&lt;/strong&gt; Low training error but poor unseen performance. Mitigate with regularisation, early stopping, cross-validation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PAC learning:&lt;/strong&gt; Describes when a concept class is learnable—Probably Approximately Correct.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-geometry-and-nearest-neighbours"&gt;4. Geometry and Nearest Neighbours&lt;/h2&gt;
&lt;h3 id="41-distance-based-learning"&gt;4.1 Distance-Based Learning&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Represent data points as vectors in high-dimensional space and use a &lt;strong&gt;metric&lt;/strong&gt; to measure similarity.&lt;/li&gt;
&lt;li&gt;$k$-NN classification: majority vote among the $k$ closest labelled neighbours.&lt;/li&gt;
&lt;li&gt;$k$-NN regression: predict the (possibly weighted) average of the neighbours’ targets.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-properties"&gt;4.2 Properties&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Virtually zero training cost—just store the data—while inference is heavy.&lt;/li&gt;
&lt;li&gt;Distance metric choice matters: Euclidean, Manhattan, cosine, etc.&lt;/li&gt;
&lt;li&gt;Curse of dimensionality: distances become less informative; use dimensionality reduction or distance weighting.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-kernels-and-manifolds"&gt;4.3 Kernels and Manifolds&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Define nonlinear similarities with kernel functions to capture local structure.&lt;/li&gt;
&lt;li&gt;Manifold assumption: high-dimensional data may live on lower-dimensional surfaces—neighbourhood information remains meaningful.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-decision-tree-learning"&gt;5. Decision Tree Learning&lt;/h2&gt;
&lt;h3 id="51-structure"&gt;5.1 Structure&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Recursively split the feature space with questions. Leaves output predictions.&lt;/li&gt;
&lt;li&gt;Splitting criteria: information gain, Gini index, chi-squared tests.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-training-id3c45cart"&gt;5.2 Training (ID3/C4.5/CART)&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Choose the best attribute to split on.&lt;/li&gt;
&lt;li&gt;Recurse on child nodes.&lt;/li&gt;
&lt;li&gt;Stop when leaves are pure or the sample count hits thresholds.&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Continuous features use threshold-based binary splits.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="53-pruning"&gt;5.3 Pruning&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Pre-pruning: depth limits, minimum samples per node, etc.&lt;/li&gt;
&lt;li&gt;Post-pruning: build the full tree, then remove branches that raise validation error (e.g., reduced error pruning).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="54-pros-and-cons"&gt;5.4 Pros and Cons&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Interpretable, no need for feature scaling, handles nonlinearity.&lt;/li&gt;
&lt;li&gt;Sensitive to data splits and prone to overfitting → use ensembles (Random Forest, Gradient Boosting) for robustness.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-perceptron"&gt;6. Perceptron&lt;/h2&gt;
&lt;h3 id="61-linear-separator"&gt;6.1 Linear Separator&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Learns weights $w$ and bias $b$ to classify via $\text{sign}(w^\top x + b)$.&lt;/li&gt;
&lt;li&gt;Update rule for misclassified sample $(x,y)$:&lt;br&gt;
$w \leftarrow w + \eta y x$, $b \leftarrow b + \eta y$.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Perceptron convergence theorem:&lt;/strong&gt; If data is linearly separable, convergence occurs in finite steps.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="62-limitations"&gt;6.2 Limitations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Cannot solve nonlinearly separable problems (e.g., XOR) without kernels or multilayer networks.&lt;/li&gt;
&lt;li&gt;Sensitive to learning rate $\eta$ and sample order.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-practical-considerations"&gt;7. Practical Considerations&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Preprocessing:&lt;/strong&gt; Handle missing values and outliers, apply scaling, encode categorical features.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Evaluation:&lt;/strong&gt; Maintain train/validation/test splits; use k-fold CV or time-series CV as appropriate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Regularisation:&lt;/strong&gt; L1 encourages sparsity; L2 stabilises weights. Dropout, batch normalisation, etc., regulate neural nets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hyperparameter search:&lt;/strong&gt; Grid, random, or Bayesian optimisation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interpretability:&lt;/strong&gt; SHAP, LIME, and feature importance expose model behaviour.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="8-beyond-binary-classification"&gt;8. Beyond Binary Classification&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multiclass:&lt;/strong&gt; One-vs-rest, one-vs-one, softmax regression.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-label:&lt;/strong&gt; A sample may belong to multiple classes—use binary relevance, classifier chains, sigmoid outputs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Regression:&lt;/strong&gt; Predict continuous targets using linear regression, regression trees, Gaussian processes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Imbalanced data:&lt;/strong&gt; Apply class weighting, SMOTE, or cost-sensitive losses.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Structured outputs:&lt;/strong&gt; Sequence labelling with HMM/CRF, image segmentation with U-Net, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="9-linear-models"&gt;9. Linear Models&lt;/h2&gt;
&lt;h3 id="91-linear-regression"&gt;9.1 Linear Regression&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Fits $y \approx w^\top x + b$ via ordinary least squares.&lt;/li&gt;
&lt;li&gt;Regularisation: Ridge (L2), Lasso (L1), Elastic Net.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="92-logistic-regression"&gt;9.2 Logistic Regression&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Models binary probability with the sigmoid:
$$P(y=1|x) = \sigma(w^\top x + b) = \frac{1}{1 + e^{-(w^\top x + b)}}$$&lt;/li&gt;
&lt;li&gt;Train by maximising log-likelihood or minimising cross-entropy.&lt;/li&gt;
&lt;li&gt;Decision boundary is linear—extend with kernels or polynomial features for nonlinearity.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="93-softmax-regression"&gt;9.3 Softmax Regression&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;For $K$ classes,&lt;br&gt;
$\mathrm{softmax}(z)_k = \frac{e^{z_k}}{\sum_j e^{z_j}}$.&lt;/li&gt;
&lt;li&gt;Optimise with cross-entropy; works well with stochastic gradient descent.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="94-pros-and-cons"&gt;9.4 Pros and Cons&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Pros: explainable, fast to train, strong with high-dimensional sparse data.&lt;/li&gt;
&lt;li&gt;Cons: limited expressiveness for complex nonlinear relationships—upgrade with kernels or deep networks.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="10-suggested-learning-workflow"&gt;10. Suggested Learning Workflow&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Define the problem and capture domain knowledge.&lt;/li&gt;
&lt;li&gt;Clean and explore the data; engineer informative features.&lt;/li&gt;
&lt;li&gt;Establish baselines with simple models (linear, tree, k-NN).&lt;/li&gt;
&lt;li&gt;Decide on validation strategy and tune hyperparameters.&lt;/li&gt;
&lt;li&gt;Compare models on performance, interpretability, and operational cost.&lt;/li&gt;
&lt;li&gt;Deploy, monitor for drift, and retrain periodically.&lt;/li&gt;
&lt;/ol&gt;</description></item><item><title>Software Engineering</title><link>https://ansangah.github.io/en/blog/subjects/se/</link><pubDate>Fri, 17 Oct 2025 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/se/</guid><description>&lt;h2 id="1-overview"&gt;1. Overview&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Software engineering applies disciplined, systematic methods to build complex systems.&lt;/li&gt;
&lt;li&gt;Goals: deliver &lt;strong&gt;high-quality software&lt;/strong&gt; on predictable cost/schedule while keeping maintenance and evolution in mind.&lt;/li&gt;
&lt;li&gt;Pillars: &lt;strong&gt;Process&lt;/strong&gt;, &lt;strong&gt;Method&lt;/strong&gt;, &lt;strong&gt;Tooling&lt;/strong&gt;, and &lt;strong&gt;Quality&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-software-development-life-cycle-sdlc"&gt;2. Software Development Life Cycle (SDLC)&lt;/h2&gt;
&lt;h3 id="21-waterfall-requirements--design--implementation--verification--maintenance"&gt;2.1 Waterfall (Requirements → Design → Implementation → Verification → Maintenance)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Fully sequential. Works for contract-heavy or change-resistant projects.&lt;/li&gt;
&lt;li&gt;Pros: strong documentation, straightforward management.&lt;/li&gt;
&lt;li&gt;Cons: slow feedback, poor at absorbing requirement changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-iterative--incremental"&gt;2.2 Iterative &amp;amp; Incremental&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Repeated cycles of design/build/test deliver small increments and expose risk early.&lt;/li&gt;
&lt;li&gt;Examples: Spiral model (risk-driven), RUP, incremental delivery.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="23-agile"&gt;2.3 Agile&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Emphasises customer collaboration and rapid iteration: &lt;strong&gt;Scrum&lt;/strong&gt;, &lt;strong&gt;Kanban&lt;/strong&gt;, etc.&lt;/li&gt;
&lt;li&gt;Each sprint covers planning → development → review → retrospective.&lt;/li&gt;
&lt;li&gt;Prioritises working software over exhaustive documents, yet minimal artefacts are still maintained.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-requirements-engineering"&gt;3. Requirements Engineering&lt;/h2&gt;
&lt;h3 id="31-types"&gt;3.1 Types&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Functional:&lt;/strong&gt; behaviours and use cases the system must perform.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-functional:&lt;/strong&gt; performance, security, availability, compliance—quality attributes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Domain-specific:&lt;/strong&gt; rules tied to particular industries or organisations.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-elicitation-techniques"&gt;3.2 Elicitation Techniques&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Interviews, workshops, surveys, observation, prototyping.&lt;/li&gt;
&lt;li&gt;Agile-friendly user stories (“As a … I want … so that …”) capture intent.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-analysis--specification"&gt;3.3 Analysis &amp;amp; Specification&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Resolve conflicts, prioritise (MoSCoW, WSJF).&lt;/li&gt;
&lt;li&gt;Document with UML use-case diagrams, structured templates, and SRS documents.&lt;/li&gt;
&lt;li&gt;Govern changes via Change Control Boards and versioning.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-system-and-software-design"&gt;4. System and Software Design&lt;/h2&gt;
&lt;h3 id="41-architecture-design"&gt;4.1 Architecture Design&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Define structures to satisfy quality attributes.&lt;/li&gt;
&lt;li&gt;Patterns: layered, client–server, microservices, event-driven.&lt;/li&gt;
&lt;li&gt;Styles: REST, SOA, pipe-and-filter.&lt;/li&gt;
&lt;li&gt;Artefacts: C4 model diagrams, Architecture Decision Records (ADRs).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-detailed-design"&gt;4.2 Detailed Design&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Specify modules, classes, interfaces, and data structures.&lt;/li&gt;
&lt;li&gt;UML diagrams (class, sequence, state, activity).&lt;/li&gt;
&lt;li&gt;Principles: SOLID, dependency injection, GoF patterns (strategy, observer, factory, etc.).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-reuse"&gt;4.3 Reuse&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Leverage libraries, components, frameworks.&lt;/li&gt;
&lt;li&gt;Product line engineering derives variants from a shared asset base.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-project-planning-and-management"&gt;5. Project Planning and Management&lt;/h2&gt;
&lt;h3 id="51-estimation"&gt;5.1 Estimation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Use COCOMO II, Function Points, Story Points.&lt;/li&gt;
&lt;li&gt;Management artefacts: WBS, Gantt charts, Critical Path Method.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-risk-management"&gt;5.2 Risk Management&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Identify → analyse (probability/impact) → mitigate/avoid/transfer/accept.&lt;/li&gt;
&lt;li&gt;Focus on staffing, schedule, and technical uncertainties.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="53-configuration-management"&gt;5.3 Configuration Management&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Track versions of code, docs, build artefacts with Git/SVN.&lt;/li&gt;
&lt;li&gt;Adopt branching strategies (Git Flow, trunk-based) and peer reviews.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-implementation--quality-techniques"&gt;6. Implementation &amp;amp; Quality Techniques&lt;/h2&gt;
&lt;h3 id="61-coding-standards"&gt;6.1 Coding Standards&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Naming conventions, style guides (PEP8, Google style).&lt;/li&gt;
&lt;li&gt;Automate quality via linters, formatters, static analyzers.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="62-refactoring"&gt;6.2 Refactoring&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Improve structure without changing behaviour. Remove smells (long method, large class, feature envy).&lt;/li&gt;
&lt;li&gt;Use CI pipelines and regression tests to ensure safety.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="63-performance-tuning"&gt;6.3 Performance Tuning&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Profile to locate bottlenecks. Apply caching, async processing, data-structure optimisations.&lt;/li&gt;
&lt;li&gt;Reference models include Amdahl’s and Little’s laws.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-testing--qa"&gt;7. Testing &amp;amp; QA&lt;/h2&gt;
&lt;h3 id="71-test-levels"&gt;7.1 Test Levels&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Unit:&lt;/strong&gt; functions/classes, often TDD.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integration:&lt;/strong&gt; interactions between components.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;System:&lt;/strong&gt; end-to-end functional/non-functional checks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Acceptance:&lt;/strong&gt; confirm user needs (UAT).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="72-techniques"&gt;7.2 Techniques&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;White-box: path, branch coverage.&lt;/li&gt;
&lt;li&gt;Black-box: equivalence partitioning, boundary analysis.&lt;/li&gt;
&lt;li&gt;Static reviews: peer review, walkthrough, inspection.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="73-automation--cicd"&gt;7.3 Automation &amp;amp; CI/CD&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Frameworks: JUnit, pytest, Cypress.&lt;/li&gt;
&lt;li&gt;CI tools: GitHub Actions, Jenkins for build/test/deploy automation.&lt;/li&gt;
&lt;li&gt;Track coverage and quality gates (e.g., SonarQube).&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="8-operations-and-maintenance"&gt;8. Operations and Maintenance&lt;/h2&gt;
&lt;h3 id="81-maintenance-types"&gt;8.1 Maintenance Types&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Corrective:&lt;/strong&gt; fix defects.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adaptive:&lt;/strong&gt; respond to environment changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Perfective:&lt;/strong&gt; enhance performance/features.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Preventive:&lt;/strong&gt; eliminate latent issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="82-devops"&gt;8.2 DevOps&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Integrates development and operations with CI/CD, monitoring, IaC.&lt;/li&gt;
&lt;li&gt;Tooling: Docker, Kubernetes, Terraform, Prometheus, Grafana.&lt;/li&gt;
&lt;li&gt;Close feedback loop via logs, APM, feature flags.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="9-quality-models-and-standards"&gt;9. Quality Models and Standards&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ISO/IEC 25010:&lt;/strong&gt; functionality, reliability, usability, efficiency, maintainability, portability, security, compatibility.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CMMI:&lt;/strong&gt; organisational process maturity (levels 1–5).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ISO/IEC 12207:&lt;/strong&gt; software life-cycle processes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IEEE standards:&lt;/strong&gt; templates for SRS (IEEE 830), test documentation (IEEE 829), etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="10-tools-and-collaboration"&gt;10. Tools and Collaboration&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Requirements tracking: Jira, Azure DevOps, Trello.&lt;/li&gt;
&lt;li&gt;Documentation: Confluence, Notion, MkDocs; diagrams with PlantUML, Mermaid.&lt;/li&gt;
&lt;li&gt;Code collaboration: GitHub, GitLab; adopt PR reviews, pair/mob programming.&lt;/li&gt;
&lt;li&gt;Metrics: defect density, MTBF, defect discovery rate, lead time.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="11-ethics-and-professionalism"&gt;11. Ethics and Professionalism&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Follow ACM/IEEE codes of ethics.&lt;/li&gt;
&lt;li&gt;Address privacy, accessibility, algorithmic fairness, licence compliance.&lt;/li&gt;
&lt;li&gt;Conduct postmortems and root-cause analyses to foster organisational learning.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Databases</title><link>https://ansangah.github.io/en/blog/subjects/db/</link><pubDate>Wed, 30 Apr 2025 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/db/</guid><description>&lt;h2 id="1-database-normalization"&gt;1. Database Normalization&lt;/h2&gt;
&lt;h3 id="11-definition"&gt;1.1 Definition&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Normalization&lt;/strong&gt; decomposes relations so that only related attributes remain together, eliminating anomalies and redundancy.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="12-anomalies"&gt;1.2 Anomalies&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Insertion anomaly:&lt;/strong&gt; need to insert unrelated data to add a new fact.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Update anomaly:&lt;/strong&gt; modifying one duplicate tuple but not the others causes inconsistencies.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deletion anomaly:&lt;/strong&gt; removing a tuple unintentionally deletes valuable information.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;Normalization uses &lt;strong&gt;functional dependencies&lt;/strong&gt; to prevent these anomalies.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="2-functional-dependencies"&gt;2. Functional Dependencies&lt;/h2&gt;
&lt;h3 id="21-definition"&gt;2.1 Definition&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;In relation R, if attribute set $X$ determines $Y$, we denote $X \rightarrow Y$—tuples with the same $X$ must share the same $Y$.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-guidelines"&gt;2.2 Guidelines&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Derive dependencies from attribute semantics and business rules, not from sample data alone.&lt;/li&gt;
&lt;li&gt;Primary and candidate keys typically determine all other attributes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="23-full-functional-dependency"&gt;2.3 Full Functional Dependency&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;$X \rightarrow Y$ but no proper subset of $X$ determines $Y$.&lt;/li&gt;
&lt;li&gt;Indicates $Y$ depends on the entire composite key.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="24-partial-functional-dependency"&gt;2.4 Partial Functional Dependency&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;When $Y$ depends on only part of a composite key.&lt;/li&gt;
&lt;li&gt;Break such relations into 2NF to remove partial dependencies.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-normal-forms"&gt;3. Normal Forms&lt;/h2&gt;
&lt;h3 id="31-first-normal-form-1nf"&gt;3.1 First Normal Form (1NF)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;All attribute values are atomic (no repeating groups or arrays).&lt;/li&gt;
&lt;li&gt;Remove multi-valued attributes. If non-key attributes do not fully depend on the key, move to 2NF.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-second-normal-form-2nf"&gt;3.2 Second Normal Form (2NF)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;In 1NF and every non-key attribute is &lt;strong&gt;fully functionally dependent&lt;/strong&gt; on the primary key.&lt;/li&gt;
&lt;li&gt;Eliminates partial dependencies; composite-key relations may require decomposition.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-third-normal-form-3nf"&gt;3.3 Third Normal Form (3NF)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;In 2NF and no non-key attribute is &lt;strong&gt;transitively dependent&lt;/strong&gt; on the primary key (no $A \rightarrow B$, $B \rightarrow C$ implying $A \rightarrow C$ among non-keys).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="34-boycecodd-normal-form-bcnf"&gt;3.4 Boyce–Codd Normal Form (BCNF)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Stronger than 3NF: every determinant in a functional dependency is a candidate key.&lt;/li&gt;
&lt;li&gt;Needed when multiple candidate keys exist and 3NF still allows anomalies.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;Higher normal forms reduce redundancy but may increase join cost. Aim for a balance; 5NF is rarely necessary in practice.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id="35-lossless-decomposition--dependency-preservation"&gt;3.5 Lossless Decomposition &amp;amp; Dependency Preservation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Decompose relations without losing information and retain essential dependencies.&lt;/li&gt;
&lt;li&gt;Joining the decomposed tables must reconstruct the original data.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-views"&gt;4. Views&lt;/h2&gt;
&lt;h3 id="41-definition"&gt;4.1 Definition&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;view&lt;/strong&gt; is a virtual table defined by a SELECT query over base tables. It stores no data, providing abstraction, reuse, and security.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-syntax"&gt;4.2 Syntax&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;CREATE&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;VIEW&lt;/span&gt; view_name [(column_list)]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;AS&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;SELECT&lt;/span&gt; ...
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[&lt;span style="color:#66d9ef"&gt;WITH&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;CHECK&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;OPTION&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WITH CHECK OPTION&lt;/code&gt; enforces view predicates during DML operations.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ORDER BY&lt;/code&gt; is not allowed inside view definitions; apply ordering when querying the view.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-dml-restrictions"&gt;4.3 DML Restrictions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;View updates propagate to base tables only when:
&lt;ol&gt;
&lt;li&gt;key and NOT NULL columns are present,&lt;/li&gt;
&lt;li&gt;no aggregates, DISTINCT, GROUP BY, or UNION,&lt;/li&gt;
&lt;li&gt;simple single-table views.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Dropping a view leaves base tables intact, but drop dependent constraints first.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="44-benefits"&gt;4.4 Benefits&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Simplify complex queries.&lt;/li&gt;
&lt;li&gt;Provide column-level access control.&lt;/li&gt;
&lt;li&gt;Maintain logical independence when base schema changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-indexing"&gt;5. Indexing&lt;/h2&gt;
&lt;h3 id="51-what--why"&gt;5.1 What &amp;amp; Why&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;An index is a data structure that enables &lt;strong&gt;fast record retrieval&lt;/strong&gt;—most RDBMSs use B+ Trees (sometimes hashes).&lt;/li&gt;
&lt;li&gt;Conceptually stores key-value pairs (key → record address).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-how-it-works"&gt;5.2 How It Works&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Look up the search key in the index.&lt;/li&gt;
&lt;li&gt;Follow the pointer to fetch the record, avoiding full table scans and reducing complexity to O(log n).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="53-design-considerations"&gt;5.3 Design Considerations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Best for selective predicates, frequent sorting/grouping, join keys, read-heavy workloads.&lt;/li&gt;
&lt;li&gt;Caveats: maintenance cost on INSERT/UPDATE/DELETE, functions/casts may prevent usage, low selectivity columns yield little benefit.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="54-clustered-vs-nonclustered"&gt;5.4 Clustered vs. Nonclustered&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Clustered index:&lt;/strong&gt; table rows are stored in index order (e.g., InnoDB primary key).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nonclustered index:&lt;/strong&gt; separate structure points to the actual data pages.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-triggers"&gt;6. Triggers&lt;/h2&gt;
&lt;h3 id="61-concept"&gt;6.1 Concept&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Stored routines that fire automatically in response to events (DML, DDL, login).&lt;/li&gt;
&lt;li&gt;Enforce integrity rules, record audit logs, maintain derived values.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="62-types"&gt;6.2 Types&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;BEFORE&lt;/strong&gt; triggers: execute prior to the event—validate or adjust values.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AFTER&lt;/strong&gt; triggers: run post-event—log or cascade changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;INSTEAD OF&lt;/strong&gt; triggers: mainly for views; intercept operations and apply custom logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="63-cautions"&gt;6.3 Cautions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Complex trigger chains can hurt performance or cause recursion.&lt;/li&gt;
&lt;li&gt;Failures roll back the entire transaction—add proper exception handling.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-stored-procedures"&gt;7. Stored Procedures&lt;/h2&gt;
&lt;h3 id="71-definition"&gt;7.1 Definition&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Precompiled SQL code stored in the database; accepts parameters to automate recurring tasks.&lt;/li&gt;
&lt;li&gt;Executes on the server, reducing network trips and centralising business logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="72-example"&gt;7.2 Example&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;CREATE&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;PROCEDURE&lt;/span&gt; proc_name(&lt;span style="color:#66d9ef"&gt;IN&lt;/span&gt; p INT, &lt;span style="color:#66d9ef"&gt;OUT&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;result&lt;/span&gt; VARCHAR(&lt;span style="color:#ae81ff"&gt;50&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;BEGIN&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;-- SQL statements
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;END&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;Invoke with &lt;code&gt;CALL proc_name(value, @out);&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="73-pros--cons"&gt;7.3 Pros &amp;amp; Cons&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Pros: reusable, secure (permission-controlled), potential performance gains.&lt;/li&gt;
&lt;li&gt;Cons: higher complexity, tricky version control and testing, DBMS vendor lock-in.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="74-procedure-vs-function"&gt;7.4 Procedure vs. Function&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Functions must return a value and can appear inside SELECT queries.&lt;/li&gt;
&lt;li&gt;Procedures may omit a return value, use OUT parameters, and manage transactions.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="8-transactions"&gt;8. Transactions&lt;/h2&gt;
&lt;h3 id="81-definition"&gt;8.1 Definition&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;transaction&lt;/strong&gt; is a logical unit of work that groups multiple SQL statements. Commit all if successful, otherwise roll back to maintain consistency.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="82-acid-properties"&gt;8.2 ACID Properties&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Atomicity:&lt;/strong&gt; all-or-nothing execution.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistency:&lt;/strong&gt; preserves integrity constraints.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isolation:&lt;/strong&gt; concurrent transactions do not interfere.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durability:&lt;/strong&gt; committed changes survive failures.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="83-isolation-levels"&gt;8.3 Isolation Levels&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Read Uncommitted:&lt;/strong&gt; allows dirty reads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Read Committed:&lt;/strong&gt; prevents dirty reads (default in many systems).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Repeatable Read:&lt;/strong&gt; guarantees repeatable reads; prevents non-repeatable reads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Serializable:&lt;/strong&gt; equivalent to serial execution; safest but slowest.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="84-concurrency-control"&gt;8.4 Concurrency Control&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Locks (shared/exclusive, two-phase locking), optimistic control, timestamp ordering, MVCC.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="85-design-tips"&gt;8.5 Design Tips&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Keep transactions short to avoid deadlocks and lock contention.&lt;/li&gt;
&lt;li&gt;Common pattern: &lt;code&gt;BEGIN; ...; COMMIT;&lt;/code&gt; with &lt;code&gt;ROLLBACK;&lt;/code&gt; on errors.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="9-production-checklist"&gt;9. Production Checklist&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Balance normalization and denormalization according to read/write patterns.&lt;/li&gt;
&lt;li&gt;Maintain only necessary indexes and review usage statistics regularly.&lt;/li&gt;
&lt;li&gt;Include logging and error handling in triggers/procedures for auditability.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Operating Systems</title><link>https://ansangah.github.io/en/blog/subjects/os/</link><pubDate>Wed, 30 Apr 2025 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/os/</guid><description>&lt;h2 id="1-history-and-concepts"&gt;1. History and Concepts&lt;/h2&gt;
&lt;h3 id="11-batch-processing"&gt;1.1 Batch Processing&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Early OSes executed a single job at a time with no user intervention.&lt;/li&gt;
&lt;li&gt;Operators manually queued jobs; the next job started only after the previous finished.&lt;/li&gt;
&lt;li&gt;Idle CPU time abounded while waiting for I/O, making computation inefficient.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="12-limitations-of-batch"&gt;1.2 Limitations of Batch&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;CPU idle time:&lt;/strong&gt; Fast CPUs waited for slow I/O devices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slow job switching:&lt;/strong&gt; Manual intervention delayed the transition between jobs.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="13-spooling-fixes-issue-1"&gt;1.3 Spooling (Fixes Issue 1)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Buffers I/O so computation and device work overlap.&lt;/li&gt;
&lt;li&gt;Example: printer spooling—documents are queued on disk; printers fetch at their own pace while the CPU continues other work.&lt;/li&gt;
&lt;li&gt;Benefit: CPU need not stall for I/O completion.&lt;/li&gt;
&lt;li&gt;Caveat: If the program depends immediately on I/O results (e.g., &lt;code&gt;read()&lt;/code&gt;), spooling alone cannot help.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="14-automatic-job-sequencing-fixes-issue-2"&gt;1.4 Automatic Job Sequencing (Fixes Issue 2)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Scheduling software automatically loads the next job as soon as the previous one finishes.&lt;/li&gt;
&lt;li&gt;Improves throughput compared with manual batching.&lt;/li&gt;
&lt;li&gt;Requires &lt;strong&gt;multiprogramming&lt;/strong&gt; to keep multiple jobs resident in memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="15-multiprogramming--time-sharing"&gt;1.5 Multiprogramming &amp;amp; Time Sharing&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Multiple jobs reside in memory; CPU switches to another while the current one waits for I/O.&lt;/li&gt;
&lt;li&gt;FCFS plus priority-based policies balance fairness.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time sharing:&lt;/strong&gt; CPU time is sliced so each job sees frequent progress. Heavy context switching gives the illusion of concurrency but adds overhead.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-os-and-computer-system-structure"&gt;2. OS and Computer-System Structure&lt;/h2&gt;
&lt;h3 id="21-four-components"&gt;2.1 Four Components&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Hardware:&lt;/strong&gt; CPU, memory, I/O devices provide raw resources.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operating System:&lt;/strong&gt; Arbitrates resource access among programs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application Programs:&lt;/strong&gt; Decide how resources are used to satisfy user tasks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Users:&lt;/strong&gt; People or other systems interacting with the computer.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="22-bus-architecture"&gt;2.2 Bus Architecture&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Early machines used a single bus—CPU, memory, I/O shared one channel—causing bottlenecks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hierarchical dual-bus&lt;/strong&gt; design emerged:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;System bus:&lt;/strong&gt; connects fast CPU/memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;I/O bus:&lt;/strong&gt; connects slower peripherals.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Northbridge:&lt;/strong&gt; controller for high-speed devices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Southbridge:&lt;/strong&gt; handles slower devices and legacy ports.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-execution-modes-user-vs-kernel"&gt;3. Execution Modes: User vs. Kernel&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;CPUs provide at least two privilege levels for system protection.&lt;/li&gt;
&lt;li&gt;Each mode controls which instructions and memory regions are accessible.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="31-kernel-mode"&gt;3.1 Kernel Mode&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Privileged; OS services, drivers, and resource managers run here with full hardware access.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-user-mode"&gt;3.2 User Mode&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Restricted; applications cannot execute privileged instructions and must request services via the OS.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-mode-switching"&gt;3.3 Mode Switching&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;System calls, interrupts, and traps flip the mode bit and jump into kernel handlers.&lt;/li&gt;
&lt;li&gt;After handling, control returns to user mode at the interrupted point.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-cpu-event-handling"&gt;4. CPU Event Handling&lt;/h2&gt;
&lt;h3 id="41-hardware-interrupts"&gt;4.1 Hardware Interrupts&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Asynchronous events from devices.&lt;/li&gt;
&lt;li&gt;Sequence: save context → jump to ISR → perform service → restore context → resume execution.&lt;/li&gt;
&lt;li&gt;Priorities decide which interrupts pre-empt others; keep ISRs short.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-traps-software-interrupts"&gt;4.2 Traps (Software Interrupts)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Synchronous events within a program: e.g., divide-by-zero, system calls.&lt;/li&gt;
&lt;li&gt;Trigger a switch to kernel mode but may reuse existing context without full saving.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-io-device-components"&gt;4.3 I/O Device Components&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Bus:&lt;/strong&gt; data, address, and control lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Device registers:&lt;/strong&gt; control, status, input, output; mapped to memory for CPU access.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Controller:&lt;/strong&gt; intermediates between devices and buses, arbitrating use.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-device-access-methods"&gt;5. Device Access Methods&lt;/h2&gt;
&lt;h3 id="51-io-instructions"&gt;5.1 I/O Instructions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU-specific instructions communicate directly with devices.&lt;/li&gt;
&lt;li&gt;Non-portable because instruction sets differ.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-memory-mapped-io"&gt;5.2 Memory-Mapped I/O&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Maps device registers into the main address space so ordinary loads/stores access hardware.&lt;/li&gt;
&lt;li&gt;Improves portability and programming simplicity.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-io-completion-techniques"&gt;6. I/O Completion Techniques&lt;/h2&gt;
&lt;h3 id="61-polling"&gt;6.1 Polling&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU repeatedly checks device status.&lt;/li&gt;
&lt;li&gt;Fast response for quick devices but wastes CPU cycles when waiting.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="62-interrupt-driven-io"&gt;6.2 Interrupt-Driven I/O&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU continues other tasks until a device interrupts to signal completion.&lt;/li&gt;
&lt;li&gt;Saves busy-wait time but incurs context-switch overhead and may delay detection of very fast events.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;&lt;strong&gt;Rule of thumb:&lt;/strong&gt; Fast devices favour polling; slower ones benefit from interrupts.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="7-data-transfer-methods"&gt;7. Data Transfer Methods&lt;/h2&gt;
&lt;h3 id="71-programmed-io"&gt;7.1 Programmed I/O&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU performs all data movement; expensive for large transfers.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="72-direct-memory-access-dma"&gt;7.2 Direct Memory Access (DMA)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A DMA controller transfers data between memory and devices on behalf of the CPU.&lt;/li&gt;
&lt;li&gt;Process: CPU issues command → DMA moves data → completion interrupt notifies CPU.&lt;/li&gt;
&lt;li&gt;Pros: frees CPU cycles; excels for high-volume transfers.&lt;/li&gt;
&lt;li&gt;Cons: additional hardware cost and possible bus contention.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="8-os-design-considerations"&gt;8. OS Design Considerations&lt;/h2&gt;
&lt;h3 id="81-general-vs-special-purpose"&gt;8.1 General vs. Special Purpose&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;General-purpose OSes serve diverse workloads; special-purpose OSes target embedded, real-time, or appliance scenarios.&lt;/li&gt;
&lt;li&gt;Balancing performance, fairness, and reliability requires deliberate trade-offs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="82-layering-vs-modularity"&gt;8.2 Layering vs. Modularity&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Layering:&lt;/strong&gt; strict top-down structure; upper layers use lower-layer services only.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modularity:&lt;/strong&gt; independent components communicate through explicit interfaces; freer ordering but demands dependency management.&lt;/li&gt;
&lt;li&gt;Modern OSes blend both: layered architecture populated with modular subsystems for stability and extensibility.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="9-kernel-structures-and-system-calls"&gt;9. Kernel Structures and System Calls&lt;/h2&gt;
&lt;h3 id="91-system-calls--mode-switch"&gt;9.1 System Calls &amp;amp; Mode Switch&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;User code invokes an API → generates a trap → CPU enters kernel mode → trap handler executes → returns to user mode.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="92-parameter-passing"&gt;9.2 Parameter Passing&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Registers:&lt;/strong&gt; fastest but few parameters fit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory blocks:&lt;/strong&gt; store arguments in memory and pass the address.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stack:&lt;/strong&gt; push arguments in user mode; kernel pops them.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="93-monolithic-kernel"&gt;9.3 Monolithic Kernel&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;All kernel services share one address space.&lt;/li&gt;
&lt;li&gt;Pros: minimal overhead for cross-service calls.&lt;/li&gt;
&lt;li&gt;Cons: tightly coupled; a faulty module can crash the entire kernel.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="94-address-spaces"&gt;9.4 Address Spaces&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Define accessible address ranges. Sharing the same space allows direct referencing; separate spaces reinforce protection boundaries.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="95-microkernel"&gt;9.5 Microkernel&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Decomposes services into user-space servers communicating via IPC.&lt;/li&gt;
&lt;li&gt;Pros: low coupling, easy maintenance, unload unused services.&lt;/li&gt;
&lt;li&gt;Cons: frequent address-space switches and IPC overhead can hurt performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="96-hybrid-kernel"&gt;9.6 Hybrid Kernel&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Real-world kernels typically combine monolithic cores with loadable modules or user-space servers, balancing performance and flexibility.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Computer Networks</title><link>https://ansangah.github.io/en/blog/subjects/cn/</link><pubDate>Tue, 15 Apr 2025 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/cn/</guid><description>&lt;h2 id="chapter-1-introduction"&gt;Chapter 1. Introduction&lt;/h2&gt;
&lt;h3 id="11-evolution-of-data-networks"&gt;1.1 Evolution of Data Networks&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Consider &lt;strong&gt;commercial viability&lt;/strong&gt;, &lt;strong&gt;line installation cost&lt;/strong&gt; (very high), and relatively cheaper equipment.&lt;/li&gt;
&lt;li&gt;Evaluate whether new technologies can reuse existing infrastructure.
&lt;ul&gt;
&lt;li&gt;Success: xDSL leveraged telephone lines for broadband.&lt;/li&gt;
&lt;li&gt;Failure: 1970s video phones—insufficient demand relative to infrastructure cost.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Modems convert digital ↔ analogue signals so legacy phone lines can transport data.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="12-development-path"&gt;1.2 Development Path&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Telcos gradually expanded data services while keeping the telephone backbone.&lt;/li&gt;
&lt;li&gt;Phone number ↔ IP mapping allowed voice-over-IP on regular lines, though with lower audio quality.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="13-internet--isps"&gt;1.3 Internet &amp;amp; ISPs&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ISPs&lt;/strong&gt; (e.g., KT, SKT) provide network access.&lt;/li&gt;
&lt;li&gt;Hierarchical topology: local ISPs → backbone ISPs → global backbones connected via peering/transit.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="chapter-19-host-to-host-delivery"&gt;Chapter 19. Host-to-Host Delivery&lt;/h2&gt;
&lt;h3 id="21-osi-seven-layers-quick-review"&gt;2.1 OSI Seven Layers (Quick Review)&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Physical:&lt;/strong&gt; signal transmission.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Link:&lt;/strong&gt; MAC, error detection, hop-to-hop delivery.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Network:&lt;/strong&gt; routing, addressing, multicast, ARP.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transport:&lt;/strong&gt; TCP/UDP for end-to-end reliability.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Session&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Presentation&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application:&lt;/strong&gt; HTTP, DNS, etc. (Labs typically focus on layers 4–7.)&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="22-network-layer-roles"&gt;2.2 Network Layer Roles&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Internetworking:&lt;/strong&gt; connects heterogeneous networks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Addressing:&lt;/strong&gt; assigns globally unique identifiers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Routing:&lt;/strong&gt; chooses optimal paths.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Packetizing:&lt;/strong&gt; encapsulates upper-layer data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fragmenting:&lt;/strong&gt; splits packets to respect MTU limits.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="23-switching"&gt;2.3 Switching&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Circuit switching:&lt;/strong&gt; dedicated path (telephone network).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Packet switching:&lt;/strong&gt; best-effort, store-and-forward (Internet).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="24-datagram-service"&gt;2.4 Datagram Service&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Connectionless: each packet is routed independently.&lt;/li&gt;
&lt;li&gt;Packets may arrive out of order; TCP reorders and handles flow control.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="chapter-19-ipv4-addressing-and-subnets"&gt;Chapter 19. IPv4 Addressing and Subnets&lt;/h2&gt;
&lt;h3 id="31-address-classes"&gt;3.1 Address Classes&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;32-bit addresses must be unique and universally routable.&lt;/li&gt;
&lt;li&gt;Classful ranges:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Class A:&lt;/strong&gt; 0xxxxxxx (0–127), NetID 7 bits, HostID 24 bits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Class B:&lt;/strong&gt; 10xxxxxx (128–191), NetID 14 bits, HostID 16 bits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Class C:&lt;/strong&gt; 110xxxxx (192–223), NetID 21 bits, HostID 8 bits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Class D:&lt;/strong&gt; 1110xxxx (224–239), multicast.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Class E:&lt;/strong&gt; 1111xxxx (240–255), reserved for experiments.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Special addresses: &lt;code&gt;-.0.0.0&lt;/code&gt; (network), &lt;code&gt;-.0.0.1&lt;/code&gt; (gateway), &lt;code&gt;-.255.255.255&lt;/code&gt; (broadcast).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-subnetting"&gt;3.2 Subnetting&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Partition large networks into manageable subnets to improve organisation and security.&lt;/li&gt;
&lt;li&gt;Use bitwise AND: IP &amp;amp; subnet mask = subnet address.&lt;/li&gt;
&lt;li&gt;CIDR enables flexible, classless allocation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-dhcp"&gt;3.3 DHCP&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Dynamically assigns IP configuration. Sequence: Discover → Offer → Request → ACK.&lt;/li&gt;
&lt;li&gt;Mitigates address exhaustion; well-suited for mobile devices.&lt;/li&gt;
&lt;li&gt;Combine with NAT to hide private addresses.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="34-nat"&gt;3.4 NAT&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Translates private ↔ public addresses so many hosts share one public IP.&lt;/li&gt;
&lt;li&gt;PAT (port address translation) differentiates sessions.&lt;/li&gt;
&lt;li&gt;External access requires port forwarding or static public IPs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="35-ip-datagram"&gt;3.5 IP Datagram&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;TTL decrements at each router; packet discarded at zero to avoid loops.&lt;/li&gt;
&lt;li&gt;Fragmentation splits packets exceeding link MTU; reassembly happens at the final destination.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="chapter-20-network-layer-protocols"&gt;Chapter 20. Network Layer Protocols&lt;/h2&gt;
&lt;h3 id="41-arp"&gt;4.1 ARP&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Resolves IP addresses to MAC addresses within the same subnet.&lt;/li&gt;
&lt;li&gt;Request sent via broadcast; reply delivered as unicast. Results cached.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-ip"&gt;4.2 IP&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Minimum 20-byte header with version, header length, TTL, protocol, checksum, etc.&lt;/li&gt;
&lt;li&gt;Protocol field multiplexes upper-layer protocols (TCP=6, UDP=17, OSPF=89, &amp;hellip;).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-fragmentation--mtu"&gt;4.3 Fragmentation &amp;amp; MTU&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Routers split packets when downstream MTU is smaller.&lt;/li&gt;
&lt;li&gt;DF (Don’t Fragment) flag forbids splitting, prompting ICMP errors instead.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="44-icmp"&gt;4.4 ICMP&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Reports network-layer errors and diagnostic information.&lt;/li&gt;
&lt;li&gt;Error messages: Destination Unreachable, (deprecated) Source Quench, Time Exceeded, Parameter Problem, Redirect.&lt;/li&gt;
&lt;li&gt;Query messages: Echo (ping), Timestamp, etc.&lt;/li&gt;
&lt;li&gt;ICMP only reports problems—flow and congestion control live elsewhere.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="45-ipv6-overview"&gt;4.5 IPv6 Overview&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;128-bit address space, simplified header, richer QoS support.&lt;/li&gt;
&lt;li&gt;Address notation uses 16-bit hex blocks with &lt;code&gt;::&lt;/code&gt; compression.&lt;/li&gt;
&lt;li&gt;Transition strategies:
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Dual Stack&lt;/strong&gt; (run IPv4 &amp;amp; IPv6 simultaneously).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tunnelling&lt;/strong&gt; (encapsulate IPv6 in IPv4).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Header Translation&lt;/strong&gt; (convert headers; may lose info like flow labels).&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="chapter-21-unicast--multicast-routing"&gt;Chapter 21. Unicast &amp;amp; Multicast Routing&lt;/h2&gt;
&lt;h3 id="51-routing-types"&gt;5.1 Routing Types&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Unicast:&lt;/strong&gt; one-to-one (default Internet traffic).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multicast:&lt;/strong&gt; one-to-many (group members only).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Broadcast:&lt;/strong&gt; one-to-all (limited in IPv4).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anycast:&lt;/strong&gt; one-to-nearest (e.g., DNS root replicas).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-overlay-networks"&gt;5.2 Overlay Networks&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Logical networks built atop the physical Internet (e.g., CDNs).&lt;/li&gt;
&lt;li&gt;Reduce load when delivering identical media streams.&lt;/li&gt;
&lt;li&gt;New services must weigh overlay benefits against cost.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="53-unicast-protocols"&gt;5.3 Unicast Protocols&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;RIP:&lt;/strong&gt; distance vector, hop-count metric—small networks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OSPF:&lt;/strong&gt; link-state—large enterprise networks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BGP:&lt;/strong&gt; path vector—inter-AS routing on the global Internet.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="54-multicast-routing"&gt;5.4 Multicast Routing&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Hosts join/leave groups via IGMP.&lt;/li&gt;
&lt;li&gt;Routers build multicast trees to forward only along necessary links.&lt;/li&gt;
&lt;li&gt;Protocols include PIM (protocol-independent multicast) variants.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="chapter-22-security-fundamentals"&gt;Chapter 22. Security Fundamentals&lt;/h2&gt;
&lt;h3 id="61-http-security"&gt;6.1 HTTP Security&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Basic auth:&lt;/strong&gt; Base64 username/password—susceptible to eavesdropping.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Digest auth:&lt;/strong&gt; adds hashing yet still vulnerable (no server authentication, MITM).&lt;/li&gt;
&lt;li&gt;Real-world solution: HTTPS via SSL/TLS to encrypt the transport layer.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="62-secure-email"&gt;6.2 Secure Email&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Requirements: &lt;strong&gt;confidentiality&lt;/strong&gt;, &lt;strong&gt;authentication&lt;/strong&gt;, &lt;strong&gt;integrity&lt;/strong&gt;, &lt;strong&gt;non-repudiation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Encryption approaches:
&lt;ul&gt;
&lt;li&gt;Symmetric keys (fast but key distribution is hard).&lt;/li&gt;
&lt;li&gt;Public/private keys (PGP combines both).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Strong passphrases should be long, unpredictable, yet memorable.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="63-public-key-validation"&gt;6.3 Public-Key Validation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Certificate Authorities (CA):&lt;/strong&gt; trusted third parties issue certificates binding public keys to identities. Certificates include serials, subject/issuer info, validity, signatures.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PGP Web of Trust:&lt;/strong&gt; decentralised—users vouch for one another; keys have validity and trust scores.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="64-transport-layer-security"&gt;6.4 Transport-Layer Security&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;SSL/TLS:&lt;/strong&gt; negotiate session keys, encrypt data, authenticate endpoints. HTTPS = HTTP over TLS.&lt;/li&gt;
&lt;li&gt;Drawback: handshake incurs public-key operations and latency.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="65-network-layer-security-ipsec"&gt;6.5 Network-Layer Security (IPsec)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Provides tunnelling, encryption, and integrity between routers or hosts.&lt;/li&gt;
&lt;li&gt;Protocols: &lt;strong&gt;ESP&lt;/strong&gt; (encryption + authentication) and &lt;strong&gt;AH&lt;/strong&gt; (authentication + integrity only).&lt;/li&gt;
&lt;li&gt;Modes: transport (end-to-end) and tunnel (network-to-network).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="66-vpn"&gt;6.6 VPN&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Emulates a private network over the public Internet.&lt;/li&gt;
&lt;li&gt;Comparison:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Leased line:&lt;/strong&gt; secure but expensive.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hybrid:&lt;/strong&gt; mix of private lines and Internet.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;VPN:&lt;/strong&gt; IPsec tunnel mode balances cost and security.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-summary--study-tips"&gt;7. Summary &amp;amp; Study Tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Analyse cost vs. benefit when reusing existing infrastructure versus deploying new tech.&lt;/li&gt;
&lt;li&gt;Practise subnetting and CIDR to design addressing plans.&lt;/li&gt;
&lt;li&gt;Compare routing protocols (RIP/OSPF/BGP) and match them to network scale.&lt;/li&gt;
&lt;li&gt;Security spans multiple layers: application (HTTPS) → transport (TLS) → network (IPsec).&lt;/li&gt;
&lt;li&gt;Use packet-analyser tools (Wireshark) to observe ARP, ICMP, DHCP, TLS handshakes and solidify understanding.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Algorithms</title><link>https://ansangah.github.io/en/blog/subjects/algorithm/</link><pubDate>Thu, 10 Oct 2024 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/algorithm/</guid><description>&lt;h2 id="1-overview"&gt;1. Overview&lt;/h2&gt;
&lt;p&gt;This note compiles the key concepts covered in an undergraduate algorithms course. Use it to refresh important ideas quickly and to understand how the individual topics are connected.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="2-sorting-algorithms"&gt;2. Sorting Algorithms&lt;/h2&gt;
&lt;p&gt;Sorting is the preparatory step for many problems. When choosing an algorithm, consider input size, data distribution, auxiliary space, and whether stability (preserving the order of equal keys) matters.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Average Time&lt;/th&gt;
&lt;th&gt;Worst Time&lt;/th&gt;
&lt;th&gt;Extra Space&lt;/th&gt;
&lt;th&gt;Highlights&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Merge Sort&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;Stable; great for external sorting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Quick Sort&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(log n)&lt;/td&gt;
&lt;td&gt;Divide and conquer; pivot choice is critical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Selection Sort&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Few swaps but generally slow; unstable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bubble Sort&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Simple; fast on nearly sorted data with early exit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Insertion Sort&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Excellent for small or nearly sorted arrays; stable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Radix Sort&lt;/td&gt;
&lt;td&gt;O(d·n)&lt;/td&gt;
&lt;td&gt;O(d·n)&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;Digit-wise; bypasses comparisons&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Counting/Bucket Sort&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;Strong when value range is small or uniform&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id="21-merge-sort"&gt;2.1 Merge Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Recursively splits the array and merges the sorted halves.&lt;/li&gt;
&lt;li&gt;Stable because equal keys retain their relative order.&lt;/li&gt;
&lt;li&gt;Drawbacks: needs extra memory and incurs recursion overhead.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-quick-sort"&gt;2.2 Quick Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Partitions around a pivot into smaller and larger elements and recurses.&lt;/li&gt;
&lt;li&gt;Typically the fastest in practice, but degenerates to O(n²) on sorted data unless you randomise or choose smart pivots (median-of-three, etc.).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="23-selection-sort"&gt;2.3 Selection Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Repeatedly selects the minimum (or maximum) remaining element and swaps it into place.&lt;/li&gt;
&lt;li&gt;Swap count is limited to O(n), but the algorithm is mainly pedagogical due to its O(n²) comparisons.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="24-bubble-sort"&gt;2.4 Bubble Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Repeatedly swaps adjacent elements that are out of order so the largest “bubbles” to the end.&lt;/li&gt;
&lt;li&gt;Each pass places one element; adding a flag for “already sorted” speeds up nearly sorted inputs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="25-insertion-sort"&gt;2.5 Insertion Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Inserts each element into the correct position within the already sorted prefix.&lt;/li&gt;
&lt;li&gt;Stable and efficient for tiny datasets or partially ordered inputs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="26-radix-sort"&gt;2.6 Radix Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Sorts integers or fixed-length strings digit by digit: LSD (least significant digit first) or MSD (most significant digit first).&lt;/li&gt;
&lt;li&gt;Requires a stable subroutine (e.g., counting sort) to guarantee global stability.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="27-counting--bucket-sort"&gt;2.7 Counting &amp;amp; Bucket Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Counting sort achieves O(n + k) for small value range k; bucket sort achieves expected O(n) when inputs are uniformly distributed.&lt;/li&gt;
&lt;li&gt;Both need extra memory and require advance knowledge of the key range.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-trees-red-black-trees"&gt;3. Trees: Red-Black Trees&lt;/h2&gt;
&lt;p&gt;Red-black trees are balanced binary search trees that maintain O(log n) height by enforcing colour-based invariants.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invariants:&lt;/strong&gt;&lt;br&gt;
(1) Every node is red or black.&lt;br&gt;
(2) The root and NIL leaves are black.&lt;br&gt;
(3) Red nodes have black children.&lt;br&gt;
(4) Every path from a node to its descendant NIL nodes contains the same number of black nodes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operations:&lt;/strong&gt;&lt;br&gt;
Insert like a BST, then fix colours/rotations. Delete by replacing with a successor and resolving the “double black” case.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Why use them:&lt;/strong&gt; Fewer rotations than AVL trees, making them practical when inserts/deletes are frequent.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Examples:&lt;/strong&gt; &lt;code&gt;std::map&lt;/code&gt;, &lt;code&gt;std::set&lt;/code&gt;, Java &lt;code&gt;TreeMap&lt;/code&gt;, Linux CFS scheduler.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-hash-tables"&gt;4. Hash Tables&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Hash a key to an array index so average lookup/insertion/deletion becomes O(1).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collision:&lt;/strong&gt; When multiple keys hash to the same bucket. Quality of the hash function and load factor (n/m) dictate performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="41-collision-resolution-strategies"&gt;4.1 Collision-Resolution Strategies&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Separate chaining:&lt;/strong&gt; Linked lists or dynamic arrays per bucket. Simple and flexible, but needs pointer storage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Open addressing:&lt;/strong&gt; Probe for the next empty slot (linear, quadratic probing, double hashing). Cache-friendly, yet suffers from clustering.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rehashing:&lt;/strong&gt; Enlarge the table when the load factor exceeds a threshold and reinsert all entries.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="42-design-tips"&gt;4.2 Design Tips&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Aim for a hash function that distributes keys evenly, is fast to compute, and resists adversarial input.&lt;/li&gt;
&lt;li&gt;For concurrent scenarios, look into lock-free buckets, striped locks, or partitioned tables.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-graph-algorithms"&gt;5. Graph Algorithms&lt;/h2&gt;
&lt;p&gt;Graphs model networks, dependency orders, and relationships. Sparse graphs typically use adjacency lists; dense graphs favour adjacency matrices.&lt;/p&gt;
&lt;h3 id="51-topological-sort"&gt;5.1 Topological Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Produces a linear order of a DAG’s prerequisites.&lt;/li&gt;
&lt;li&gt;Implement via Kahn’s algorithm (in-degree queue) or DFS finishing times; both detect cycles when sorting fails.&lt;/li&gt;
&lt;li&gt;Useful for course prerequisites, build systems, and task scheduling.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-bellmanford-algorithm"&gt;5.2 Bellman–Ford Algorithm&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Handles graphs with negative edge weights to find single-source shortest paths.&lt;/li&gt;
&lt;li&gt;Runs |V|−1 relaxations and checks for updates on the |V|th iteration to detect negative cycles.&lt;/li&gt;
&lt;li&gt;Critical for routing protocols such as RIP where Dijkstra cannot be applied.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="53-pebble-game"&gt;5.3 Pebble Game&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Places “pebbles” on DAG nodes to study computation order and resource usage.&lt;/li&gt;
&lt;li&gt;Helps derive lower bounds for register allocation, memory minimisation, and proof complexity.&lt;/li&gt;
&lt;li&gt;Solving the optimal pebbling strategy is challenging beyond restricted graph classes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="54-additional-highlights"&gt;5.4 Additional Highlights&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;DFS/BFS:&lt;/strong&gt; Core search routines; basis for connectivity, cycle detection, and topological sort.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strongly Connected Components:&lt;/strong&gt; Kosaraju’s or Tarjan’s algorithms condense graphs into DAGs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Minimum Spanning Tree:&lt;/strong&gt; Kruskal and Prim minimise connection cost in undirected weighted graphs.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-string-matching-rabinkarp"&gt;6. String Matching: Rabin–Karp&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Uses a rolling hash to compare the pattern hash with substrings of the text.&lt;/li&gt;
&lt;li&gt;Offers expected O(n + m) time; collisions trigger explicit substring comparisons.&lt;/li&gt;
&lt;li&gt;Particularly handy for multi-pattern search after precomputing pattern hashes.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-study-tips"&gt;7. Study Tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Implement algorithms and analyse both average and worst cases using your own test datasets.&lt;/li&gt;
&lt;li&gt;Visualise algorithm steps with tools such as VisuAlgo or CS Academy.&lt;/li&gt;
&lt;li&gt;In coding interviews or contests, inspect input bounds and memory constraints before choosing a strategy.&lt;/li&gt;
&lt;li&gt;Suggested reading: &lt;em&gt;CLRS&lt;/em&gt;, Sedgewick’s &lt;em&gt;Algorithms&lt;/em&gt;, and &lt;em&gt;Problem Solving with Algorithms and Data Structures&lt;/em&gt; by Miller &amp;amp; Ranum.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Data Mining</title><link>https://ansangah.github.io/en/blog/subjects/dm/</link><pubDate>Tue, 16 Apr 2024 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/dm/</guid><description>&lt;h2 id="1-overview"&gt;1. Overview&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Data mining extracts &lt;strong&gt;meaningful patterns and knowledge&lt;/strong&gt; from massive datasets.&lt;/li&gt;
&lt;li&gt;Pipeline: data cleaning → feature construction → modelling/pattern discovery → evaluation &amp;amp; visualisation.&lt;/li&gt;
&lt;li&gt;Algorithms must account for the “4 V’s” of big data: volume, variety, velocity, veracity.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-frequent-itemset-mining"&gt;2. Frequent Itemset Mining&lt;/h2&gt;
&lt;h3 id="21-concepts"&gt;2.1 Concepts&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Identify sets of items that co-occur in transaction data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Support:&lt;/strong&gt; fraction of transactions containing itemset $X$&lt;br&gt;
$$\mathrm{support}(X) = \frac{#\text{transactions containing }X}{#\text{all transactions}}$$&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Confidence:&lt;/strong&gt; probability that $Y$ appears when $X$ does in rule $X \rightarrow Y$.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lift:&lt;/strong&gt; $ \frac{P(X,Y)}{P(X)P(Y)}$ measures how much more often $X$ and $Y$ appear together than by independence.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-apriori-algorithm"&gt;2.2 Apriori Algorithm&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Top-down&lt;/strong&gt; search that grows larger frequent itemsets from smaller ones.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Apriori principle:&lt;/strong&gt; if an itemset is not frequent, none of its supersets can be frequent.&lt;/li&gt;
&lt;li&gt;Steps:
&lt;ol&gt;
&lt;li&gt;Generate candidate 1-itemsets and compute support.&lt;/li&gt;
&lt;li&gt;Keep itemsets above the minimum support threshold.&lt;/li&gt;
&lt;li&gt;Combine survivors to form $(k+1)$-item candidates.&lt;/li&gt;
&lt;li&gt;Repeat until no more frequent sets remain.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Limitation: repeated data scans and huge candidate sets.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="23-fp-growth"&gt;2.3 FP-Growth&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Compress transactions into an &lt;strong&gt;FP-tree&lt;/strong&gt; without candidate generation.&lt;/li&gt;
&lt;li&gt;Process: order items by support → insert transactions into the tree sharing prefixes → build conditional FP-trees recursively.&lt;/li&gt;
&lt;li&gt;Requires less I/O than Apriori and scales well to large datasets.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="24-association-rules"&gt;2.4 Association Rules&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Split each frequent itemset into antecedent/consequent pairs to form rule candidates.&lt;/li&gt;
&lt;li&gt;Filter by support, confidence, lift, etc.&lt;/li&gt;
&lt;li&gt;Applications: recommendation, market-basket analysis, intrusion detection.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-similar-item-search-locality-sensitive-hashing-lsh"&gt;3. Similar Item Search: Locality-Sensitive Hashing (LSH)&lt;/h2&gt;
&lt;h3 id="31-problem"&gt;3.1 Problem&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Quickly find &lt;strong&gt;similar objects&lt;/strong&gt; in very large datasets (duplicate documents, image search, record linkage).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-core-idea"&gt;3.2 Core Idea&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Design hash families so that &lt;strong&gt;similar items collide with high probability&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Choose hash functions according to similarity metrics:
&lt;ul&gt;
&lt;li&gt;Jaccard → MinHash&lt;/li&gt;
&lt;li&gt;Cosine → Random hyperplane&lt;/li&gt;
&lt;li&gt;$L_p$ distance → $p$-stable hashes&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-minhash-with-banding"&gt;3.3 MinHash with Banding&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Represent documents as sets and build MinHash signatures (minimum values of multiple hash functions).&lt;/li&gt;
&lt;li&gt;Split the signature matrix into $b$ bands of $r$ rows; hash each band to buckets.&lt;/li&gt;
&lt;li&gt;If two signatures match in any band, treat them as a candidate pair and compute exact similarity.&lt;/li&gt;
&lt;li&gt;Adjust $(r, b)$ to balance false negatives (more bands) vs. false positives (more rows).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="34-lsh-pipeline"&gt;3.4 LSH Pipeline&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Preprocess data into sets or vectors.&lt;/li&gt;
&lt;li&gt;Generate LSH signatures.&lt;/li&gt;
&lt;li&gt;Extract candidate pairs.&lt;/li&gt;
&lt;li&gt;Compute exact distances and return top-$k$ or threshold matches.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h2 id="4-clustering"&gt;4. Clustering&lt;/h2&gt;
&lt;h3 id="41-essentials"&gt;4.1 Essentials&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Discover &lt;strong&gt;natural groupings&lt;/strong&gt; in unlabeled data.&lt;/li&gt;
&lt;li&gt;Objectives: maximise intra-cluster similarity and minimise inter-cluster similarity.&lt;/li&gt;
&lt;li&gt;Distance metrics: Euclidean, cosine, Hamming, DTW, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-k-means"&gt;4.2 K-means&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Classic algorithm for roughly spherical clusters.&lt;/li&gt;
&lt;li&gt;Procedure: choose $K$ centres (random or k-means++), assign points to nearest centre, recompute centres, repeat until convergence.&lt;/li&gt;
&lt;li&gt;Watch out for $K$ selection (elbow, silhouette), sensitivity to outliers, and initial seeds.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-hierarchical-clustering"&gt;4.3 Hierarchical Clustering&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Builds a &lt;strong&gt;dendrogram&lt;/strong&gt; based on pairwise distances.&lt;/li&gt;
&lt;li&gt;Agglomerative (bottom-up): start with singletons and merge clusters using linkage criteria (single, complete, average, Ward).&lt;/li&gt;
&lt;li&gt;Divisive (top-down): start with all points and split recursively.&lt;/li&gt;
&lt;li&gt;Cut the tree at a chosen level to obtain the desired number of clusters.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="44-density-based-clustering"&gt;4.4 Density-Based Clustering&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;DBSCAN/HDBSCAN treat dense regions as clusters and sparse areas as noise.&lt;/li&gt;
&lt;li&gt;Parameters: radius $\varepsilon$ and minimum points MinPts.&lt;/li&gt;
&lt;li&gt;Captures arbitrarily shaped clusters and automatically flags outliers.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-community-detection-in-graphs"&gt;5. Community Detection in Graphs&lt;/h2&gt;
&lt;h3 id="51-definition"&gt;5.1 Definition&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Partition a graph into subgraphs with &lt;strong&gt;dense internal connections&lt;/strong&gt; and sparse external ones.&lt;/li&gt;
&lt;li&gt;Use cases: social networks, recommendation engines, biological networks.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-modularity"&gt;5.2 Modularity&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Measures the difference between intra-cluster and inter-cluster edge density.&lt;/li&gt;
&lt;li&gt;Louvain/Leiden algorithms greedily maximise modularity for large graphs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="53-spectral-clustering"&gt;5.3 Spectral Clustering&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Uses eigenvectors of the graph Laplacian to embed nodes into a low-dimensional space.&lt;/li&gt;
&lt;li&gt;Workflow: build adjacency matrix $W$, degree matrix $D$, compute normalised Laplacian $L = D^{-1/2}(D-W)D^{-1/2}$, take the smallest $k$ eigenvectors, and run k-means.&lt;/li&gt;
&lt;li&gt;Handles nonlinear structures and non-spherical clusters.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="54-comparison"&gt;5.4 Comparison&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Modularity optimisation is fast but subject to resolution limits.&lt;/li&gt;
&lt;li&gt;Spectral methods are more costly (eigen decomposition) yet yield high-quality partitions.&lt;/li&gt;
&lt;li&gt;Choose based on graph size, sparsity, and runtime constraints.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-dimensionality-reduction"&gt;6. Dimensionality Reduction&lt;/h2&gt;
&lt;h3 id="61-motivation"&gt;6.1 Motivation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;High-dimensional data worsens computation, visualisation, and the curse of dimensionality.&lt;/li&gt;
&lt;li&gt;Dimensionality reduction keeps as much information as possible while compressing representation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="62-principal-component-analysis-pca"&gt;6.2 Principal Component Analysis (PCA)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Eigen-decompose the covariance matrix to find directions of maximal variance.&lt;/li&gt;
&lt;li&gt;Steps: standardise data → compute covariance → eigenvalues/vectors → project onto top-$k$ components.&lt;/li&gt;
&lt;li&gt;Linear, orthogonal transform that preserves maximum variance; sensitive to nonlinearity/outliers.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="63-linear-discriminant-analysis-lda"&gt;6.3 Linear Discriminant Analysis (LDA)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Maximises between-class variance while minimising within-class variance.&lt;/li&gt;
&lt;li&gt;Supervised dimensionality reduction; boosts classification performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="64-nonlinear-techniques"&gt;6.4 Nonlinear Techniques&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;t-SNE: excellent for local structure visualisation, but distorts global layout.&lt;/li&gt;
&lt;li&gt;UMAP: faster than t-SNE with better global preservation.&lt;/li&gt;
&lt;li&gt;Autoencoders: neural networks that learn nonlinear embeddings.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="65-working-with-lshclustering"&gt;6.5 Working with LSH/Clustering&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Reduce dimensionality first to improve LSH efficiency and denoise features.&lt;/li&gt;
&lt;li&gt;Applying PCA before clustering often yields higher silhouette scores.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-project-tips"&gt;7. Project Tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Prioritise data quality: handle missing values, detect outliers, and scale appropriately.&lt;/li&gt;
&lt;li&gt;Evaluation metrics:
&lt;ul&gt;
&lt;li&gt;Frequent patterns: support, confidence, lift, conviction, Kulczynski, etc.&lt;/li&gt;
&lt;li&gt;Clustering/community detection: silhouette, Davies–Bouldin, modularity.&lt;/li&gt;
&lt;li&gt;Dimensionality reduction: reconstruction error, downstream model accuracy.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Visualise results with heatmaps, correlation matrices, network graphs, and 2D embeddings (PCA, t-SNE).&lt;/li&gt;
&lt;li&gt;In practice, LSH is just a candidate generator—always follow up with precise distance checks.&lt;/li&gt;
&lt;li&gt;Document your pipeline and tuning experiments to ensure reproducibility.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Data Structures</title><link>https://ansangah.github.io/en/blog/subjects/ds/</link><pubDate>Mon, 15 Apr 2024 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/ds/</guid><description>&lt;h2 id="1-overview"&gt;1. Overview&lt;/h2&gt;
&lt;p&gt;Data structures organise information in memory and on disk so that algorithms can run efficiently. When solving problems, consider both the abstract data type (what operations are supported) and the concrete implementation (time/space trade-offs).&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="2-arrays-and-wrapper-classes"&gt;2. Arrays and Wrapper Classes&lt;/h2&gt;
&lt;h3 id="21-arrays"&gt;2.1 Arrays&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Traits:&lt;/strong&gt; Contiguous memory, O(1) random access by index.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limitations:&lt;/strong&gt; Fixed size; mid-array insert/delete costs O(n) shifts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use cases:&lt;/strong&gt; Cache-friendly for numerical computing, DP tables, game state loops.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-class-wrappers"&gt;2.2 Class Wrappers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Wrapping arrays inside classes adds safety features such as bounds checking, dynamic resizing, and iterators.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;std::vector&lt;/code&gt; (C++) and &lt;code&gt;ArrayList&lt;/code&gt; (Java) double their capacity when full, yielding amortised O(1) append operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-stack-and-queue"&gt;3. Stack and Queue&lt;/h2&gt;
&lt;h3 id="31-stack"&gt;3.1 Stack&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Last-in-first-out (LIFO). Underpins call stacks, delimiter checking, DFS backtracking.&lt;/li&gt;
&lt;li&gt;Core ops: &lt;code&gt;push&lt;/code&gt;, &lt;code&gt;pop&lt;/code&gt;, &lt;code&gt;top&lt;/code&gt;. Implementable with arrays or linked lists.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-queue"&gt;3.2 Queue&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;First-in-first-out (FIFO). Used in BFS, job scheduling, buffering.&lt;/li&gt;
&lt;li&gt;Core ops: &lt;code&gt;enqueue&lt;/code&gt;, &lt;code&gt;dequeue&lt;/code&gt;, &lt;code&gt;front&lt;/code&gt;. Circular arrays eliminate index wrap-around.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-deque"&gt;3.3 Deque&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Inserts and deletes on both ends. Handy for sliding windows and monotonic queues.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-pointers-and-linked-lists"&gt;4. Pointers and Linked Lists&lt;/h2&gt;
&lt;h3 id="41-pointers"&gt;4.1 Pointers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Store memory addresses and reference dynamically allocated objects.&lt;/li&gt;
&lt;li&gt;Beware of null dereferences, dangling pointers, and double frees.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-singly-linked-list"&gt;4.2 Singly Linked List&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Nodes store &lt;code&gt;(data, next)&lt;/code&gt;. Inserts/deletes run in O(1); random access takes O(n).&lt;/li&gt;
&lt;li&gt;Techniques: head insertion, tail pointer maintenance, sentinel (dummy) heads.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-doubly-linked-list"&gt;4.3 Doubly Linked List&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Each node keeps &lt;code&gt;prev&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt;, enabling bidirectional traversal.&lt;/li&gt;
&lt;li&gt;Useful for LRU caches and editors. Twice as many pointer updates—test carefully.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-list-abstract-data-type"&gt;5. List Abstract Data Type&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;List ADTs define ordered collections; performance depends on implementation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic array list:&lt;/strong&gt; O(1) indexing, O(n) mid-insert/delete.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Linked list:&lt;/strong&gt; O(1) insert/delete (with references), O(n) search; cursor iterators help frequent traversals.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-recursion"&gt;6. Recursion&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Functions call themselves to break a problem into smaller cases.&lt;/li&gt;
&lt;li&gt;Essential elements: &lt;strong&gt;base case&lt;/strong&gt;, &lt;strong&gt;recursive relation&lt;/strong&gt;, and &lt;strong&gt;state propagation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Watch call-stack depth; tail recursion can often be transformed into iteration.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-trees"&gt;7. Trees&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Hierarchical, acyclic structures branching from a root.&lt;/li&gt;
&lt;li&gt;Terminology: depth, height, degree, subtree.&lt;/li&gt;
&lt;li&gt;Traversals: preorder, inorder, postorder, level-order—implemented via recursion or queues.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="8-binary-search-tree-bst"&gt;8. Binary Search Tree (BST)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Maintains the invariant left subtree &amp;lt; root &amp;lt; right subtree.&lt;/li&gt;
&lt;li&gt;Average O(log n) lookup/insert/delete; skewed trees degrade to O(n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Balancing options:&lt;/strong&gt; AVL, red-black tree, treap, splay tree—guarantee logarithmic height.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="9-priority-queue"&gt;9. Priority Queue&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Stores elements with priorities; retrieves the highest (or lowest) priority element.&lt;/li&gt;
&lt;li&gt;Typically implemented with heaps: &lt;code&gt;insert&lt;/code&gt; and &lt;code&gt;extract&lt;/code&gt; in O(log n), &lt;code&gt;peek&lt;/code&gt; in O(1).&lt;/li&gt;
&lt;li&gt;Applications: Dijkstra’s algorithm, schedulers, event simulation, running medians.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="10-graphs"&gt;10. Graphs&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Comprised of vertices (V) and edges (E). Consider direction, multiedges, self-loops.&lt;/li&gt;
&lt;li&gt;Representations:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Adjacency list:&lt;/strong&gt; O(V + E) space—ideal for sparse graphs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adjacency matrix:&lt;/strong&gt; O(V²) space—constant-time edge existence checks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Traversals: DFS (stack/recursion) and BFS (queue) underpin connectivity, topological order, and cycle detection.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="11-weighted-graphs"&gt;11. Weighted Graphs&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Each edge carries a cost. Models maps, networks, logistics.&lt;/li&gt;
&lt;li&gt;Single-source shortest paths: Dijkstra (non-negative weights), Bellman–Ford (with negatives), SPFA (practical improvements).&lt;/li&gt;
&lt;li&gt;All-pairs shortest paths: Floyd–Warshall (O(V³)), Johnson’s algorithm (sparse graphs).&lt;/li&gt;
&lt;li&gt;Minimum spanning tree: Kruskal (Union-Find) and Prim (priority queue).&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="12-sorting-review"&gt;12. Sorting (Review)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Reorders data to enable faster search or analytics.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Comparison-based:&lt;/strong&gt; Quick, merge, heap sort—lower bound O(n log n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-comparison:&lt;/strong&gt; Counting, radix, bucket sort—use key range/digits to reach O(n + k).&lt;/li&gt;
&lt;li&gt;Evaluate stability, in-place behaviour, memory footprint, and whether divide-and-conquer fits the scenario.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="13-searching"&gt;13. Searching&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Linear search:&lt;/strong&gt; Scan sequentially; works on unsorted collections; O(n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Binary search:&lt;/strong&gt; Halves the range on a sorted array; O(log n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hash lookup:&lt;/strong&gt; Average O(1) with well-designed collisions handling.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tree search:&lt;/strong&gt; Balanced BSTs or B-Trees deliver O(log n); maintaining balance is vital.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="14-study-tips"&gt;14. Study Tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Build your own complexity tables and revisit them regularly.&lt;/li&gt;
&lt;li&gt;Step through pointer manipulations with a debugger to internalise recursion and linked structures.&lt;/li&gt;
&lt;li&gt;Analyse input size, update frequency, and random access needs before choosing a structure.&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>