Professional Decision-Making, AI, Ethics, and GovernanceIntroductionData structures and algorithms are often taught as technical mechanisms: arrays store values, trees organize records, graphs model relationships, and algorithms transform inputs into outputs. In professional software development, however, choosing an algorithm is a decision under constraints. A technically elegant algorithm may be unsuitable because it is too slow at peak load, consumes excessive memory, is difficult to maintain, exposes sensitive information, excludes users with disabilities, or creates unacceptable social and legal risks. Modern systems make these decisions more difficult. Search engines rank information; recommendation systems influence attention and purchasing; routing systems affect travel, logistics, and emergency response; analytics systems support decisions about employment, credit, health, and public services. Artificial intelligence adds statistical models whose behaviour may be difficult to explain, reproduce, or govern. The programmer therefore needs both algorithmic competence and professional judgement. This chapter develops a practical framework for selecting and governing algorithms. It connects complexity analysis with workload, latency, throughput, memory, maintainability, security, accessibility, and cost. It also examines algorithmic applications, biased objectives, privacy, denial-of-service risks, reproducibility, and emerging hardware-aware and AI-assisted development. Learning ObjectivesBy the end of this chapter, you should be able to: - Select algorithms using technical, operational, ethical, and economic criteria.
- Distinguish latency, throughput, capacity, scalability, and resource utilisation.
- Evaluate algorithms used in analytics, recommendation, search, routing, and AI systems.
- Explain how objectives, training data, and evaluation metrics can produce bias.
- Identify privacy, security, denial-of-service, reproducibility, and accessibility risks.
- Apply a structured decision record to an algorithm-selection problem.
- Describe governance controls for algorithmic systems.
- Use Java and Python responsibly when implementing and evaluating algorithms.
1. Algorithm Selection as a Professional Decision1.1 Beyond asymptotic complexityBig-O notation describes how resource requirements grow as input size increases. It is essential, but it does not by itself determine which algorithm is best. Two algorithms with the same asymptotic complexity can differ substantially in constant factors, memory access patterns, cache behaviour, implementation complexity, and failure modes. For example, a hash table usually provides expected constant-time lookup, written as O(1), but its performance depends on a suitable hash function, a controlled load factor, and resistance to collision attacks. A balanced binary search tree provides O(log n) lookup in the worst case and maintains ordered traversal, but it may involve more pointer operations and memory overhead. A sorted array can provide binary search in O(log n) while offering excellent cache locality, but insertion is generally O(n). Professional selection therefore begins with the question: “What constraints must the complete system satisfy?” 1.2 A multi-criteria decision modelA useful decision process records requirements before implementation. Typical criteria include: | Criterion | Important question | Typical evidence |
|---|
| Workload | How many items, requests, updates, and users are expected? | Traces, forecasts, production measurements | | Latency | How quickly must one operation complete? | Percentiles such as p95 and p99 | | Throughput | How much work must the system complete per unit time? | Requests per second, records per hour | | Memory | What is the available memory budget? | Peak resident memory, object counts | | Maintainability | Can engineers understand, test, and change it? | Code review, test coverage, complexity | | Security | Can inputs cause abuse or information leakage? | Threat modelling, adversarial tests | | Accessibility | Can diverse users access and understand outcomes? | Usability and assistive-technology testing | | Cost | What are infrastructure, development, and operational costs? | Cloud bills, staffing, energy use | | Fairness and impact | Who benefits, who is harmed, and how? | Impact assessment and subgroup evaluation |
A weighted scoring model can support discussion, but it must not disguise value judgements as objective mathematics. If criterion scores are normalised to a common scale, a simple model is: S(a) = ∑ᵢ wᵢ rᵢ(a) Here, S(a) is the score of alternative algorithm a, wi is the weight assigned to criterion i, and ri(a) is the measured or justified rating of the alternative on that criterion. The weights should normally satisfy wi ≥ 0 and ∑wi = 1. This model assumes that the ratings are comparable and that trade-offs are acceptably represented by a weighted sum. Safety, legal compliance, and human rights should usually be treated as mandatory constraints rather than merely low-weight criteria. A decision record should state the alternatives considered, assumptions, evidence, rejected options, risks, and conditions that would trigger reassessment. 2. Workload, Latency, Throughput, and Capacity2.1 Distinguishing operational measuresLatency is the elapsed time for an operation. Throughput is the amount of completed work per unit time. They are related but not interchangeable. Increasing concurrency may increase throughput while worsening latency. A batch process may have excellent throughput but be unsuitable for an interactive application. For a stable system, a basic utilisation relationship is commonly expressed as: U = λ / μ Here, λ is the arrival rate in jobs per second, μ is the service rate in jobs per second, and U is utilisation. The interpretation assumes a reasonably stable service process and compatible units. As utilisation approaches 1, queues can grow rapidly, so designing for exactly 100% utilisation is unsafe. Average latency is often insufficient. A service with a one-second average may still be unacceptable if one in every twenty users waits ten seconds. Engineers therefore examine percentiles: p50 is the median, p95 is the value below which 95% of observations fall, and p99 is the value below which 99% fall. Measurements must specify the workload, hardware, dataset, concurrency, warm-up conditions, and whether queueing time is included. 2.2 Memory and data representationAn algorithm that is computationally efficient can fail because of memory. In Python, references and object metadata can make a list of integers much larger than a compact numeric array. In Java, object headers, references, garbage collection, and boxed values also affect memory. For large datasets, contiguous primitive arrays or specialised libraries may be preferable to collections of objects. Memory complexity should include auxiliary storage, temporary buffers, indexes, caches, and retained historical data. Streaming algorithms can reduce memory by processing records incrementally. For example, a running mean for values x1, x2, ..., xn can be maintained as: mk = mk-1 + (xk - mk-1)/k Here, mk is the mean after k observations. The method uses constant additional memory, assumes numerical values can be represented adequately, and avoids storing the entire dataset. 3. Maintainability, Security, Accessibility, and Cost3.1 MaintainabilityMaintainability includes readability, modularity, testability, documentation, observability, and the availability of engineers who understand the technology. A slightly slower algorithm may be preferable if it is substantially easier to verify and modify. Good practice includes separating algorithmic logic from input/output, defining clear interfaces, documenting invariants, testing boundary cases, and measuring before optimising. In Java, interfaces and generics can make data-structure choices explicit. In Python, type hints, small pure functions, property-based tests, and profiling tools improve reliability without removing the language’s flexibility. 3.2 SecurityAlgorithms become security components when attackers control inputs or observe outputs. Relevant threats include: - Hash-collision attacks that make dictionary operations expensive.
- Pathological regular expressions that cause excessive backtracking.
- Graph or tree inputs designed to exhaust memory or recursion depth.
- Query patterns that force expensive database operations.
- Model-extraction or membership-inference attacks against AI services.
- Ranking manipulation, poisoning, and adversarial examples.
Defensive measures include input limits, timeouts, iteration budgets, rate limiting, bounded queues, safe parsing, authentication, monitoring, and fail-safe behaviour. A recursive algorithm should have a justified depth bound or an iterative alternative where hostile input is possible. 3.3 AccessibilityAlgorithmic accessibility is broader than screen-reader compatibility. It includes understandable explanations, keyboard access, language support, low-bandwidth operation, appropriate contrast, and avoidance of unnecessary cognitive burden. A recommendation or decision system may be technically accurate yet inaccessible if users cannot discover why a result was produced or how to challenge it. Accessibility should be evaluated with representative users and assistive technologies. Automated checks are useful but cannot replace human evaluation. 3.4 Cost and sustainabilityCost includes engineering time, cloud compute, storage, network transfer, licensing, support, energy, and the cost of errors. A computationally expensive model may be justified for a high-value task but wasteful for a simple classification that a smaller method can perform adequately. Cost estimates should use measured consumption where possible. They should also account for peak capacity rather than only average demand. Efficient algorithms can reduce both financial cost and environmental impact, although efficiency must not be pursued by weakening privacy, safety, or fairness. 4. Applications of Data Structures and Algorithms4.1 AnalyticsAnalytics pipelines commonly combine filtering, grouping, sorting, aggregation, joins, sampling, and indexing. Hash-based grouping is often efficient for equality keys, while sorting supports ordered reports and merge-based operations. Streaming analytics is appropriate when data arrives continuously or cannot fit in memory. Approximate algorithms can provide useful answers with bounded error. A sampling strategy, for example, may estimate a population property at lower cost, but the sampling method must match the question. Convenience samples can produce serious bias. Engineers should document the population, sampling frame, missing data, and uncertainty. 4.2 Recommendation systemsRecommendation systems may use content-based similarity, collaborative filtering, graph methods, or hybrid approaches. A nearest-neighbour method can recommend items associated with users or products having similar interaction patterns. Ranking algorithms then order candidates according to predicted relevance. Optimising only clicks can produce sensational or repetitive content. Appropriate objectives may include relevance, diversity, novelty, user control, safety, and long-term satisfaction. Metrics should be evaluated by subgroup and over time. Offline accuracy does not guarantee beneficial real-world outcomes because recommendations change user behaviour and generate new data. 4.3 SearchSearch systems typically perform indexing, candidate retrieval, scoring, ranking, filtering, and presentation. An inverted index maps terms to documents and allows efficient retrieval. Ranking may consider textual relevance, freshness, authority, location, and user context. Search quality involves precision and recall. Precision is the fraction of retrieved results that are relevant; recall is the fraction of all relevant results that are retrieved. Their usefulness depends on the task. A legal researcher may require high recall, while a user seeking one precise answer may prefer high precision. Ranking evaluation should include human judgement, query diversity, adversarial manipulation, and accessibility. 4.4 RoutingA road network can be represented as a weighted graph. Vertices represent locations and edges represent roads; edge weights may represent distance, travel time, tolls, risk, or energy. Dijkstra’s algorithm is suitable when edge weights are non-negative and computes shortest paths from a source. A* can reduce explored nodes when an admissible heuristic is available; an admissible heuristic never overestimates the remaining cost. Routing objectives are not purely mathematical. The shortest route may pass through residential streets, increase pollution, or create unequal burdens. Systems should consider safety, accessibility, emergency priorities, uncertainty, and the effect of routing many users simultaneously. 4.5 AI systemsAI systems involve data preparation, feature or representation construction, model training, evaluation, deployment, monitoring, and retirement. Algorithms include decision trees, linear models, nearest neighbours, neural networks, and optimisation procedures. The correct choice depends on the task, available data, required explanation, error costs, hardware, and governance obligations. A model should not be selected solely because it is more complex or achieves a higher aggregate score. Calibration, robustness, subgroup performance, privacy, interpretability, and operational cost may be more important. 5. Objectives, Bias, and Fairness5.1 Bias enters through the whole systemBias can arise from historical data, under-representation, measurement error, labels, proxy variables, problem framing, optimisation targets, deployment context, and feedback loops. Removing an explicitly sensitive attribute does not guarantee fairness because other variables may encode it. Suppose a system predicts future demand using historical service records. If a community previously received fewer services, the data may show low demand even when underlying need was high. Optimising prediction against those records can reproduce the original allocation pattern. 5.2 Metrics and trade-offsFairness has multiple definitions that are not always simultaneously achievable. For a binary decision, a confusion matrix contains true positives, false positives, true negatives, and false negatives. Important rates include: - True-positive rate: TPR = TP/(TP + FN), when the denominator is non-zero.
- False-positive rate: FPR = FP/(FP + TN), when the denominator is non-zero.
- Positive predictive value: PPV = TP/(TP + FP), when the denominator is non-zero.
These rates can differ between groups because of prevalence, data quality, or model behaviour. A responsible evaluation states which fairness concept is being used, why it fits the application, and what trade-offs remain. Fairness metrics should supplement, not replace, qualitative impact assessment and affected-community participation. 5.3 Objective designA system objective should represent the real purpose rather than an easy proxy. “Maximise engagement” may reward addictive or polarising content. “Minimise delivery time” may increase unsafe driving. “Reduce fraud” may impose disproportionate burdens on legitimate users. Objectives should include constraints, human review, appeal mechanisms, and monitoring for unintended effects. 6. Privacy, Security, and Denial-of-Service RisksPrivacy protection begins with data minimisation: collect only what is needed, retain it for a justified period, restrict access, and document lawful purpose. Pseudonymisation reduces direct identifiers but does not guarantee anonymity; combining datasets can enable re-identification. Algorithms can leak information through outputs. Membership inference attempts to determine whether a person’s record was used in training. Model inversion attempts to infer sensitive features. Mitigations may include access controls, aggregation, noise, differential privacy, secure logging, and limiting query detail. Differential privacy is a formal framework, but its parameters and utility trade-offs must be understood rather than treated as a label of safety. Denial-of-service protection requires analysing worst-case input behaviour. A service should set maximum request size, recursion depth, graph size, search breadth, execution time, and memory allocation where appropriate. Rate limits should be designed carefully so that they do not unfairly block legitimate users or users behind shared networks. Expensive operations can be queued, cached, precomputed, or isolated. 7. Reproducibility and EvidenceA result is reproducible when another competent person can obtain the same result under the documented conditions. Reproducibility requires versioned source code, dependency versions, configuration, random seeds where meaningful, dataset identifiers, preprocessing steps, hardware details, evaluation scripts, and clear metric definitions. Randomness deserves special care. Setting a seed can improve repeatability but does not guarantee identical results across libraries, processors, parallel execution, or versions. A reported result should include variation across runs when randomness affects conclusions. Benchmarking must avoid leakage. Training and test data must be separated appropriately, and repeated tuning against a test set can turn it into an informal training set. Production monitoring is also evidence: distribution shift, drift, latency, error rates, and subgroup outcomes may change after deployment. 8. Governance and Professional AccountabilityGovernance converts principles into responsibilities and controls. A practical lifecycle includes: - Purpose definition: Describe the decision, affected people, benefits, harms, and prohibited uses.
- Data assessment: Record provenance, consent or legal basis, quality, representativeness, retention, and access.
- Design review: Compare algorithmic and non-algorithmic alternatives; identify security and accessibility requirements.
- Validation: Test accuracy, robustness, fairness, privacy, usability, and worst-case performance.
- Approval: Assign accountable owners and define release criteria.
- Deployment controls: Use logging, access management, rate limiting, human oversight, and rollback plans.
- Monitoring: Track operational and social outcomes, including complaints and subgroup effects.
- Incident response: Investigate failures, notify appropriate parties, correct harm, and preserve evidence.
- Retirement: Remove obsolete models, revoke access, and manage retained data.
Documentation such as model cards, data sheets, threat models, algorithm registers, decision logs, and impact assessments supports accountability. Governance is not only a compliance activity; it improves engineering quality by making assumptions visible. 9. Hardware-Aware and AI-Assisted Algorithm DevelopmentModern performance depends on more than instruction count. Caches, branch prediction, vector instructions, GPUs, accelerators, memory bandwidth, and parallelism influence actual execution. An algorithm with fewer abstract operations may be slower if it causes irregular memory access or prevents vectorisation. Hardware-aware development should measure on representative systems. Important practices include selecting data layouts that improve locality, batching operations when appropriate, avoiding unnecessary transfers between CPU and accelerator, and considering precision requirements. A change that improves benchmark speed may increase energy use, reduce numerical stability, or make debugging harder. AI-assisted programming tools can generate code, tests, explanations, and optimisation suggestions. They can also produce insecure code, reproduce licensing concerns, invent APIs, or obscure algorithmic assumptions. Generated code must be reviewed, tested, benchmarked, scanned for vulnerabilities, and checked against project policies. The human developer remains accountable for correctness and consequences. A sound workflow is: specify requirements and invariants; generate or draft an implementation; inspect data structures and complexity; test normal, boundary, adversarial, and accessibility cases; benchmark with realistic workloads; review dependencies and licences; document decisions; and obtain peer review. 10. Illustrative Case: Fair and Resilient Benefits-Application TriageBackgroundThis fictional case concerns a public agency receiving a large number of benefits applications. Staff want to prioritise cases requiring urgent review while preserving the right to human decision-making. ProblemThe agency proposes a model that predicts which applications are likely to contain errors. Historical records are incomplete, processing delays vary by region, and some applicants have limited internet access. A simple accuracy score would not reveal whether the system disadvantages particular groups. AnalysisThe team identifies several risks. Historical “error” labels may reflect unequal scrutiny rather than actual error. A model could use postcode as a proxy for protected characteristics. High request volumes could be used to exhaust the service. Applicants may not understand why their case was prioritised or delayed. The system must support accessible communication and human appeal. The team compares three approaches: manual first-come processing, rule-based triage, and a predictive model. It chooses a conservative rule-based system for urgent indicators, supported by a model used only to suggest cases for review. No applicant is automatically denied. The system records reasons, confidence, and the human decision. Approach and controlsData minimisation removes unnecessary attributes. Inputs are validated and bounded. Rate limits and queues protect service availability. The system is tested for subgroup false-positive and false-negative rates, language accessibility, keyboard navigation, and low-bandwidth use. A random sample of cases is manually reviewed to detect missed urgency. All model versions, rules, and decisions are logged. OutcomeThe agency finds that the model’s aggregate accuracy is higher than the rules’ accuracy, but its error rate is substantially worse for applicants with incomplete digital histories. The agency therefore limits the model’s role, adds a human review pathway, improves data collection, and publishes an explanation of the process. The final system is less automated but more defensible and equitable. Learning pointsThe case demonstrates that the most accurate aggregate model is not automatically the best professional choice. Objectives, data quality, accessibility, contestability, security, and accountability must be evaluated together. A lower-risk algorithm with human oversight may produce greater public value than full automation. 11. Practical Decision ChecklistBefore selecting or deploying an algorithm, ask: - What problem is being solved, and what decisions are outside its authority?
- What are normal, peak, and adversarial workloads?
- Which latency percentile and throughput target matter?
- What are the memory, energy, and financial budgets?
- What assumptions does the algorithm require?
- What happens on malformed, missing, extreme, or biased input?
- Can users understand, challenge, or correct an outcome?
- Are vulnerable and disabled users included in testing?
- Could the system leak information or be exploited for denial of service?
- Can results be reproduced and audited?
- Who owns the system after deployment?
- What evidence will cause the algorithm to be changed or withdrawn?
Challenges and LimitationsNo decision framework eliminates uncertainty. Workloads change, metrics can be gamed, fairness definitions conflict, and monitoring may detect harm only after it occurs. Small organisations may lack specialised security, accessibility, or statistical expertise. Regulatory requirements vary by jurisdiction and application. Human oversight can itself be inconsistent or biased. Documentation can become stale, and reproducibility can be limited by proprietary data or changing dependencies. These limitations reinforce the need for proportionality. High-impact systems require stronger evidence, independent review, meaningful human control, and effective remedies than low-risk personal tools. Technical optimisation must remain subordinate to lawful, safe, and socially legitimate use. Chapter SummaryProfessional algorithm selection is a multi-criteria engineering and governance decision. Big-O complexity is necessary but insufficient: workload, latency percentiles, throughput, memory, hardware, maintainability, security, accessibility, cost, fairness, and environmental impact also matter. Analytics, recommendation, search, routing, and AI systems illustrate how data structures and algorithms shape real-world outcomes. Bias can enter through objectives, data, labels, proxies, evaluation metrics, and feedback loops. Privacy requires minimisation, access control, retention discipline, and awareness of inference attacks. Denial-of-service resilience requires bounded computation and defensive input handling. Reproducibility depends on versioned code, data, configurations, seeds, and transparent evaluation. Governance provides lifecycle controls from purpose definition through retirement. AI-assisted development is useful but does not transfer professional accountability away from the developer. Key TermsAlgorithmic governance: Policies, responsibilities, controls, and processes used to manage algorithmic systems. Accessibility: Designing systems so that people with diverse abilities and technologies can use them. Admissible heuristic: A heuristic that never overestimates remaining path cost. Bias: Systematic distortion that can produce unequal or inaccurate outcomes. Capacity: The maximum sustainable workload under specified conditions. Differential privacy: A formal framework for limiting the effect of one individual’s data on an output. Drift: Change in data, relationships, or performance after deployment. Fairness metric: A quantitative measure used to examine disparities or equity-related properties. Inverted index: A mapping from terms to documents or records containing them. Latency: Elapsed time required to complete an operation. Maintainability: The ease with which software can be understood, tested, modified, and operated. Model card: Documentation describing a model’s intended use, evaluation, limitations, and risks. Percentile: A value below which a specified percentage of observations falls. Precision: In retrieval, the fraction of retrieved results that are relevant. Reproducibility: The ability to obtain consistent results under documented conditions. Throughput: Amount of work completed per unit time. Threat model: A structured description of assets, attackers, vulnerabilities, and mitigations. Utilisation: Proportion of service capacity being used. Review QuestionsShort Answer Questions- Why is Big-O complexity insufficient for professional algorithm selection?
- Distinguish latency from throughput.
- What is the purpose of an inverted index?
- Name two sources of algorithmic bias.
- Why are reproducible experiments important?
Long Answer Questions- Explain how workload, memory, maintainability, security, and cost can produce different choices between a hash table, balanced tree, and sorted array.
- Discuss why maximising engagement may be an unsafe objective for a recommendation system.
- Explain the main stages of an algorithm-governance lifecycle.
- Compare the roles of precision and recall in search evaluation.
- Discuss how privacy and denial-of-service risks can arise in an AI service and how they can be mitigated.
Analytical / Application Questions- A service receives 800 requests per second and can process 1,000 requests per second under the measured workload. Calculate utilisation using U = λ/μ and explain why operating close to full utilisation may be risky.
- Design a decision record for choosing between Dijkstra’s algorithm and A* for a navigation application. State assumptions about edge weights, heuristics, latency, memory, and correctness.
- Propose an evaluation and governance plan for a benefits-triage model. Include data quality, subgroup testing, accessibility, privacy, human review, monitoring, and appeal mechanisms.
Multiple Choice Questions with AnswersQuestion 1Which measure describes the amount of work completed per unit time? A. Latency B. Throughput C. Memory complexity D. Precision Correct Answer: B. Throughput Question 2A hash table is most directly vulnerable to which performance risk when inputs are adversarial? A. Hash collisions B. Loss of sorted traversal C. Excessive recursion in every lookup D. Inability to store key-value pairs Correct Answer: A. Hash collisions Question 3Which condition is required for Dijkstra’s algorithm in its standard form? A. All edge weights are identical B. All edge weights are non-negative C. The graph must be acyclic D. The graph must be directed Correct Answer: B. All edge weights are non-negative Question 4If a service receives 800 requests per second and processes 1,000 requests per second, what is utilisation using U = λ/μ? A. 0.08 B. 0.20 C. 0.80 D. 1.25 Correct Answer: C. 0.80 Question 5What does p95 latency represent? A. The fastest 95% of requests B. The average of all request times C. The value below which 95% of measured latencies fall D. The latency of the 95th request only Correct Answer: C. The value below which 95% of measured latencies fall Question 6Which practice most directly supports reproducibility? A. Changing dependencies without recording versions B. Reporting only the best experimental run C. Recording code, data identifiers, configuration, and evaluation procedure D. Removing all randomisation from every algorithm Correct Answer: C. Recording code, data identifiers, configuration, and evaluation procedure Question 7Why can removing a sensitive attribute fail to eliminate unfairness? A. Algorithms cannot process numerical values B. Other variables may act as proxies for it C. Sensitive attributes are always required for accuracy D. Fairness is determined only by runtime Correct Answer: B. Other variables may act as proxies for it Question 8Which is an appropriate denial-of-service defence for an expensive graph operation? A. Allow unlimited graph size B. Remove authentication C. Set input and execution bounds D. Disable monitoring Correct Answer: C. Set input and execution bounds Question 9What is an admissible heuristic in A* search? A. One that always overestimates the remaining cost B. One that never overestimates the remaining cost C. One that ignores edge weights D. One that works only on cyclic graphs Correct Answer: B. One that never overestimates the remaining cost Question 10What is the most appropriate attitude toward AI-generated code? A. Accept it without testing because it is machine-generated B. Use it only for user-interface styling C. Review, test, benchmark, and check its security and licensing D. Assume it is automatically reproducible Correct Answer: C. Review, test, benchmark, and check its security and licensing
|