BCA
Data structures in business applications
Study map: Original foundation and applied lesson; editorially linked to the named subject
A data structure organises values so particular operations are possible and reasonably efficient. A list preserves a sequence, a set represents membership, a dictionary associates a key with a value, and a queue models waiting work. These are not interchangeable names for a collection. Choosing a structure begins with the question the system must answer: find an order, detect a repeated identifier, process the oldest request or summarise quantities by department.
Foundation: choose a representation that matches the operation
A data structure organises values so particular operations are possible and reasonably efficient. A list preserves a sequence, a set represents membership, a dictionary associates a key with a value, and a queue models waiting work. These are not interchangeable names for a collection. Choosing a structure begins with the question the system must answer: find an order, detect a repeated identifier, process the oldest request or summarise quantities by department.
In an order service, a dictionary keyed by order identifier can support lookup. A set can track identifiers already seen. A queue can hold accepted work awaiting processing. The queue must contain references to accepted records, not silently include rejected requests. A customer may care about their place in the queue, while a manager cares about age, fairness and service commitments. The representation supports those questions but does not decide the policy.
Draw a small example by hand. Insert A, B and C into an arrival-order queue. Removing from the front produces A first. A last-in-first-out stack would produce C first. A stack is appropriate for some undo or nested-processing tasks, but using it for customer arrivals would change service order. Explain the consequence before discussing implementation speed.
Undergraduate: invariants, complexity and duplicate policy
An invariant is a condition that must remain true as operations occur. In the workshop, every queued identifier refers to one accepted order, accepted identifiers are unique, and total value is derived from accepted quantities and prices. Check these conditions after insertion and removal. A structure that looks efficient can still be wrong if a mutation breaks its invariant.
A linear search may examine every item; a dictionary usually offers average constant-time key lookup, though this is not a promise that every lookup has identical cost. Hashing needs memory and has collision and worst-case considerations. Removing the first item from a Python list shifts remaining elements; a deque is better suited to repeated removal at the front. Measure the actual workload instead of claiming that a familiar complexity label proves acceptable performance.
Distinguish membership from equivalence. Seeing identifier A twice establishes repeated identity, but the associated content may agree or conflict. Retain a mapping to the original content if that distinction matters. A set alone cannot explain whether the second price differs. Decide what fields belong in the comparison and who may authorise a correction.
Postgraduate: scheduling is also a business choice
Use an operation–representation–invariant framework. List required operations and their frequency, choose a representation, define invariants, then test performance and correctness. Avoid adding a sophisticated structure without a demonstrated need. A small dictionary and deque may be clearer than an elaborate class hierarchy for a bounded teaching problem.
Arrival order is one policy, not universal fairness. Emergency work may require priority, but then define who can assign priority and how ordinary work avoids indefinite delay. Sorting by invoice value may reward large customers while breaching promises to smaller ones. A priority queue implements a ranking rule; it does not justify that ranking ethically or commercially.
Consider interoperability. Sales may identify an order by a customer reference, operations by an internal job number and finance by an invoice number. Establish mappings rather than pretending each key is the same concept. Keep the relationship explicit so duplicate detection does not mistakenly merge different objects. Communicate the meaning and lifetime of each identifier to staff who create and use it.
Research: compare structures under a stated workload
A study can compare queue implementations for a defined pattern of arrivals and removals. Specify dataset size, operation mix, machine environment and repetitions. Include memory and correctness evidence, not just the fastest observed run. Small timing differences may reflect noise or setup rather than a transferable advantage.
If the research question concerns service fairness, execution timing is insufficient. Examine waiting-time distributions, exceptions and priority overrides. A technically faster queue may not reduce customer waiting when fulfilment capacity is the bottleneck. Distinguish time spent manipulating a container from time spent waiting for people, stock or approval.
In the workshop, inspect the same accepted orders through lookup, membership and scheduling views. Predict their order before running the code. Explain which information each structure retains and loses. Submit an invariant table, a justified scheduling policy and a comparison design. Keep the conclusion local: this exercise is not a distributed queue, a durable broker or evidence of production capacity.
Study questions and answers
What distinguishes a set from a dictionary?
A set records membership; a dictionary stores a value for a key. Duplicate detection that must compare original payloads needs retained content, not membership alone. Indicative marking: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
A, B and C arrive in order. What does FIFO remove first?
A. A stack would remove C. The container implements an order; the organisation must justify which scheduling policy fits its commitments. Indicative marking: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
Why does fast lookup not establish fair service?
Lookup time concerns computation. Service fairness concerns priority, waiting and overrides. A fast structure can implement an unfair policy or leave fulfilment bottlenecks unchanged. Indicative marking: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
Design a queue comparison.
Specify size, arrival/removal mix, environment and repetitions. Verify identical order and invariants; measure memory and timing. Do not infer customer waiting improvements from container benchmarks alone. Indicative marking: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
Extended practice questions
What distinguishes a set from a dictionary?
A set records membership; a dictionary stores a value for a key. Duplicate detection that must compare original payloads needs retained content, not membership alone.
Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
Marks: 10
A, B and C arrive in order. What does FIFO remove first?
A. A stack would remove C. The container implements an order; the organisation must justify which scheduling policy fits its commitments.
Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
Marks: 10
Why does fast lookup not establish fair service?
Lookup time concerns computation. Service fairness concerns priority, waiting and overrides. A fast structure can implement an unfair policy or leave fulfilment bottlenecks unchanged.
Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
Marks: 10
Design a queue comparison.
Specify size, arrival/removal mix, environment and repetitions. Verify identical order and invariants; measure memory and timing. Do not infer customer waiting improvements from container benchmarks alone.
Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.
Marks: 10
A service desk uses a set to hold waiting requests and customers complain about inconsistent order. Which requirement and structure should be reconsidered?
Define whether service should follow arrival order, priority or another explicit rule. A set supports membership and uniqueness but is not a first-in-first-out queue. For an arrival-order exercise, keep a queue of request identities and a separate record of request details. Check duplicate submissions and cancellations without silently changing the policy. Operations owns the service rule; developers select and test the structure. A technically convenient collection does not decide fairness or urgency. Inspect a short event trace so the team can explain which request will be served next and why.
Marking guide: Service rule; set versus queue; identities/details; duplicates/cancellations; policy ownership. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
Compare a dictionary and a queue in a customer-request application.
A dictionary associates a key with a value, allowing a request identity to retrieve its details. A queue models the order in which waiting work is removed under the chosen queue rule. The application may need both: queued identities plus a dictionary of records. Updating request details should not accidentally duplicate its place in the queue. Define how cancellation and repeated submission affect each structure. Neither structure alone guarantees persistence, concurrent safety or the correct business policy. Test those requirements separately rather than treating an in-memory demonstration as a complete service system.
Marking guide: Lookup versus ordering; combined design; update/cancellation semantics; persistence/concurrency boundaries. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
A queue starts with seven requests. Two distinct requests arrive, then three requests are completed, with no cancellations or retries. Calculate the final queue length.
Final length is seven plus two minus three, giving six waiting requests. The result assumes all arrivals are new, the completions remove existing requests and no other event changes the queue. Trace the identities as well as the count: a correct length can hide removal of the wrong requests. With first-in-first-out service, the three earliest waiting identities should leave first. Record the state after each event and test an empty-queue boundary separately. The arithmetic is a conservation check, not evidence of acceptable waiting times or service quality.
Marking guide: Six remaining; distinct events; identity/order trace; conservation versus performance. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
Design data-structure tests for a bounded service queue using synthetic requests.
Test arrival order, lookup by identity, duplicate submission, cancellation and removal from an empty queue. Define the expected sequence and record state before executing each case. Check that a cancellation changes both the waiting representation and the relevant status consistently. Keep synthetic identities and avoid copying real customer details. Explain that the exercise is in-memory unless persistence has actually been implemented. A manager reviews the service policy while the programmer verifies the operations. Passing these cases demonstrates specified behaviours, not scalability, concurrent safety or compliance with every service promise.
Marking guide: Varied boundary fixtures; expected state; consistent cancellation; synthetic data; bounded conclusion. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
Revision cards
When can a hash-based lookup improve a workflow?
It can support efficient retrieval by a suitable key under the implementation’s assumptions. Consider collisions, updates, memory and identity correctness. Fast lookup is not proof that the key represents the right business entity.
A service desk uses a set to hold waiting requests and customers complain about inconsistent order. Which requirement and structure should be reconsidered?
Choose the service policy first. A membership set is not a FIFO queue; retain request identities and test the expected event order.
Compare a dictionary and a queue in a customer-request application.
A dictionary retrieves details by identity; a queue orders waiting work. They may cooperate, but persistence and concurrent behaviour require separate design.
A queue starts with seven requests. Two distinct requests arrive, then three requests are completed, with no cancellations or retries. Calculate the final queue length.
Queue length is 7 + 2 − 3 = 6. Check identities and removal order as well as the count; six does not describe waiting-time quality.
Design data-structure tests for a bounded service queue using synthetic requests.
Test ordering, lookup, duplicate, cancellation and empty removal with expected identities. State persistence and concurrency limits instead of claiming a complete system.
Why might priority work require more than a simple queue?
Urgency, service commitments and fairness may require an explicit prioritisation policy. Choose a structure that supports the policy, but keep the business rule and exception authority visible rather than letting the structure decide them.
What does a data-structure invariant do?
It states a property the representation must preserve after valid operations. Test insertions, deletions and boundary cases against it. The invariant supports consistency within the model, not factual accuracy of supplied records.
What tradeoff does a hash-based lookup introduce?
It can support efficient lookup under its assumptions but depends on hashing, equality and collision handling. Ordering may need a separate structure. Choose based on operations and correctness requirements rather than a single advertised speed figure.
Why does a queue's ordering rule matter to a business workflow?
The rule determines which work is considered next and how priorities are treated. First-in-first-out may not fit every urgency. Document exceptions and starvation risks so a technical container does not silently define service fairness.
How can choosing the wrong key distort a data structure?
Different entities may collapse into one entry or one entity may split across several entries. Define identity and matching rules. A fast lookup is not useful if it consistently returns a record for the wrong business meaning.
Practice task
Complete computing-workshop.html: predict category counts and totals, run the script and tests, then submit the six portfolio deliverables.
Sources and further reading
- Computing for business workshop
Type: Original practice
Use: Predict, run, test and reconcile synthetic orders. - Python tutorial — for learners with some programming familiarity
Type: Free official learning documentation
Use: Use after the Library foundation: functions, control flow and errors. - Python collections reference
Type: Free official reference
Use: Inspect deque and mapping behaviour; not a complete algorithms course. - Python sqlite3 reference
Type: Free official reference
Use: Study binding and transaction controls for the local database. - GitHub Actions concepts
Type: Free official documentation
Use: Learn workflow vocabulary; hosted execution pricing is not evaluated here.