Computer Science: Algorithms, Systems and Software — Study Sequence and Worked Investigations

Four guided blocks preserve the original quantitative investigations. The expanded original on-site reader supplies programming, hardware/operating systems, relational/software design and network/application mechanisms plus a complete cumulative case. Publisher chapters are optional; current internal written-course review is recorded above.

Open the course and saved study sequence

Weeks 1–4: Problem specification, algorithms and complexity

Open Learn → Apply → Check → Readings

Begin with the matching native lesson and original on-site reader. Reproduce this retained investigation, optionally attempt changed facts and compare the full reasoning. All practice and publisher chapters are optional.

Specification, invariants and honest algorithm comparisons

An algorithm starts with a contract. Specify accepted inputs, the meaning of the result, and behavior at boundaries. Find a matching value, find its first occurrence, and find an insertion position are different tasks on the same array. A method can return a plausible index while violating the actual contract. Tests become stronger when expected behavior comes from a simple independent definition rather than a second copy of the implementation.

For lower-bound search on an ascending array, the result is the smallest index whose value is at least the target; the result may equal the array length. Maintain a half-open candidate interval [lo, hi). Values strictly before lo are below the target; values at or after hi are at least the target. Set mid to the integer midpoint. If a[mid] is below target, discard it and everything before it by setting lo = mid+1. Otherwise set hi = mid. The interval shrinks and the invariant survives. At termination lo = hi, so the insertion boundary is determined. An ordinary matching-value lookup then also checks that the index is in range and its value equals the target.

Correctness and complexity are separate claims. Halving a random-access interval gives logarithmic comparisons; it does not make sorting free. If a changing dataset receives one lookup, sorting solely to enable that lookup may cost more than a scan. For repeated queries, index construction can pay off. A hash table has different expected behavior, memory requirements and worst-case qualifications. Measure the workload you actually intend to support.

A benchmark needs a fixture, a result check, a timing boundary and enough repetitions to expose noise. Exclude printing from the timed region unless output is part of the workload. Count preprocessing, copying and updates when they occur in actual use. If a fast routine returns the wrong duplicate or silently mutates the input, its speed is irrelevant to the promised contract.

Worked investigation

Search [2, 4, 4, 9] for lower bound of 4. Start lo=0, hi=4. mid=2 contains 4, so hi=2. mid=1 contains 4, so hi=1. mid=0 contains 2, so lo=1. Stop at 1, the first 4. For target 10, the same contract returns 4, not an invalid access to a[4]. A follow-up membership check must test index < len(a) before reading the value. For an empty array the answer is 0 and no element is accessed.

Independent transfer problem

Trace lower bound for targets 1, 4 and 8 in [1, 4, 4, 4, 8]. Write a linear reference function and compare every target from 0 through 9. Then deliberately change hi=mid to hi=mid−1 and identify a failing input.

Compare the reasoning after your attempt

The correct indices are 0, 1 and 4. A linear reference returns the first enumerated value >= target, otherwise len(a). With [1,4] and target 4, the defective update can return 0 after discarding index 1 improperly. Explain the broken invariant; a single matching output on a large fixture does not prove correctness.

Weeks 5–8: Representation, hardware and operating systems

Open Learn → Apply → Check → Readings

Begin with the matching native lesson and original on-site reader. Reproduce this retained investigation, optionally attempt changed facts and compare the full reasoning. All practice and publisher chapters are optional.

Bits, ranges, representation and resource boundaries

Bits have no self-announcing type. The same eight bits can represent an unsigned integer, a signed two's-complement integer, a character code or part of a larger value. A file format or protocol supplies the interpretation. Converting bytes to a number requires agreement on width, signedness and byte order. Successfully decoding something does not establish that the chosen interpretation is correct.

For eight-bit unsigned integers, the range is 0 through 255. Two's-complement signed eight-bit integers represent −128 through 127. The high bit has a different weight in the signed interpretation. Arithmetic beyond a representation's range needs a defined policy: reject, widen, saturate, or wrap where the language or operation specifies wrapping. Do not assume that every programming language handles overflow alike. Python's ordinary integers can grow beyond a fixed machine width, while storage formats and external systems may still impose a fixed range.

Binary floating-point represents a finite set of scaled binary values. Many decimal fractions have no exact finite binary expansion. This is a representation issue, not evidence that arithmetic is random. Choose an error tolerance tied to the problem for approximate scientific work. For an integer-cent ledger, parse and validate the input as an exact number of cents and enforce the allowed range. Rounding every intermediate amount can introduce a different error from rounding only the final presentation.

An operating system mediates resources such as memory, files and processes. A process address space is an abstraction; an address meaningful in one process is not automatically a transferable data reference. Persistent storage, process memory and CPU cache have different lifetime and consistency properties. A variable updated in memory can disappear on restart. A file write acknowledged by a high-level function may still differ from a complete durable transaction. A reliable design states which failure boundary its completion signal actually covers.

Worked investigation

The byte 11111110 has unsigned value 128+64+32+16+8+4+2 = 254. Under signed eight-bit two's complement it is −128+64+32+16+8+4+2 = −2. The bytes 01 00 interpreted as an unsigned 16-bit integer give 256 in big-endian order and 1 in little-endian order. Neither interpretation is inherently visible in the bytes; the surrounding format must specify it.

Independent transfer problem

Interpret 10000001 as unsigned and signed eight-bit two's complement. Then specify an input contract for integer cents that rejects fractional cents and values outside −1,000,000 through +1,000,000. Name three boundary tests.

Compare the reasoning after your attempt

