Evaluating Two-Tier LLM Coding Capabilities with Two Algorithm Problems

    A high-performance model and its lightweight counterpart should be evaluated on more than sample-test pass rates. This article uses a time-dependent, multi-objective shortest-path problem and an out-of-order event replay problem to examine algorithmic reasoning, business-rule correctness, edge cases, and scalability. It outlines a shared evaluation framework covering hidden tests, randomized comparisons, repair quality, resource use, and cost per successful completion.

    1. Evaluating Two Model Tiers Requires More Than a Pass Rate

    New generations of large language models often come in two tiers: a high-performance model and a lightweight model. The high-performance tier typically handles complex reasoning, long contexts, and code generation under multiple constraints. The lightweight tier emphasizes low latency, low cost, and high throughput. Rather than direct replacements for each other, they represent different levels of compute within the same system.

    Evaluating these tiers therefore requires two separate questions:

    1. Can the high-performance model solve complex problems correctly and make its failures reproducible and verifiable?
    2. Can the lightweight model reliably complete frequent, well-defined tasks at a sufficiently low cost?

    Public sample-test pass rates alone can mistake familiarity with coding templates for genuine understanding. A more reliable evaluation combines tiered tasks, hidden tests, randomized differential testing, complexity constraints, and the ability to repair failed solutions.

    The following two algorithm problems illustrate this approach. The first tests time-dependent shortest paths and multi-objective trade-offs. The second tests ordering, idempotency, and snapshots in event replay. Together, they probe algorithmic reasoning and precision in implementing business rules.

    2. Problem One: Multi-Objective Shortest Paths with Periodic Departures

    2.1 Problem Definition

    Consider a directed graph with nodes numbered (0..n-1). Each edge contains:

    • Source node (u)
    • Destination node (v)
    • Departure phase phase
    • Departure interval period
    • Travel time duration
    • Travel cost cost

    If a traveler reaches (u) at time (T), departure is allowed only when:

    [
    (depart + phase) \bmod period = 0
    ]

    If departure is not immediately possible, the traveler waits until the next valid departure time. Arrival at (v) occurs at depart + duration, and the edge cost is added to the accumulated cost.

    The required result is a triple:

    1. The earliest arrival time
    2. The lowest total cost among routes achieving that arrival time
    3. The lexicographically smallest node path when both arrival time and cost are equal

    Return an empty result if the destination is unreachable. Inputs may include parallel edges, self-loops, (s=t), zero-cost edges, and many equivalent paths.

    The next valid departure time can be calculated in (O(1)) time using integer arithmetic:

    1. def next_depart(t, phase, period):
    2. r = (t + phase) % period
    3. if r == 0:
    4. return t
    5. return t + period - r
    6. arrival = next_depart(T, phase, period) + duration

    Although this calculation looks simple, generated solutions may use floating-point modulo, mishandle negative phases, or scan departure times linearly. A correct implementation should use integer arithmetic throughout and follow the specified contract for (s=t)—for example, returning the starting time, zero cost, and a single-node path.

    2.2 Why a Single-Label Shortest-Path Algorithm Fails

    The most obvious implementation stores one best state per node and expands states from a priority queue ordered by arrival time. This can determine the earliest arrival time, but it is insufficient for finding the cheapest route among all earliest-arrival routes.

    Consider two prefixes reaching node (u):

    • Path A arrives at time 10 with cost 100.
    • Path B arrives at time 12 with cost 0.
    • An edge from (u) to destination (t) next departs at time 20 and has cost 0.

    Both prefixes can wait for the same departure and reach (t) at the same time. Path B, however, has the lower cost. Retaining only the earliest-arriving prefix, A, discards the route that satisfies the secondary objective.

    Retaining only the cheapest prefix is also unsafe: a later-arriving prefix may miss a departure that an earlier prefix could catch.

    The implementation therefore needs non-dominated labels. A label that arrives earlier but costs more and another that arrives later but costs less cannot automatically eliminate each other. For the time-and-cost objectives, label A dominates label B when A arrives no later, costs no more, and is strictly better in at least one dimension. When time and cost are identical, the lexicographically smaller path is preferred.

    2.3 Lexicographic Paths and Zero-Cost Alternatives

    When two candidate paths have identical arrival times and costs, their node sequences must be compared lexicographically.

    Storing a complete path in every state and comparing lists directly becomes expensive when paths are long or candidates are numerous. An engineering approach is to first identify the optimal objective values, then perform lexicographic comparisons within the relevant candidate set. Persistent linked path structures and ranking techniques can also reduce path-comparison overhead.

    Particularly revealing hidden tests combine:

    • period = 1
    • Zero-cost edges
    • Parallel edges
    • Different prefixes that lead to the same departure after waiting

    When the period is 1, every time is a valid departure time and waiting is always zero. Zero-cost edges can leave many routes tied on the cost objective, making lexicographic ordering decisive.

    A solution that merges parallel edges solely by ((u,v)), or relies on unordered hash-table traversal to select among candidates, may produce incorrect or unstable results. Parallel edges cannot be merged indiscriminately: different phase, period, and duration values can produce different arrival possibilities depending on the current time.

    2.4 An Implementation Framework

    A practical starting point is label expansion with dominance pruning:

    1. frontier[u] = list of non-dominated labels
    2. label = (time, cost, path_rank, node)
    3. heap = min-heap ordered by (time, cost, path_rank)
    4. while heap not empty:
    5. l = pop(heap)
    6. if l is outdated: continue
    7. for edge in adjacency[l.node]:
    8. d = next_depart(l.time, edge.phase, edge.period)
    9. nt = d + edge.duration
    10. nc = l.cost + edge.cost
    11. nl = (nt, nc, extend(l.path_rank, edge.to), edge.to)
    12. if nl is dominated by frontier[edge.to]: continue
    13. remove labels in frontier[edge.to] dominated by nl
    14. insert nl; push(heap, nl)

    For pruning around the earliest-arrival objective, first compute the earliest destination arrival time (D). A reverse computation can then determine (L[v]), the latest feasible time at each node that still permits arrival by (D).

    Any prefix reaching (v) after (L[v]) cannot contribute to an earliest-arrival solution and can be discarded. This reduces unnecessary expansion, but it does not turn the multi-objective problem into a single-label problem.

    At scales of roughly one hundred thousand nodes and several hundred thousand edges, implementations must avoid scanning departure periods, using floating-point times, or copying complete paths on every expansion. Whether generated code reflects these complexity concerns is an important distinction between model tiers.

    3. Problem Two: Idempotent Replay of Out-of-Order Logs and State Snapshots

    3.1 What the Task Tests

    The second problem replays a collection of out-of-order event logs. Each event contains a timestamp, actor, idempotency key, operation type, and payload.

    The system maintains objects, each with an identifier, owner, and value. Events must be replayed in ascending order by timestamp, actor, and idempotency key. Once a key has been encountered for an actor, subsequent events with that same actor-key pair must be ignored.

    The operations follow these rules:

    • Add: Create an object only if its identifier does not already exist.
    • Move: Transfer ownership only if the actor is the current owner.
    • Delete: Delete an object only if the actor is the current owner.
    • Snapshot: Record the visible state of specified object identifiers at that point in replay. Record absent identifiers as missing.

    This problem is less algorithmically demanding than the first, but its business semantics are dense. A dictionary-based implementation that merely looks plausible can fail on ordering, when idempotency keys are consumed, ownership checks, or snapshot copying.

    3.2 Correct Implementation

    1. def reconcile(events):
    2. events = sort(events, key=(ts, actor, op_id))
    3. seen = empty set
    4. objects = empty map from id to (owner, value)
    5. snapshots = []
    6. for e in events:
    7. key = (e.actor, e.op_id)
    8. if key in seen:
    9. continue
    10. seen.add(key)
    11. if e.kind == "add":
    12. oid, value = e.payload
    13. if oid not in objects:
    14. objects[oid] = (e.actor, value)
    15. else if e.kind == "move":
    16. oid, new_owner = e.payload
    17. if oid in objects and objects[oid].owner == e.actor:
    18. objects[oid] = (new_owner, objects[oid].value)
    19. else if e.kind == "delete":
    20. oid = e.payload
    21. if oid in objects and objects[oid].owner == e.actor:
    22. remove objects[oid]
    23. else if e.kind == "snapshot":
    24. label, ids = e.payload
    25. view = []
    26. for oid in ids:
    27. if oid in objects:
    28. view.append((oid, objects[oid].owner, objects[oid].value))
    29. else:
    30. view.append((oid, missing))
    31. snapshots.append((label, view))
    32. return snapshots // Follow the output structure specified by the task.

    The following details are essential:

    • Use the complete sorting key. Sorting only by timestamp is insufficient. For equal timestamps, actor ordering can affect the outcome of ownership checks.
    • Scope idempotency keys to actors. The key is (actor, op_id), not a globally unique operation identifier. Different actors may use the same identifier.
    • Consume a key when first encountered. Record the key before applying the operation, even if that operation has no business effect. Otherwise, a later duplicate may be executed. If the specification instead consumes keys only for effective operations, that alternative contract must be explicit.
    • Do not overwrite existing objects on add. An add operation targeting an existing identifier must leave its owner and value unchanged.
    • Check existence before ownership. Moves and deletions require both an existing object and a matching current owner.
    • Preserve snapshot values. A snapshot must capture the visible values at that moment, not retain mutable object references that later operations can change.
    • Represent missing identifiers explicitly. Do not omit them or invent default values.
    • Keep snapshot work proportional to requested output. Sorting should take (O(N\log N)), with replay and hash-table updates approximately linear. Snapshot output has an unavoidable size, but each snapshot should not require copying every object in the system.

    Common model errors include applying an operation before checking duplicates, sorting only by timestamp, using a global idempotency set, overwriting existing objects, transferring without ownership validation, raising errors when deleting absent objects, retaining mutable references in snapshots, and excluding snapshot events from ordering or idempotency checks.

    4. A Shared Evaluation Matrix for Both Model Tiers

    Both problems can be assessed with the same evaluation framework.

    4.1 Basic Correctness

    Require all public examples and minimal test cases to pass. These establish a baseline, not proof that the implementation is correct.

    4.2 Edge-Case Coverage

    Include unreachable destinations, (s=t), single-node graphs, parallel edges, zero costs, and periods of 1.

    For event replay, include missing objects, duplicate operations, unauthorized transfers, and empty snapshots.

    4.3 Randomized Differential Testing

    For suitable small graph cases, exhaustively enumerate simple paths and compare the returned objective fields with a reference result. For short event sequences, implement a reference interpreter and compare all snapshot fields.

    These checks should validate the complete result, not just the primary objective.

    4.4 Complexity and Resource Use

    Generate inputs near the stated limits and measure runtime and peak memory. Check for repeated complete-path copying, excessive candidate expansion, and exponential growth in the label set.

    4.5 Repair Ability

    Provide a failing test case and assess whether the model identifies the underlying cause. A repair should address the general failure mechanism rather than patch only the supplied example.

    4.6 Maintainability

    Review variable names, boundary-condition comments, error handling, and explicitly stated assumptions. Correct code should also make its reasoning and limitations understandable.

    4.7 Cost Efficiency

    Evaluate the lightweight tier using cost per correct completion and tail latency, rather than comparing only individual response times.

    High-performance models generally have an advantage on long specifications, multiple objectives, complex state machines, and difficult repairs. Lightweight models are often better suited to clearly defined interfaces, simpler rules, and batch workloads.

    A practical deployment pattern is tiered routing: let the lightweight model handle high-confidence tasks first, then fall back to the high-performance model if static checks or hidden tests fail. Tasks involving money, permissions, or state consistency should retain human review or independent validation.

    5. Engineering Recommendations

    A robust evaluation process should version prompts, test suites, reference implementations, and execution logs together.

    Run generated code in an isolated environment with time and memory limits. Fix random seeds for reproducibility, and prevent submissions from reading hidden test data or depending on external state.

    Record more than a pass/fail result. Evaluation records should also include:

    • Failure category
    • Reproducible input
    • Number of repair attempts

    In general-purpose cloud environments, including Baidu AI Cloud, object storage can manage test suites and reference implementations, logging services can aggregate execution traces, and monitoring and alerts can help detect regressions. These infrastructure components support the evaluation workflow; they do not replace technical judgment.

    6. Conclusion

    Evaluating two-tier LLM coding capabilities means moving beyond “Can the model generate code?” to “Can it reliably deliver under constraints, edge cases, complexity limits, and precise business semantics?”

    The periodic-departure shortest-path problem exposes weaknesses in multi-objective state management, time calculations, and scalability. The event-replay problem exposes weaknesses in ordering, deduplication, ownership validation, and snapshot consistency.

    The high-performance tier is suited to complex reasoning and difficult repairs. The lightweight tier is suited to well-defined rules and high-volume workloads. Hidden tests, randomized differential testing, stress tests, and cost metrics provide a more useful basis for choosing between them than a single successful demonstration.