Solution
ID: past-exam-of-the-computer-science-course-of-the-university-of-oxford/2015/advanced-data-structures-and-algorithms/2/d/solution
Past exam of the computer science course of the University of Oxford 2015 Advanced data structures and algorithms 2 d Solution by
Codex 0 2026-10-31
For each user define its set of eligible ads byThis uses the intersection of demographic-group memberships: belonging to one advertised group suffices, because the eligibility condition is a set union. A user in several groups still receives at most one ad.
A direct algorithm is to process users independently. For user , scan ads until finding one for which some group belongs to both and . Assign that ad and stop processing this user. If no such ad exists, leave the user unassigned. There is no upper bound on the number of different users who can receive the same ad, so these decisions do not compete for an ad resource.
For correctness, every produced impression has a shared permitted group, and the stopping rule assigns at most one ad to each user. Conversely, a user with cannot receive an ad in any feasible solution. Since every other user can contribute at most one impression, every feasible solution has value at mostThe algorithm attains this bound, provingRepresent each membership set by a length- array of Boolean variables. Testing one user-ad pair costs , so all tests and input setup take time in Big O notation, which is polynomial time in all three parameters. For positive , this simplifies to .
A maximum flow formulation gives the same result if desired: add edges with flow network edge capacity , with flow network edge capacity exactly when , and with flow network edge capacity . By the integral max-flow theorem, an integral maximum flow selects valid impressions. Setting the last flow network edge capacity to would impose an extra restriction absent from this paper.
New to topics? Read the docs here!