The unsigned value is 129 and the signed value is −127. An exact-cent contract validates representation and range before mutation; it rejects a fractional-cent input rather than silently truncating it. Test exactly −1,000,000, exactly +1,000,000 and one value just outside the range; also test a fractional amount and malformed text.

Weeks 9–12: Software design, data and testing

Open Learn → Apply → Check → Readings

Begin with the matching native lesson and original on-site reader. Reproduce this retained investigation, optionally attempt changed facts and compare the full reasoning. All practice and publisher chapters are optional.

Data invariants, transactions and tests that expose failures

A database design protects relationships that must remain true across operations. A customer display name can change and can be shared by different customers. A stable identifier distinguishes identity from presentation. A foreign key can require that an order references an existing customer; a unique constraint can prevent duplicate event identifiers. Application checks are useful for feedback, but they cannot replace database constraints when concurrent requests race.

A transaction groups changes that must succeed or fail together. Suppose an event changes a ledger, increments a version and creates an audit record. Committing only the ledger creates a state that cannot be reconciled with its recorded history. A deliberate failure after each internal step is a stronger test than checking only the successful path. The test should inspect persisted state after the exception, not merely assert that an exception was raised.

Optimistic concurrency compares the version a client read with the current version. If both clients read version 7, the first successful update can create version 8. The second client must not silently overwrite it using the old assumptions. The version comparison and write need one atomic database operation or a protected transaction. A separate read followed later by an unprotected write leaves a race window.

Idempotency concerns the identity of an operation, not just equality of its amount. Two legitimate purchases for the same amount can be distinct events. An identical retry of one event must not charge twice. Reusing an event ID with changed contents should produce a conflict rather than quietly return success. Test the operation through the actual request boundary, including authorization and input parsing, because unit tests of a helper function cannot establish that the server invokes it correctly.

Worked investigation

Start with balance 10,000 cents and version 7. Client A sends event E1, amount −2,000, expected version 7. A transaction records E1, balance 8,000 and version 8. Client B sends E2, amount −1,000, also expecting 7: it must receive a stale-state conflict and leave balance at 8,000. An exact retry of E1 can return the previously committed result. E1 with amount −3,000 is a conflicting reuse, not a harmless retry. E3 with amount −2,000 can be a distinct valid event after the client refreshes to version 8.

Independent transfer problem

Design a test where audit insertion fails after ledger insertion. Specify the expected ledger, audit and version state. Then run two simultaneous writes using the same expected version and distinct event IDs.

Compare the reasoning after your attempt

After the forced audit failure, no event or audit row should remain and the version must be unchanged. In the concurrent versioned-write test exactly one fresh write should commit; the other must conflict. An exact retry is tested separately because returning a previous result is not a second commit.

Weeks 13–16: Networks, applications and responsible computing

Open Learn → Apply → Check → Readings

Begin with the matching native lesson and original on-site reader. Reproduce this retained investigation, optionally attempt changed facts and compare the full reasoning. All practice and publisher chapters are optional.

Networks, ambiguous failures and permission-scoped AI

A network timeout describes the caller's observation. It does not prove whether the remote operation committed. The server may have written successfully and lost the response. Retrying blindly can duplicate a charge, message or file. Design a request identifier and a reconciliation operation so a caller can discover the established state. Retry policies also need limits and backoff; multiplying load during an outage can make recovery harder.

Authentication establishes a verified identity under an explicit trust mechanism. Authorization decides what that identity may do to a particular object. A client-supplied tenant field is not proof of membership. Derive the tenant or access scope from verified server-side identity, and apply that restriction to every relevant database query. Checking the overview page while leaving the detail endpoint unrestricted does not protect the underlying data.

A retrieval-augmented AI feature adds another boundary. Documents admitted to a model's context must already satisfy the caller's permissions. Filtering the generated answer afterward cannot undo disclosure to an unauthorized model context. Retrieved text is data, not a privileged instruction channel. A document that says ignore policy must not gain authority to change permissions, invoke tools or disclose unrelated records. An answer with a well-formed citation may still fail to support its claim; source identity and claim entailment are separate tests.

Evaluation should include positive and negative cases. A system that always abstains may avoid false assertions while being useless. A system that always answers may look helpful while ignoring evidence. Keep a fixed fixture with supported, unsupported, contradictory, stale and unauthorized documents. Count errors by category and inspect the permitted context. If a feature can perform an external action, validate arguments and authorization independently of generated prose, and require the application's intended confirmation policy at that action boundary.

Worked investigation

A write with request ID R commits, but its response is lost. The client times out. A safe retry reuses R and the same contents; the server recognizes the committed event and returns its result. A new ID R2 would instead mean a new operation. Separately, a learner from tenant A asks for a summary while a tenant B document has the best textual match. The permitted search must exclude B before ranking or assembling context. A high similarity score cannot authorize access.

Independent transfer problem

Create five synthetic retrieval records: authorized support, authorized contradiction, stale support, unauthorized support and an instruction to reveal secrets. Specify the allowed context and answer state for a query with no current authorized support. Then explain how an exact write retry differs from a new request ID.

Compare the reasoning after your attempt

No current authorized supporting document means abstention or a clear unsupported state. Stale and unauthorized records cannot supply hidden support; malicious instructions remain untrusted document content. Contradictory authorized evidence requires an explicit conflict state rather than silent cherry-picking. An exact retry uses the original operation identity; a new ID can create another action.

Reading sources

Publisher chapter links are optional references. Complete original on-site explanations, cumulative models and rubric accompany the preserved fictional records and worked solutions above.