About

I'm a developer interested in building AI agents.

I take them apart, run them, and write down what I find.

One rule: I only write what I've verified myself — and when I haven't, I say so.

Using Codex with Claude

NP Does Not Mean Hard

Everyone Says It Wrong

"Can't do it, that's NP." The line usually means one of three things.

What people sayWhat is true
"It's NP, so you can't solve it fast"The N in NP does not stand for "no"
"NP-hard is a milder NP-complete"Backwards. NP-hard is far wider
"NP-complete means unsolvable"We solve them daily. Only unlucky inputs drag

Cook and Levin coined these in 1971, independently, and Karp carried them forward in 1972. They had one purpose — to measure how hard a problem is, and sort it.

Sorting is not filed under a complexity class. It already has a clear O(n log n) answer. A complexity class is a yardstick built for problems nobody has found a good algorithm for.

1. What Counts as Fast

P is the set of problems you can solve in polynomial time.

How running time grows

Both axes are logarithmic, so every polynomial is a straight line and only the red ones bend upward. n³ stays above 2ⁿ for a while, then gets passed around n = 10. However big the exponent, a line is still a line. That one wall is the whole standard.

Three of the names ahead (P · NP · NP-complete) attach only to questions answered "yes" or "no". "Is this number prime?", "Does the maze have a path to the exit?", "Can I get there by subway in K minutes?" are P. "Give me the cheapest route", where the answer is a route, gets no such label.

And solving in polynomial time is not enough to be in P. Sorting is the example. Its answer is not yes or no, so it cannot be in P.

2. Problems Where Only Brute Force Comes to Mind

You have a stack of receipts.

  Of n receipts, can you pick some that add up to exactly X?

Any idea? I have none beyond trying every combination. Each receipt is either in or out, so there are 2ⁿ ways.

So I measured it. I set the target to an amount that cannot be reached, which forces the search to the very end. These are real numbers off a real run.

    n   brute force (s)   vs. previous row
   16             0.008                  -
   18             0.031               3.9x     four times for every +2
   20             0.128               4.1x
   22             0.486               3.8x
   24             1.995               4.1x
   26             8.064               4.0x

Two more receipts, four times the wait. On the same machine that is 37 hours at 40 receipts and 4 years at 50 — those two I did not measure, I extended them from 26. Fifty receipts. That is not a lot. And it is four years.

There are plenty more like this. The cheapest tour through every city, an exam timetable with no clashes, packing a bag.

But "slow" is not what these have in common. That is why I am holding off on a name. What they share is on the checking side, not the solving side.

3. But Checking Is Fast

While I flail for four years, someone walks up with an answer. "Receipts 3, 7 and 12." How long to check? Add three numbers. Done.

  solving clock     try every way to choose       2^n steps
  checking clock    add up the answer handed in     n steps

Solving looks hopeless, yet checking is fast every time. Problems like this are collected under the name NP.

The Clay Mathematics Institute opens its page on the problem with exactly this idea.

If it is easy to check that a solution to a problem is correct, is it also easy to solve the problem? This is the essence of the P vs NP question.

That is the first paragraph of the Clay Institute's P vs NP page, quoted as is.

The N is not the N of non-polynomial. It is nondeterministic. Suppose someone guesses the answer and I only grade it — the name comes from that picture.

So P sits entirely inside NP. If you can solve it yourself, you can check it too. Ignore the answer handed to you, solve it again, compare. The primality test and the maze from section 1 are both in NP.

  P ⊆ NP        ⊆ means "sits inside"

The symbol ⊆ matters. Nobody knows whether P is genuinely narrower than NP. That question is P vs NP, and it has been open since 1971. It is one of the Clay Institute's seven Millennium Problems, and their official page puts the prize at a million dollars each.

4. Solving One Problem as Another — Reduction

Turning problem A into problem B and solving that instead is called reduction. The turning has to be fast.

Here is one such problem.

  Splitting teams - can these numbers be split into two piles of equal sum?
     e.g.  8, 2, 5, 5   ->   {8, 2} and {5, 5}. Both 10. Yes.

The receipt problem in section 2 asked "can you pick some that add up to the target?" You can rewrite it as splitting teams. Throw in two numbers, and the team-splitting machine solves the receipt problem for you.

  receipts   8  3  5  2,  target 10       they add up to 18

  (1) make each side total 19             19 = 18 + 1

  (2) throw in 9 and 11                   9 = 19 - 10,   11 = 19 - 8

        8  3  5  2  9  11                 total 38, half is 19

        {8, 2, 9} = 19      {3, 5, 11} = 19        it splits

        drop the 9 from its side and you have {8, 2}
        8 + 2 = 10 - the answer to the receipt problem

I solved "does it split in half?" and got "can I make 10?" for free. That is reduction.

The One That Takes It On Is Harder

  give me one team-splitting machine, and

      it splits teams           its actual job
      it solves receipts too    throw in two numbers and hand it over

  you can turn A into B   ->   B cannot be easier than A

       A = receipts,   B = splitting teams

The team-splitting machine took on both problems. So it may be harder, it may be the same, but it cannot be easier.

5. All Four Names in One Picture

  NP-hard       everything in NP reduces to it
  NP-complete   NP-hard, and in NP itself

NP-complete is the cell where NP and NP-hard overlap. That is the entire difference between the two names. And nothing says an NP-hard problem has to be in NP.

                          +------ NP-hard --------------------------------+
  +----- NP --------------+-------------------+                           |
  |                       |                   |                           |
  | +- P ---------------+ | NP-complete       |  Halting problem          |
  | | Is N prime?       | |                   |  Find cheapest route      |
  | | Maze has a path?  | | SAT               |  ^ both outside NP        |
  | | Reach B in K min? | | Subset Sum        |                           |
  | +-------------------+ | Partition         |                           |
  |                       |                   |                           |
  | Factor < K, not 1?    |                   |                           |
  | Two graphs same?      |                   |                           |
  |                       |                   |                           |
  +-----------------------+-------------------+                           |
                          +-----------------------------------------------+

Everything in the P cell has been rewritten as a yes/no question. Subset Sum is the receipt problem, Partition is splitting teams.

The two at the bottom of the NP cell are factoring and graph isomorphism. They are certainly in NP — hand me an answer and I divide, or match up the vertices — but which cell they belong to, nobody has known for decades. So they float, in neither box.

Halting problem asks "will this program ever stop, or run forever?" It is not merely hard, it is impossible. Turing proved that in 1936. Problems in NP eventually produce an answer, however slowly; this one does not, so it cannot be in NP. And yet it is NP-hard. NP-hard is not a weaker NP-complete. It is a much wider name.

6. How to Pin Down Your Problem's Complexity Class

  (1) see which kind it is, then rewrite it as a yes/no question

       decision      "can it?"             leave it
       search        "give me one"      -> "is there one?"
       optimization  "give me the best" -> "can it be done under K?"

  (2) can you write a checker      ->  it is in NP
  (3) can you write a solver       ->  it is in P
  (4) does a known NP-hard problem
      reduce to your problem       ->  NP-hard

  (5) both (2) and (4)             ->  NP-complete

  (6) go back to the original
       the yes/no version was NP-complete
          ->  the original search / optimization version is NP-hard

(2), (3) and (4) are all proved by building something — a checker, an algorithm, a reduction. If neither (3) nor (4) works, the answer is "not known yet." Failing to find something proves nothing — factoring and graph isomorphism have sat there for decades.

A Lap with the Traveling Salesman

  original     "give me the cheapest route"            optimization
  (1) rewrite  "is there a route costing K or less?"   decision

Run (2) through (5) on the rewrite and you get NP-complete. Checking is fast, since you take a route, add the distances and compare to K (2); and "is there a path through every point exactly once?", already known to be NP-complete, reduces to it (4).

Now back to the original. If you have a machine that finds the cheapest route, you solve the yes/no version just by finding it and comparing to K. The yes/no version is NP-complete, so the original is at least that hard. Hence NP-hard. It cannot be NP-complete — the answer is a route, so it does not qualify for NP.

The problem you end up calling "NP-hard" out loud is usually this optimization version.

Who Proved the First NP-complete Problem

Step (4) needs a problem that is already known, and at the very start there isn't one. The first rung of the ladder cannot be made by reduction.

Cook did it in 1971 and Levin in 1973, independently. They proved SAT is NP-complete straight from the definition. SAT hands you a formula like (A or B) and (not A) and asks whether any combination makes the whole thing true (A = false, B = true).

One first NP-complete problem was enough. After that you only had to keep reducing out from SAT, and that is how Karp got 21 in 1972 and Garey & Johnson's 1979 appendix got to 320.

In Practice You Almost Never Do (4)

Far more often, your problem already is a problem someone has settled. Then you don't write a new reduction, you just take their conclusion.

  your problem           the known problem it already is

  delivery ordering   =  traveling salesman   ->  TSP is NP-hard, so this is too
  exam timetabling    =  graph coloring
  job assignment      =  splitting teams
  package versioning  =  SAT

Recognizing "wait, this is the traveling salesman" is the skill you actually use.

7. Who Made These

WhoWhenWhat they did
Hartmanis · Stearns1965Made the field itself. The name "computational complexity", the idea of grouping problems by resource budget (complexity class), the time hierarchy theorem
Cobham · Edmonds1965Defined P. Independently proposed "polynomial time = solvable in practice". Hence the Cobham–Edmonds thesis
Cook · Levin1971Made NP-completeness. Independently. SAT was the first NP-complete problem
Karp1972Proved it was useful. Showed 21 classic problems are all NP-complete, turning a theory into a tool
Garey & Johnson1979Organized it. A textbook plus a list of 320, built so a practitioner can look things up
  1965  Hartmanis, Stearns  "group problems by resource budget"  <- the frame
  1965  Cobham, Edmonds     "polynomial time is the line"        <- P
  1971  Cook, Levin         "some groups are fast to check"      <- NP, NP-complete
  1972  Karp                "and it catches 21 real problems"    <- spread
  1979  Garey & Johnson     "320 of them, indexed for lookup"    <- the dictionary

The last two invented nothing — they applied and organized. That is also why Karp and Garey & Johnson are famous: they took a concept off the desk and made it usable by people doing the work.

8. Yardsticks Other Than Time

Big-O predates complexity theory by 70 years. The mathematician Paul Bachmann introduced it in 1894, Landau extended it in 1909, and Knuth brought it into computer science.

There is also more than one complexity class. The yardstick changes with what you count as the resource, and P and NP are just the "time" one.

  time      P, NP, EXP    how many steps it takes
  space     L, PSPACE     how much memory it uses
  random    BPP, RP       if you may flip coins
  quantum   BQP           on a quantum computer
  parallel  NC            if you may use many machines at once

This post covers only time because that is what you run into most at work.

What I Am Not Sure About

  • Nobody has proved P ≠ NP. The overlap diagram assumes it.
  • Cook 1971's five come from a transliteration of the original, and the 320 in Garey & Johnson's appendix I counted myself, category by category, from the book. Levin 1973's six come from the English translation; Karp 1972's 21 come from secondary sources.
  • What the Clay page confirms is "Cook and Levin formulated P vs NP independently in 1971", and no more. Levin 1973 is the publication year.
  • The measurements are Python brute force, so absolute times shift with the language and the machine. Take only the four-times-per-two-more. The 40 and 50 figures were not measured — they were extended from 26 (8.064 s) by 2ⁿ.

Sources

Every number here was counted at the source.

The people who made the names

  • Hartmanis · Stearns 1965 · Juris Hartmanis, Richard E. Stearns, On the Computational Complexity of Algorithms, Transactions of the AMS 117. The paper that made the field and its name. The time hierarchy theorem in it proves that some cells really are separated. Turing Award 1993.
  • Cobham 1965 · Alan Cobham, The Intrinsic Computational Difficulty of Functions. Generally credited as the first to single out P.
  • Edmonds 1965 · Jack Edmonds, Paths, Trees, and Flowers, Canadian Journal of Mathematics 17. Same year, separately. Together they give the Cobham–Edmonds thesis.

NP and NP-complete

  • Cook 1971 · Stephen A. Cook, The Complexity of Theorem-Proving Procedures, STOC 1971. The first rung. He lists five problems that look hard; of those, primality dropped to P in 2002 and graph isomorphism is still open. — transliteration
  • Levin 1973 · Leonid A. Levin, Universal Sequential Search Problems, Problems of Information Transmission 9(3), 265–266. Independently of Cook. Six problems, phrased as "find one" rather than "does one exist". — English translation
  • Karp 1972 · Richard M. Karp, Reducibility Among Combinatorial Problems, Complexity of Computer Computations, Plenum Press, 85–103. The ladder goes up and one paper adds 21. — paper page
  • Garey & Johnson 1979 · Michael R. Garey, David S. Johnson, Computers and Intractability: A Guide to the Theory of NP-Completeness, W. H. Freeman. The first book devoted to NP-completeness. The appendix carries 320, and a (*) after a name marks that NP membership was never established — that is, NP-hard rather than NP-complete.

Everything else in the post

  • Turing 1936 · Alan M. Turing, On Computable Numbers, with an Application to the Entscheidungsproblem, Proc. London Mathematical Society. The proof that the halting problem cannot be solved.
  • AKS 2002 · Manindra Agrawal, Neeraj Kayal, Nitin Saxena, PRIMES is in P, 6 August 2002. The day primality dropped into P. Gödel Prize and Fulkerson Prize, both 2006.
  • Big-O notation · Introduced by Paul Bachmann in 1894 and extended by Edmund Landau in 1909. Also called Bachmann–Landau notation.
  • Clay Mathematics Institute · P vs NP · Millennium Problems. The English quotation and the prize figure were checked here.

More to Watch

Classifying 1 - There Are 75 Famous Problems

Remembering algorithm problems does not mean memorizing every problem you have solved. The number of problems keeps growing, but the original problems underneath them do not. Some of them have names, and most new problems are a small change to one of those.

The cleanest list of them is Steven Skiena's Stony Brook Algorithm Repository. The site introduces itself this way — a collection of implementations for the 75 most fundamental problems.

1. Seven Categories, 75 Problems

  Data Structures                   6
  Numerical Problems               11
  Combinatorial Problems           10
  Graph: Polynomial-time Problems  12
  Graph: Hard Problems             11
  Computational Geometry           16
  Set and String Problems           9
                                   --
                                   75

The split is by topic. Data structures, numbers, combinatorics, geometry, sets and strings. Only graphs are cut in two.

Polynomial-time and Hard. Difficulty is in the category name.

No other category does this. And the hard problems are not only in graphs — Satisfiability just sits in Combinatorial, Knapsack Problem just sits in Numerical.

The Hard side is probably NP-hard problems, or ones nobody has solved yet.

  Polynomial-time   Shortest Path . Minimum Spanning Tree . Topological Sorting .
                    Connected Components . Matching . Network Flow ...

  Hard              Clique . Independent Set . Vertex Cover .
                    Traveling Salesman . Hamiltonian Cycle . Vertex Coloring ...

If your problem is on the Hard side, stop looking for a fast algorithm. No one has found one in decades. Instead, rely on the input being small, take an answer that is good enough, or get by with pruning.

A longer list of the hard ones is in the appendix of Garey & Johnson 1979. It has 320 problems written the same way. For the hard problems, see NP Does Not Mean Hard.

2. What One Entry Looks Like

Every entry I opened had the same eight fields. Here is Topological Sorting copied out in full.

  Topological Sorting

  Input  [figure]     dots scattered, arrows running every which way
  Output [figure]     dots in one row, every arrow pointing right

  Input Description   A directed, acyclic graph G=(V,E)
                      (also known as a partial order or poset).

  Problem             Find a linear ordering of the vertices of V such that
                      for each edge (i,j) in E, vertex i is to the left of
                      vertex j.

  Excerpt             Topological sorting arises as a natural subproblem in
                      most algorithms on directed acyclic graphs. ...

  Implementations     Boost Graph Library (10) . LEDA (9) . JGraphT (8) .
                      JDSL (8) . goraph (8) ...

  Recommended Books   Sedgewick & Schidlowsky, Algorithms in Java .
                      Cormen et al., Introduction to Algorithms .
                      Manber, Introduction to Algorithms

  Related Problems    Bandwidth Reduction . Feedback Edge/Vertex Set .
                      Job Scheduling . Sorting

Implementations is there so that when you build something, you can get code for it.

3. Similar Problems Live in Other Categories

Topological Sorting is in a graph category. But all four problems listed as similar to it are in other categories.

  Topological Sorting           Graph: Polynomial-time
     Sorting                       Combinatorial
     Job Scheduling                Combinatorial
     Bandwidth Reduction           Numerical
     Feedback Edge/Vertex Set      Graph: Hard

The grouping is not wrong. If you made a new category every time two problems looked alike, the categories would never stop growing. Skiena did not do that. He put a Related Problems field on every entry instead.

So the categories stay few — seven — and you follow similar problems from there.

4. Memorize Problems, Not Algorithms

Memorize Dijkstra and all you have is one algorithm. Try memorizing this instead.

  Input    a graph with weights on the edges, a start s, a target t
  Output   the shortest path from s to t

That is Shortest Path. A subway transfer, a delivery route, pathfinding in a game — the Input and Output all have that shape. Memorize one and you recognize every problem shaped like it.

That is why writing entries as Input and Output is good. You can hold a new problem up against that shape and compare. Memorize by algorithm name and you can only use it after the name comes to mind.

5. The Book It Came From

This list is the catalog from Part II of Skiena's The Algorithm Design Manual, 3rd edition — "The Hitchhiker's Guide to Algorithms" — put online. The site says that part was made for looking things up. The seven chapters of Part II are the seven categories on the site.

The book has longer explanations; the site keeps its implementation links up to date.

6. The 75 Names

Some names make it hard to tell what the problem is. The Input and Output for all 75 are written out one line each.

  Data Structures
     Dictionaries
     Priority Queues
     Suffix Trees and Arrays
     Graph Data Structures
     Set Data Structures
     Kd-Trees

  Numerical Problems
     Solving Linear Equations
     Bandwidth Reduction
     Matrix Multiplication
     Determinants and Permanents
     Constrained and Unconstrained Optimization
     Linear Programming
     Random Number Generation
     Factoring and Primality Testing
     Arbitrary-Precision Arithmetic
     Knapsack Problem
     Discrete Fourier Transform

  Combinatorial Problems
     Sorting
     Searching
     Median and Selection
     Generating Permutations
     Generating Subsets
     Generating Partitions
     Generating Graphs
     Calendrical Calculations
     Job Scheduling
     Satisfiability

  Graph: Polynomial-time Problems
     Connected Components
     Topological Sorting
     Minimum Spanning Tree
     Shortest Path
     Transitive Closure and Reduction
     Matching
     Eulerian Cycle/Chinese Postman
     Edge and Vertex Connectivity
     Network Flow
     Drawing Graphs Nicely
     Drawing Trees
     Planarity Detection and Embedding

  Graph: Hard Problems
     Clique
     Independent Set
     Vertex Cover
     Traveling Salesman Problem
     Hamiltonian Cycle
     Graph Partition
     Vertex Coloring
     Edge Coloring
     Graph Isomorphism
     Steiner Tree
     Feedback Edge/Vertex Set

  Computational Geometry
     Robust Geometric Primitives
     Convex Hull
     Triangulation
     Voronoi Diagrams
     Nearest Neighbor Search
     Range Search
     Point Location
     Intersection Detection
     Bin Packing
     Medial-Axis Transform
     Polygon Partitioning
     Simplifying Polygons
     Shape Similarity
     Motion Planning
     Maintaining Line Arrangements
     Minkowski Sum

  Set and String Problems
     Set Cover
     Set Packing
     String Matching
     Approximate String Matching
     Text Compression
     Cryptography
     Finite State Machine Minimization
     Longest Common Substring/Subsequence
     Shortest Common Superstring

Sources

  • Stony Brook Algorithm Repository · algorist.com. The category names and counts, the list in section 6, and the quoted entry were all checked here.
  • Skiena 2020 · Steven S. Skiena, The Algorithm Design Manual, 3rd edition, Springer. The list above is the catalog from Part II of this book, "The Hitchhiker's Guide to Algorithms", put online.
  • Garey & Johnson 1979 · Michael R. Garey, David S. Johnson, Computers and Intractability: A Guide to the Theory of NP-Completeness, W. H. Freeman. 320 in the appendix.

Classifying Appendix - All 75

This is the list from There Are 75 Famous Problems, with one line of Input and Output for each problem. Many names do not tell you what the problem is.

These are my own short versions, not the originals. The exact definitions are in each entry of the Stony Brook Algorithm Repository (algorist.com).

Data Structures

ProblemInOut
Dictionariesn records, each with a keya structure that finds, inserts and deletes a record by its key
Priority Queuesrecords with ordered keysa structure that always hands back the smallest, and stays fast as records come and go
Suffix Trees and Arraysa reference stringa structure that finds every place a query string sits inside it
Graph Data Structuresa grapha representation that is small to store and quick to walk
Set Data Structuresa universe of objects and a family of subsetsa representation that tests membership and takes unions and intersections quickly
Kd-Treesn points in k dimensionsa tree splitting the space so each point sits in its own region

Numerical Problems

ProblemInOut
Solving Linear Equationsa matrix A and a vector bthe x with A·x = b
Bandwidth Reductiona graph that represents a sparse matrixthe ordering of vertices that makes the longest edge as short as possible
Matrix Multiplicationtwo matricestheir product
Determinants and Permanentsan n x n matrixits determinant, or its permanent
Constrained and Unconstrained Optimizationa function of n variablesthe point where it is largest, or smallest
Linear Programminglinear inequalities and a linear objectivevalues that satisfy all of them and make the objective as large as possible
Random Number Generationnothing, or a seeda sequence of integers that behaves like a random one
Factoring and Primality Testingan integer nwhether n is prime, and if not, its factors
Arbitrary-Precision Arithmetictwo integers too big for a machine wordtheir sum, difference, product and quotient
Knapsack Problemitems with a size and a value, and a capacitythe subset of greatest value that still fits
Discrete Fourier Transformn values sampled from a function at even intervalsthe same signal written as a sum of frequencies

Combinatorial Problems

ProblemInOut
Sortingn itemsthe same items in increasing order
Searchingn keys and a query keywhere the query sits among them
Median and Selectionn numbersthe one with half below it and half above
Generating Permutationsan integer nevery ordering of n things, or a random one, or the next one
Generating Subsetsan integer nevery subset of 1..n, or a random one, or the next one
Generating Partitionsan integer nevery way to split n, or a random one, or the next one
Generating Graphsa vertex count, an edge count, or an edge probabilitya graph that meets them — every such graph, a random one, or the next
Calendrical Calculationsa month, a day and a yearthe weekday it fell on
Job Schedulingjobs with "this one before that one" constraintsa schedule finishing in the least time, or on the fewest machines
Satisfiabilityclauses built from ands, ors and nots on boolean variableswhether some assignment makes every clause true

Graph: Polynomial-time Problems

ProblemInOut
Connected Componentsa graph and a start vertexevery vertex and edge reachable from it
Topological Sortinga directed acyclic graphthe vertices in a row with every edge pointing right
Minimum Spanning Treea graph with weighted edgesthe cheapest set of edges that still connects everything
Shortest Patha weighted graph, a start s and an end tthe cheapest route from s to t
Transitive Closure and Reductiona directed graphan edge wherever a path exists, or the fewest edges that still let you reach the same places
Matchinga graph, possibly weightedthe largest set of edges sharing no vertex
Eulerian Cycle / Chinese Postmana graphthe shortest tour using every edge at least once
Edge and Vertex Connectivitya graph, optionally two verticesthe fewest edges or vertices you can remove to break it apart
Network Flowa graph with capacities, a source and a sinkthe most that can be pushed from source to sink
Drawing Graphs Nicelya grapha drawing that shows its structure
Drawing Treesa treea drawing of it
Planarity Detection and Embeddinga graphwhether it can be drawn with no edges crossing, and such a drawing

Graph: Hard Problems

ProblemInOut
Cliquea graphthe largest set of vertices all joined to each other
Independent Seta graphthe largest set of vertices with no edge between any two
Vertex Covera graphthe smallest set of vertices touching every edge
Traveling Salesman Problema weighted graphthe cheapest cycle through every vertex exactly once
Hamiltonian Cyclea graphan order visiting every vertex exactly once
Graph Partitiona weighted graph, a size bound and a cost bounda split into parts no bigger than the size bound, cutting no more than the cost bound
Vertex Coloringa grapha coloring of the vertices using the fewest colors, so that no two neighbors match
Edge Coloringa graphthe fewest colors for the edges so that edges meeting at a vertex differ
Graph Isomorphismtwo graphsa relabeling that turns one graph into the other, if such a relabeling exists
Steiner Treea graph and a subset of its verticesthe smallest tree connecting that subset
Feedback Edge/Vertex Seta directed graphthe fewest edges or vertices to remove so that no cycle is left

Computational Geometry

ProblemInOut
Robust Geometric Primitivesa point and a segment, or two segmentswhich side the point is on, or whether the segments cross — without rounding errors giving a wrong answer
Convex Hulln pointsthe smallest convex polygon holding them all
Triangulationa point set or a polyhedronits interior cut into triangles
Voronoi Diagramsn pointsthe region around each point closer to it than to any other
Nearest Neighbor Searchn points and a query pointthe closest one
Range Searchn points and a query polygonthe points falling inside it
Point Locationa plane cut into regions, and a query pointthe region it falls in
Intersection Detectionsegments, or two polygonswhich pairs cross, or the shape they share
Bin Packingitems with sizes, bins with capacitiesa packing using as few bins as possible
Medial-Axis Transforma polygonthe points inside that have more than one nearest point on the boundary — its skeleton
Polygon Partitioninga polygona cut into as few simple pieces as possible, usually convex ones
Simplifying Polygonsa polygon with n verticesone with fewer vertices that still looks like it
Shape Similaritytwo shapeshow alike they are
Motion Planninga robot, a room with obstacles, a start and an endthe shortest path that gets the robot across without hitting anything
Maintaining Line Arrangementsn lines and segmentsthe cells, edges and vertices they cut the plane into
Minkowski Sumtwo point sets or polygonsevery sum of a point from one and a point from the other

Set and String Problems

ProblemInOut
Set Coversubsets of a universethe fewest of them whose union is the whole universe
Set Packingsubsets of a universethe most of them that share no element
String Matchinga text and a patternwhere the pattern occurs
Approximate String Matchinga text, a pattern, and an edit budgetwhether the pattern appears somewhere after that many edits or fewer
Text Compressiona stringa shorter string the original can be rebuilt from
Cryptographya message and a keythe encrypted text, or the message back
Finite State Machine Minimizationa deterministic finite state machinethe smallest one that behaves the same way
Longest Common Substring/Subsequencea set of stringsthe longest run of characters appearing, in order, in all of them
Shortest Common Superstringa set of stringsthe shortest string containing every one of them

Classifying 2 - There Are 55 Coding Interview Problems

In There Are 75 Famous Problems we saw Skiena write an Input and an Output for every problem. No algorithm name appears, so you can find an entry knowing only what you have and what you want.

You cannot use those 75 for a coding interview as they are. Voronoi Diagrams and Medial-Axis Transform do not come up in interviews. Different problems do.

So I built the list for interviews the same way. I went back through about 3,000 problems I had solved on LeetCode.

1. In and Out Alone Do Not Tell Them Apart

At first I followed Skiena exactly and wrote only the two fields. Then this happened.

  Largest run                      the contiguous run with the largest sum
                                   array -> one number
  Longest increasing subsequence   the longest increasing subsequence
                                   array -> one number

You cannot tell them apart. Contiguous or skipping is what decides the method, and it does not show up in In or Out. So I added one more field.

  In                    what goes in
  Out                   what comes out
  Splitting question    In and Out are the same, but the method changes here

Those two split right here — does it have to be contiguous?

  yes   Largest run
  no    Longest increasing subsequence

The third field is the one you actually use. Read the problem, and if you can answer the splitting question, the method is settled.

2. Nine Categories, 55 Problems

  Skiena      categories 7    problems 75      all of computer science
  this list   categories 9    problems 55      what shows up in interviews

There is no reason behind the number 55. It is a starting point. All I fixed were the rules for growing and shrinking it.

  split    when the difference changes the method or the "why is this correct"
  merge    when two entries produce the same reasoning
  add      when you keep getting something wrong in review and no entry covers it

Arrays and Ranges

ProblemInOutSplitting questionExamples
Window over a sequencenumbers or letters in a row, and one conditionthe shortest or longest run that satisfies the conditiondoes the condition change monotonically as you widen and shrink the window. if the condition is about a sum, one negative number breaks itLongest Substring Without Repeating Characters · Minimum Size Subarray Sum
Largest runnumbers in a rowthe run with the largest sum or productit must be contiguous. picking non-adjacent items is a different problemMaximum Subarray · Maximum Product Subarray
Longest increasing subsequencenumbers or items in a rowthe length of the longest subsequence that only goes upmust it be contiguous. if you may skip, keep only the tail values and binary searchLongest Increasing Subsequence · Russian Doll Envelopes
Next greater elementnumbers in a rowfor each position, the first larger or smaller value it meets, or the range those values defineif an earlier element is smaller than the current one, is it useless foreverDaily Temperatures · Largest Rectangle in Histogram
Prefix and rangea sequence or a matrix, plus repeated range questionsthe sum or minimum of each rangedo values change in between. if not, prefix sums; if so, a treeRange Sum Query - Immutable · Range Sum Query 2D - Mutable
Kth elementunsorted values and kthe kth largest or smallest valuedo you need just the kth one, or all k of themKth Largest Element in an Array · Top K Frequent Elements
Count and tallyvalueshow many times, is there a majority, which value is missingis the range of values narrow. if it is, counting alone is enoughMajority Element · First Missing Positive
Pair with targetnumbers and a targetthe two or three that sum to the targetmay you sort. if yes, two ends; if no, a hashTwo Sum · 3Sum

Order and Priority

ProblemInOutSplitting questionExamples
Boundary by monotonicitysomething sorted or monotone, and a true/false testthe point where the test first turns trueis the answer itself monotone. then binary search on the valueSearch in Rotated Sorted Array · Koko Eating Bananas
Two ends moving ina row that is sorted, or that you may sorta pair, an area, or a count you get by closing in from both endsdo you close in from both ends, or fix one side and close inTwo Sum II - Input Array Is Sorted · Valid Triangle Number
Intervalsintervals with a start and an endmerged, maximum overlap, or the most you can picksort by start or sort by end. it depends on what you wantMerge Intervals · Non-overlapping Intervals
Pull the best one nexta situation where you must take the best or worst each timethe result after processing everythingdo the candidates change after each pull. if not, just sortMerge k Sorted Lists · Meeting Rooms II
Sort then scanitems you must decide a sort order forthe answer you get from one sort and one passdoes fixing one criterion make the rest simpleLargest Number · Queue Reconstruction by Height

Grids and Matrices

ProblemInOutSplitting questionExamples
Walk a grida grid and a starting cellthe cells you reach, the number of blobs, or the fewest stepsis there one start or many. with many you spread from all of them at onceNumber of Islands · Walls and Gates
Transform in placea matrixrotated, transposed, or markedmust you use no extra space. then swap in layersRotate Image · Set Matrix Zeroes
Grid DPa grid and a cost per cellthe best value from one corner to the opposite onedoes it only move one way. if you can come back, first check there is no cycleMinimum Path Sum · Longest Increasing Path in a Matrix
Search a sorted grida matrix sorted by row and column, and a value to findis it thereis it still sorted if you flatten it into one row. if not, start from a cornerSearch a 2D Matrix · Search a 2D Matrix II
Simulate on a grida grid and a rule that changes itthe next state, or the result of applying the rule until nothing changesdo the updates happen all at once or one after anotherGame of Life · Candy Crush

Strings

ProblemInOutSplitting questionExamples
Palindromea stringis it a palindrome, or the longest palindromic piecedo you expand from the middle or close in from both endsLongest Palindromic Substring · Valid Palindrome
Brackets and expressionsa string with brackets or operatorsis it valid, the computed value, or the expanded resultis there nesting. if yes, a stack; if no, counting aloneMinimum Add to Make Parentheses Valid · Basic Calculator
Edit distancetwo stringsthe fewest operations to turn one into the otherwhich operations are allowed. remove the replace operation and it becomes a different problemEdit Distance · Delete Operation for Two Strings
Common subsequencetwo strings or two arraysthe longest thing contained in bothmust it be contiguous. if you may skip, it is a subsequenceLongest Common Subsequence · Maximum Length of Repeated Subarray
Pattern in texta long text and one or more pieces to findwhere the pieces occuris there more than one piece. with many, a trie or a hashFind All Anagrams in a String · Add Bold Tag in String
Prefix setseveral wordsfinding the words that share a prefixare the queries repeated. for a single one a trie is not worth buildingLongest Common Prefix · Word Search II
Same lettersone string or severalare the letter counts the same, grouping the ones that matchare you only checking whether two match, or grouping all of themValid Anagram · Group Anagrams
Rewrite a stringa string with a rule written in itthe result of applying the ruledoes the rule finish in one pass, or apply again to what came outDecode String · Count and Say

Trees

ProblemInOutSplitting questionExamples
Walk a treea treethe visiting order, or a value gathered on the waydo you carry something down, or gather something upPath Sum · Maximum Depth of Binary Tree
Tree DPa tree and a value per nodethe best value collected from the subtrees belowis one value enough to send up from a child, or do you need severalBinary Tree Maximum Path Sum · House Robber III
Build a treetraversal output or a serialized stringthe original treewhere in the input is the rootConstruct Binary Tree from Preorder and Inorder Traversal · Construct Binary Tree from Inorder and Postorder Traversal
Binary search treea tree with the sorted propertyinsert, delete, kth, or validatedo you build a tree from a sorted sequence, or pull a sorted sequence out of a treeConvert Sorted Array to Binary Search Tree · Kth Smallest Element in a BST
Lowest common ancestora tree and two nodestheir nearest common ancestorcan you use the sorted property. in a binary search tree one walk down from the root solves itLowest Common Ancestor of a Binary Search Tree · Lowest Common Ancestor of a Binary Tree

Graphs

ProblemInOutSplitting questionExamples
Connected componentsvertices and edges, or a gridhow many blobs, are these two in the same blob, which edge closes a cycledo the edges arrive all at once or one at a timeNumber of Connected Components in an Undirected Graph · Redundant Connection
Topological ordertasks with precedencean execution order, or whether such an order exists at allwith a cycle there is no answer. checking for one is half the problemCourse Schedule · Course Schedule II
Shortest patha graph and a start, plus a target if neededthe least cost or the fewest stepsare all weights 1, are any negative. the method splits three waysWord Ladder · Network Delay Time
Cyclea graph or a linked listis there a cycle, where does it start, which parts never reach a cycleis there one next, or several branches. with branches you need a separate in-progress markLinked List Cycle II · Find Eventual Safe States
Spanning and flowa graph with weights or capacitiesthe cheapest way to connect everything, the most you can push through, the largest matchingdoes it split into two sides. if it does, it becomes a matching problemMin Cost to Connect All Points · Maximum Number of Accepted Invitations

States and Choices

ProblemInOutSplitting questionExamples
Carry state forwarda few states to choose from at each stepthe best value at the last stepdo you know the number of states in advance, or does it grow with the inputBest Time to Buy and Sell Stock · Best Time to Buy and Sell Stock IV
Count the waysa grid or steps, plus constraintshow many ways reach the endare the places you can go fixed from the start, or do you have to read the inputUnique Paths · Decode Ways
Interval DPa row, and an operation that works on intervalsthe best cost of merging the whole thingdoes it split on what you do lastBurst Balloons · Strange Printer
Knapsackitems with a size and a value, and a limitthe best value chosen against a limit or a targetdo you use the same item more than once. if so the loop runs the other wayOnes and Zeroes · Coin Change
List every arrangementa small n and constraintsevery arrangement that satisfies the constraintscan you prune. if not there are too many answersLetter Combinations of a Phone Number · Generate Parentheses
Small n, every subsetn around 20, a different value per subsetthe best value after trying everythingis the subset enough to describe the state, or must you also track where you areCan I Win · Android Unlock Patterns
Win or losea game with alternating movesdoes the first player windoes the board split into independent piles. if it does, Grundy numbersNim Game · Flip Game II

Numbers

ProblemInOutSplitting questionExamples
Digits and basesone number, or a number written as a stringdigits handled, or the base changeddoes it go past the type range. if so, treat it as a stringReverse Integer · Excel Sheet Column Title
Divisors and primesone number or a rangeis it prime, how many primes, what are the divisorsdo you look at one number or at a range. for a range, build a sievePrime Palindrome · Count Primes
Bit tricksnumbersa value you get with bit operationshow many of each are paired up. with two, one XOR solves itSingle Number · Single Number II
Combinatoricsn and a modulus, plus k if neededthe number of casesis there a division. if so you need an inverseCount All Valid Pickup and Delivery Options · Number of Ways to Reorder Array to Get Same BST
Chance and samplinga situation that needs randomnessa result where every choice is equally likelydo you know the total size in advance. if not, pick as the items go pastShuffle an Array · Linked List Random Node
Geometrypoints or shapesdistance, containment, or the enclosing shapedo you use floats. if so, rounding error is half the problemMax Points on a Line · Generate Random Point in a Circle

Data Structures

ProblemInOutSplitting questionExamples
Design a structurea list of operations and a time limita structure where all of them are fastdo you do the work on the way in, or on the way outTwo Sum III - Data structure design · Design Twitter
Cache and evictiona capacity limit and an access loga structure that decides what to keep and what to dropis the eviction rule time or countLRU Cache · LFU Cache
Stack and queue disciplinea rule where you push and pop at one end onlya structure that answers extra queries while keeping that ruledo they also ask for something like the minimumMin Stack · Implement Stack using Queues
Key to valuekeys and values, and the operations requireda structure where insert, delete and lookup are all constant timeis there also a random pick. if so, keep an array alongsideDesign HashMap · Insert Delete GetRandom O(1) - Duplicates allowed
Iterate on demandnested or compressed dataan iterator that hands them over one at a timemay you expand everything in advance. if not, make it lazyFlatten Nested List Iterator · Binary Search Tree Iterator
Linked list surgerya chain of nodesreverse, cut, merge, find a cycledo you know the length in advance. if not, use two pointersRemove Nth Node From End of List · Reverse Linked List II

3. How To Use It

Cover the right-hand side and look at the three fields on the left. When you read a problem and can answer the splitting question, that problem is solved. When no answer comes, that is what you need to study again.

Classifying 3 - In an Interview, Nobody Tells You the Name

The table in There Are 55 Coding Interview Problems reads left to right. The entry name comes first, and the Input and Output sit next to it.

An interview is the opposite. You get one problem statement, and no entry name comes with it. So for the list to be usable, it has to read right to left as well.

1. What You Can See in the Statement

Some things stand out as you read a statement. Not algorithm names — things that are simply written there.

If the statement saysCandidatesSplitting question
it is sorted · you may sort itTwo ends moving in · Boundary by monotonicityare you finding a pair or finding a boundary
a contiguous runWindow over a sequence · Largest runa run that satisfies a condition, or a run with the largest sum
the longest thing that only goes upLongest increasing subsequencemust it be contiguous
the first larger or smaller thing at each positionNext greater elementif an earlier element is smaller than the current one, is it useless forever
ranges asked about many timesPrefix and rangedo values change in between
the kthKth element · Pull the best one nextasked once, or asked over and over
the two or three that sum to the targetPair with targetmay you sort
how many times · a majority · a missing valueCount and tallyis the range of values narrow
you have to decide how to sort it firstSort then scandoes fixing one criterion make the rest simple
things with a start and an endIntervalssort by start, or sort by end
some tasks must come firstTopological ordera cycle means there is no answer
islands · blobs · are these two in the same blobConnected componentsdo the edges arrive all at once or one at a time
is there a cycleCycleis there one next, or several branches
cheapest way to connect everything · most you can pushSpanning and flowdoes it split into two sides
least cost · fewest stepsShortest pathare all weights 1, are any negative
a gridWalk a grid · Grid DP · Simulate on a griddoes it spread, go one way only, or repeat a rule
a table sorted along every row and every columnSearch a sorted gridis it still sorted if you flatten it into one row
rotate or flip the matrixTransform in placemust you use no extra space
a treeWalk a tree · Tree DPdoes one pass finish it, or do you choose for each subtree on the way up
traversal output is givenBuild a treewhere in the input is the root
a tree with smaller on the left, larger on the rightBinary search treedo you build the sorted sequence, or pull it out
the common ancestor of two nodesLowest common ancestorcan you use the sorted property
a palindromePalindromedo you expand from the middle or close in from both ends
brackets or operatorsBrackets and expressionsis there nesting
two strings or two arraysEdit distance · Common subsequencethe cost of fixing, or the thing they share
find a piece inside a long textPattern in textis there more than one piece
words starting with this prefixPrefix setare the queries repeated
are the letters just in a different orderSame lettersare you only checking whether two match, or grouping all of them
rewrite it by a ruleRewrite a stringdoes the rule finish in one pass, or apply again to what came out
you choose at every stepCarry state forwarddo you know the number of states in advance, or does it grow with the input
how many waysCount the ways · Combinatoricscount up one step at a time, or count it all at once with a formula
you merge intervals as you goInterval DPdoes it split on what you do last
you choose against a limit or a targetKnapsackdo you use the same item more than once
show me every arrangementList every arrangementcan you prune
the set of what you picked is the stateSmall n, every subsetis the subset enough as state, or must you carry where you are too
players take turnsWin or losedoes the board split into independent piles
everything is paired except oneBit trickshow many of each are paired up
primes · divisors · multiplesDivisors and primesdo you look at one number, or at a range
bases · digits · very large numbersDigits and basesdoes it go past the type range
draw at randomChance and samplingdo you know the total size in advance
a list of operations and a time limitDesign a structuredo you do the work on the way in, or on the way out
throw something away when it is fullCache and evictionis the eviction rule time or count
you push and pop at one end onlyStack and queue disciplinedo they also ask for something like the minimum
insert, delete and lookup must all be fastKey to valueis there also a random pick
hand them to me one at a timeIterate on demandmay you expand everything in advance
the nodes are chained togetherLinked list surgerydo you know the length in advance

The left column is visible before you know the answer. You can only reach Monotonic Stack after monotonic stacks have already come to mind. "The first larger thing at each position" is simply written in the statement.

One of part 2's 55 is missing here. Geometry has no signal you can recognize in a statement beyond "a shape shows up". It is worth knowing that some entries have a weak signal — for those, the only way is to know them on sight.

2. The Constraints Are Part of the Statement

When the size of n is written down, the complexity of the answer is nearly settled.

  n <= 20          2^n           look at every subset
  n <= 40          2^(n/2)       split in half and meet
  n <= 500         n^3
  n <= 5,000       n^2
  n <= 10^5        n log n       sorting . binary search . heap . segment tree
  n <= 10^7        n             one pass
  values to 10^9   log(value) or math    the number itself is large, not its size

But this narrows it down; it does not settle it. With n <= 20 it could be bitmask DP or it could be plain backtracking. It only cuts the candidates down to a few.

3. When There Is More Than One Candidate

This is where it really starts. When the signal has narrowed it to two or three and you do not know which to use, ask in this order.

  (1) what does it look like if you just try everything
  (2) why is that slow
  (3) what do you not have to redo
  (4) so what do you use
  (5) why is that correct

Try the shortest run whose sum is at least K.

  (1)  look at every run                        n^2
  (2)  every time the left end moves, you add the sum up from scratch
  (3)  the left end never has to go back -- extend right, then pull left
  (4)  sliding window
  (5)  once the sum reaches K you may pull the left in, and when it is too
       small you must extend the right. Neither side ever moves backwards,
       so you look at each element at most twice

(3) is the answer. The rest are questions for getting there.

And if (3) does not come, you do not know that problem yet. Whether the name came to mind has nothing to do with it. You can say "sliding window" and still be stuck the moment the problem changes a little, if you cannot do (3).

Mix in negative numbers and (3) breaks. Pulling the left in is no longer guaranteed to make the sum go down. That is why the splitting question for this entry is written the way it is.

4. How To Review

  cover the right, look only at the left   recall in this order: signal -> candidates -> splitting question
  get stuck? say (1) to (5) out loud       find out if you get stuck at (3) or at (4)
  look at the ones you got wrong more often
  come back later to the ones you got right   of course you get it right if you look again right away

When you mix, mix the ones you confuse with each other. Not a random shuffle. Window over a sequence and Largest run have almost the same Input and Output — put those two side by side. There is one question to ask: why does this one use that method when the one next to it does not?

Mixing Makes You Worse While You Practice

Someone measured this with math problems. They taught 18 college students how to find the volume of four unfamiliar solids. One group practiced grouped by type, the other with the four types mixed together. Same problems, same count, only the order was different.

  during practice         grouped  89%     mixed  60%
  test one week later     grouped  20%     mixed  63%

The reason they got them wrong matters. The grouped side did not make arithmetic errors — they picked the wrong formula. When they picked the right formula, they nearly always got the right answer.

Practice in a block and you never have to choose which kind of problem it is. You are told in advance. Do ten Largest run problems in a row and you start all ten knowing the answer. In an interview nobody tells you.

And yet the grouped side does better while practicing. 89% against 60%. So mixing feels worse. In another experiment, where people had to name the painter of a painting, 78% of the 120 participants did better when the paintings were mixed. And 78% said grouping was as good or better. They still said that after taking the test. What it feels like is the opposite of what works.

Both were measured on undergraduates in a lab. Rohrer & Taylor listed four limits of their own experiment. One of them matters most for interviews: the test problems had the same shape as the practice problems. So they did not measure whether mixing still helps on a problem you have never seen before.

And say it out loud. An interview is not a test of solving. It is a test of showing how you solve, and if you only ever practice quietly on your own, that part never gets trained. Saying (1) through (5) out loud reviews the problem and practices talking at the same time.

Sources

  • Rohrer & Taylor 2007 · Doug Rohrer, Kelli Taylor, "The shuffling of mathematics problems improves learning", Instructional Science 35:481-498. The figures above are from Experiment 2.
  • Kornell & Bjork 2008 · Nate Kornell, Robert A. Bjork, "Learning Concepts and Categories: Is Spacing the 'Enemy of Induction'?", Psychological Science 19(6):585-592. The figures above are from Experiment 1a.

Cypher 1 - Writing the Picture Down

The language you use to ask Neo4j questions is Cypher. SQL works on tables; Cypher works on a picture made of nodes and edges.

So a query looks like the picture. Three symbols are the whole thing.

  ( )       node
  -[ ]->    edge
  { }       property

This post goes through the three, one at a time. Post 2 uses them to find long paths.

1. Node — ( )

One person, one shop: that is a node. Inside the brackets you can write two things.

  ( )            any node
  (:Person)      a node of type Person
  (f)            one node. I will call it f later
  (f:Person)     a node of type Person. I will call it f later

:Person is called a label, but just read it as the type. The f in front is the name tag. Add one only when you want to return it or use it again; otherwise leave it out.

2. Edge — -[ ]->

It joins two nodes. It has a direction.

  -[:KNOWS]->    follow a KNOWS edge forwards
  <-[:KNOWS]-    backwards
  -[:KNOWS]-     direction does not matter. Follow it either way
  -[r:KNOWS]->   an edge can have a name tag too

The direction-free form matters. You may have stored (student)-[:TRAINED_UNDER]->(teacher) in one direction only, but if you write - when searching, you can also walk from the teacher back to the student.

3. Property — { }

Both nodes and edges carry values.

  (p:Person {name: 'Mina'})      a Person whose name is 'Mina'
  -[:KNOWS {since: 2019}]->      a KNOWS edge whose since is 2019

4. Find it, return it — MATCH and RETURN

Say four people are joined like this.

Mina, Jun, Hana and Tae joined by KNOWS edges

Find Mina's friends.

MATCH (me:Person {name: 'Mina'})-[:KNOWS]->(f:Person)
RETURN f.name
f.name
"Jun"
"Tae"

Line by line.

  MATCH          find this shape.  SQL's SELECT ... WHERE slot
  RETURN         which of the things found to hand back
  f.name         the name property of the node tagged f

Writing the shape as a picture is the difference. The line above does what your eye does when it follows the arrows out of Mina.

5. Two steps

Join one more arrow.

MATCH (me:Person {name: 'Mina'})-[:KNOWS]->(:Person)-[:KNOWS]->(fof:Person)
RETURN fof.name
fof.name
"Hana"

The (:Person) in the middle has no name tag. It is only passed through and never returned, so it is left empty.

Tae is not in the result. No KNOWS edge leaves Tae, so the picture stops there.

6. Rename, sort, cut

MATCH (me:Person {name: 'Mina'})-[:KNOWS]->(f:Person)
RETURN f.name AS friend
ORDER BY friend
LIMIT 2
friend
"Jun"
"Tae"
  AS friend      rename the result column to friend
  ORDER BY       sort
  LIMIT          only this many from the top

ORDER BY, LIMIT and AS work as they do in SQL. Without ORDER BY the row order is not guaranteed. The results in the earlier sections could come back in another order too.

7. You can write several MATCH clauses

MATCH (me:Person {name: 'Mina'})-[:KNOWS]->(f:Person)
MATCH (f)-[:LIVES_IN]->(c:City)
RETURN f.name, c.name

A name tag stays alive to the end of the query. The f from the first line is used again on the second.

One thing to watch: adding a MATCH changes the row count. For each row so far, you get as many rows as there are matches for the next shape — a row with no match disappears, and a row with three matches becomes three.

That is because the second MATCH above is tied to the first through f. An untied shape behaves differently.

MATCH (f:Person)
MATCH (c:City)

Three people and four cities now give every pairing, 12 rows. When you chain many of them, cut down in the middle with WITH ... LIMIT or DISTINCT. Writing WITH f, c means only f and c survive after that point.

8. Values come from outside

MATCH (me:Person {id: $userId})-[:KNOWS]->(f:Person)
RETURN f.name

$userId is a value supplied when the query is called. Rather than baking the name into the query, you leave the slot open.

9. Lists, and the | symbol

Cypher hands back lists often, and there is a syntax for transforming one in a single step.

  [x IN list | expression]

It is Python's [expression for x in list] with the two halves swapped. Run it and you get this.

RETURN [n IN [1, 2, 3] | n * 10] AS tenfold
tenfold
[10, 20, 30]

n is each item taken from the list, and what follows | is what to turn it into.

| means two things

The same symbol does different work in different places. They are easy to confuse, so here they are side by side.

  [x IN list | expr]   inside a list:  "turn each one into this"
  -[:A|B]->            inside an edge: "A or B"

The second one says follow either a KNOWS or a WORKS_WITH, whichever.

MATCH (me:Person {name: 'Mina'})-[:KNOWS|WORKS_WITH]->(f:Person)
RETURN f.name

People reached by KNOWS and people reached by WORKS_WITH all come back.

And when you add *

You meet this shape in post 2. Split into pieces, none of it is new.

  [:A|B|C*1..3]

  [: ... ]        the edge slot
  A|B|C           A or B or C
  *1..3           one to three edges along the way

The number after the star counts edges, not nodes. Cross two edges and you step on three nodes.

  (X) --A--> (Y)                1 edge.   right next door
  (X) --A--> (Y) --C--> (Z)     2 edges.  one house further

So read that number as distance. *1..3 means "whatever sits at distance 1 to 3".

And the star covers all the types at once. You may mix the three as you go — the second line above, one A then one C, is caught at distance 2.

A line starting with // is a comment.

Next

Two steps means writing -[:KNOWS]-> twice. But what if you do not know how many steps? It might be one, it might be three.

That is where post 2 starts.

Cypher 2 - You Do Not Have to Know How Many Steps

In post 1 we chained -[:KNOWS]-> twice to find a friend of a friend. More often, though, you do not know how many steps it takes.

Here we write that kind of path in one line.

1. Say the data looks like this

People, restaurants and a city, joined by edges.

a graph running from me through Mina to restaurants in Lisbon

me likes Mina, and Mina collaborated with Olive Table. Jun trained under Mina and built the wine list at Cork and Candle.

We want restaurants in Lisbon connected to someone I like. It might be one step away, it might be three.

2. One query

MATCH (me:Person {id: $userId})-[:LIKES]->(s:Person)
MATCH path = (s)-[:TRAINED_UNDER|COLLAB_WITH|BUILT_WINE_LIST*1..3]-(p:Place)
      -[:IN]->(:City {name: 'Lisbon'})
RETURN p.name,
       [r IN relationships(path) | type(r)] AS why,
       length(path) AS hops
ORDER BY hops
LIMIT 3

Only four things are new since post 1.

  path =                name the whole path that was found
  [:A|B|C]              an A or a B or a C edge
  *1..3                 one to three edges along the way -- distance 1 to 3
  relationships(path)   the list of edges on the path

The rest came up in post 1: $userId, two MATCH clauses, a node with no name tag, [x IN list | ...], AS, ORDER BY, LIMIT.

3. Line by line

The first MATCH

  (me:Person {id: $userId})    the Person whose id is $userId, called me
  -[:LIKES]->(s:Person)        whoever me LIKES, called s

In the picture, s is Mina.

The second MATCH

This is the heart of the post.

  *1..3                  distance 1 to 3 will do. You need not know which
  the end is - not ->    direction is ignored
  [:A|B|C]               any of the three types
  (p:Place)              the destination is a restaurant, tagged p
  -[:IN]->(:City {...})  it has to be in Lisbon

Without *1..3 you would write one query for one step, another for two and another for three. And as post 1 showed, you may mix the three types — that is how path B below qualifies.

The - at the end also means you can walk backwards. The edge saying Jun trained under Mina points Jun → Mina, but you can start at Mina and go back up it to Jun.

The city is never returned, so (:City ...) has no name tag — the same slot you saw in post 1.

Two paths qualify.

  A   Mina --COLLAB_WITH--> Olive Table --IN--> Lisbon            2 edges
  B   Mina <--TRAINED_UNDER-- Jun
           --BUILT_WINE_LIST--> Cork and Candle --IN--> Lisbon    3 edges

RETURN

  p.name                   the restaurant name
  relationships(path)      the list of edges on the path
  [r IN list | type(r)]    take only the type name of each edge
  length(path)             how many edges the whole path has -- the distance

4. The result

p.name              why                                        hops
"Olive Table"       ["COLLAB_WITH", "IN"]                      2
"Cork and Candle"   ["TRAINED_UNDER", "BUILT_WINE_LIST", "IN"] 3

hops looks like it exceeds the range in *1..3, and it does. The star binds only the middle segment, while length(path) counts the closing -[:IN]-> as well. Path B is two in the middle plus the one IN.

why is the useful column. Hand back only a restaurant name and you cannot explain why you recommended it; with the edge types alongside, you can say "Olive Table collaborated with Mina, who you like."

5. In SQL

That single *1..3 becomes a one-step JOIN, a two-step JOIN and a three-step JOIN, combined with UNION — or you reach for WITH RECURSIVE. Add the three edge types and the ignored direction and it grows further.

A note

Raising the numbers in *1..3 gets slow. The number of walkable paths grows at every step. Better to write down a range you will actually use.

Multi-turn Agent Eval 1 - You Cannot Write the Answer Key in Advance

A single-turn evaluation is like an exam paper. You ask a question, get an answer, and compare it to the correct one.

  question    What is the capital of France?
  answer      Paris
  correct     Paris                → right

An agent does not work like this. It talks with a user who wants to change a flight over several messages. It asks for the booking number, checks the rules, asks the user to confirm the change, and then changes the flight. Measuring that is multi-turn evaluation.

Moonshot AI's Kimi K2 technical report (July 2025) also measured multi-turn ability separately, with three tests: τ2-Bench (June 2025), ACEBench (January 2025) and MultiChallenge (January 2025).

1. There are two kinds of multi-turn evaluation

The difference is who writes the user's next line.

  scripted conversation   The user's lines are written in advance. The next line is
                          the same even if the agent answers differently
                          Checks whether it reads and understands the earlier
                          conversation                 for example MultiChallenge
  LLM user                An LLM acts as the user, reads the agent's answer and
                          writes the next line
                          Checks whether it finishes the job by sending and
                          receiving messages           for example τ2-Bench

Both are multi-turn evaluation. In the first, the agent must remember the earlier conversation to pass. In the second, it must actually send and receive messages to finish the task.

2. You cannot write the user's next line in advance

Even from the same opening line, the conversation splits depending on the agent's answer.

  user      I'd like to move next week's flight one day later
  agent A   Could you give me your booking number?
  user      It's ABC123                               ← this kind of line follows

  agent B   Sure, I've moved it one day later
  user      Wait, which booking did you change?       ← this kind of line follows

The user's second line cannot be written before seeing the agent's first answer. So in a scripted conversation test, the user's lines are written in advance. Usually, the earlier AI answers are written in advance too. In an LLM user test, an LLM plays the user. With the first, every agent gets the same user lines, but those lines do not change based on the agent's answers. With the second, the conversation continues like a real conversation, but the LLM playing the user also makes mistakes and says something different every time.

3. What to grade is not fixed

There are many ways to do the same job. You can ask for the booking number first or the name first. So τ-bench (June 2024) does not treat the order of the conversation as the answer; it compares the database state after the conversation ends with the expected state. It also checks whether the agent gave the user all the required values.

Some conversations have no final state. Asking for advice or editing a piece of writing are examples. The MultiChallenge (January 2025) paper wrote "there is no single ground-truth answer for most test conversations". These conversations need a different way of grading. We look at it in post 3.

4. The same task goes differently each time

Since an LLM also plays the user, running the same task again gives a different conversation. So τ-bench measures the chance that all k runs of the same task succeed. It is called pass^k.

  pass@k   succeeds at least once in k runs   rises with more tries   common in code evaluation
  pass^k   succeeds in all k runs             falls with more tries   fits customer service

On τ-bench's retail domain, gpt-4o has a pass^1 of about 61% but a pass^8 of about 25%. With one run for each task, it succeeds on about six out of ten tasks. It succeeds on all eight runs for about one out of four tasks.

5. The LLM playing the user makes mistakes too

The τ2-Bench (June 2025) paper counted the user simulator's mistakes by reading the conversations. A critical error is a mistake that makes the task impossible to finish: asking for something against the user's goal, or leaving things in a state that cannot be changed back.

                                            conversations read   errors      critical errors
  airline (domain taken from τ-bench)       100                  47 (47%)    13 (13%)
  retail (domain taken from τ-bench)        50                   20 (40%)    6 (12%)
  telecom (domain new in τ2-Bench)          50                   8 (16%)     3 (6%)

For each percentage, divide the count in that column by the number of conversations read.

The score of an LLM user test always includes the simulator's mistakes. That is why what you tell the user LLM, and how, matters. Post 5 lists those prompts.

6. The judge LLM cannot follow the conversation either

Without a final state, an LLM has to read and grade the conversation. A long conversation can confuse this judge LLM too. The MultiChallenge paper wrote that when the model judged the whole conversation, it agreed with humans 37% of the time. When a human wrote one yes / no question for each problem, it agreed 94% of the time.

So what do you need to decide?

  who writes the user's next line   a pre-written record · an LLM playing the user · a human
  how many times the agent answers  once at the end · every turn
  what you grade                    the last answer · the final state · results of many runs

In post 6 I suggest how to choose these three things when measuring your own agent.

Sources

  • The month next to a paper's name is the month it first appeared on arXiv.
  • Kimi Team 2025 · Kimi K2: Open Agentic Intelligence. arXiv:2507.20534.
  • Yao and others 2024 · τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains. arXiv:2406.12045. Final state comparison, pass^k, gpt-4o's 61% · 25%.
  • Barres and others 2025 · τ2-Bench: Evaluating Conversational Agents in a Dual-Control Environment. arXiv:2506.07982. Simulator error counts (Table 2). For the telecom domain's critical errors, the main text says 6%, but the note under the table says "no critical errors were reported". I followed the main text.
  • Sirdeshmukh and others 2025 · MultiChallenge. arXiv:2501.17399. How often the model and humans gave the same grade: 37.33% · 93.95% (Table 4).
  • The flight conversation in section 2 is a made-up example for explanation.

Multi-turn Agent Eval 2 - From Scripted Conversations to LLM Users

In post 1 we split multi-turn evaluation in two: whether the user's next line is written in advance, or written by an LLM after reading the agent's answer. Here are thirteen methods published since 2023, grouped into those two types and listed by date.

A timeline of thirteen multi-turn evaluation methods. The top row is scripted conversations (MT-Bench, MT-Bench-101, MultiChallenge), the bottom row is LLM users (MINT through UserBench)

Only three methods use scripted conversations. From 2024 on, most methods use an LLM user. As using an LLM to play the user became common, the field moved toward measuring how well an agent actually sends and receives messages.

1. One line each

  Posted    Name            User lines   Who writes the next turn         What is graded
  2023-06   MT-Bench        scripted     a scripted 2nd-turn question     GPT-4 scores 1-10 ·
                                                                          compares two answers
  2023-09   MINT            LLM          a user GPT-4 plays, giving       success within the allowed
                                         feedback                         number of turns
  2023-10   SOTOPIA         LLM          role-play partner (agent ·       7 things, graded by
                                         human)                           humans and GPT-4
  2024-02   MT-Bench-101    scripted     a history filled with correct    GPT-4 grades each turn; uses the lowest score
                                         answers written in advance
  2024-06   τ-bench         LLM          LLM user                         final state · pass^k
  2024-08   ToolSandbox     LLM          LLM user                         steps along the way and
                                                                          final state
  2025-01   ACEBench        both         gpt-4o user                      final state + how tools
                                                                          were called
  2025-01   MultiChallenge  scripted     a scripted history               a yes / no question for
                                                                          each problem
  2025-01   IntellAgent     LLM          a user agent built from policy   whether policy was followed
  2025-03   ColBench        LLM          LLM partner                      unit test · how closely the
                                                                          pages match
  2025-05   Lost in Conv.   LLM          a user giving one piece at a     compared with the same task's
                                         time                             single-turn score
  2025-06   τ2-Bench        LLM          LLM user (uses tools too)        5 kinds including final state ·
                                                                          pass^k
  2025-07   UserBench       LLM          a user who shows what they want  whether the answer matches
                                         without saying it directly       everything the user wanted

ACEBench differs by group. The fixed tasks (Normal) use scripted conversations. Only the Agent tasks use an LLM user. The timeline uses the Agent tasks to place ACEBench.

2. Scripted conversations differ in how many times the agent answers

  MT-Bench        Answers both turn 1 and turn 2. The turn 2 question is the same no
                  matter what the turn 1 answer was
  MT-Bench-101    Answers every turn, but earlier turns are filled with correct
                  answers written in advance (golden context)
  MultiChallenge  Earlier turns were written by another model and edited by humans.
                  Answers only the last turn

MT-Bench-101 explained why. If a model makes a mistake early, the rest of the conversation becomes awkward, and the comparison is then no longer fair. But this way it cannot test whether a model can fix its own mistakes and continue the conversation. Post 3 looks at MultiChallenge in detail.

3. LLM users differ in how they play the user

Checking whether the agent finishes the task. τ-bench, ToolSandbox, ACEBench and τ2-Bench have the agent change bookings and fix settings with tools, and look at the state after the conversation ends. ToolSandbox looks not only at the end but also at steps the agent must complete (milestone) and actions it must avoid (minefield). Post 4 looks at τ2-Bench in detail.

IntellAgent looks at policy instead of the final state. It automatically creates test situations from a company's policy document. After the conversation, a judge LLM reads it and writes down which policies were tested and which were broken. It can be used in domains with no public benchmark.

Checking whether it finds things out through conversation. The user does not say everything from the start.

  MINT            When the answer is wrong, GPT-4 gives only a hint, like a teacher
  Lost in Conv.   Splits the task into pieces and gives one in each turn
  UserBench       Starts with a goal that is not clear and shows what they want without
                  saying it directly

Lost in Conversation uses the clearest method. It compares giving the same task all at once with giving it in pieces over several turns. This directly shows how much the score drops because of the extra turns. Recent models dropped 39% on average. In the paper's words, "when LLMs take a wrong turn in a conversation, they get lost and do not recover".

UserBench wrote that on average only 20% of answers matched everything the user wanted. Even the best model found out less than 30% of the user's preferences (what the user likes or wants).

Building things or talking with others. In ColBench the agent sends messages to and receives messages from a partner played by an LLM. Together they build backend code (graded with unit tests) and web pages (graded by how closely their images match the reference page). SOTOPIA runs role-plays with social goals, and humans and GPT-4 grade 7 things, including whether the goal was reached.

4. The three Kimi K2 picked

Kimi K2 (July 2025) measured multi-turn ability with these three.

  τ2-Bench        2025-06   LLM user                does it finish the job with tools     66.1
  ACEBench        2025-01   both                    does it call tools correctly          76.5
  MultiChallenge  2025-01   scripted conversation   does it remember the details of a     54.1
                                                    long conversation

Two methods use LLM users, and one uses scripted conversations. But ACEBench's 76.5 is "overall on ACEBench English". It combines all three groups, not just the Agent tasks, so it does not measure only multi-turn tasks.

Sources

  • Dates are the month a paper first appeared on arXiv. The descriptions come from each paper's summary and main text. The numbers come from the main text.
  • Zheng and others 2023 · Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena. arXiv:2306.05685.
  • Wang and others 2023 · MINT. arXiv:2309.10691.
  • Zhou and others 2023 · SOTOPIA. arXiv:2310.11667.
  • Bai and others 2024 · MT-Bench-101. arXiv:2402.14762.
  • Yao and others 2024 · τ-bench. arXiv:2406.12045.
  • Lu and others 2024 · ToolSandbox. arXiv:2408.04682.
  • Chen and others 2025 · ACEBench. arXiv:2501.12851.
  • Sirdeshmukh and others 2025 · MultiChallenge. arXiv:2501.17399.
  • Levi · Kadar 2025 · IntellAgent. arXiv:2501.11067. Section 3.3, Dialog Critique, explains policy judging.
  • Zhou and others 2025 · SWEET-RL (ColBench). arXiv:2503.15478.
  • Laban and others 2025 · LLMs Get Lost In Multi-Turn Conversation. arXiv:2505.06120.
  • Barres and others 2025 · τ2-Bench. arXiv:2506.07982.
  • Qian and others 2025 · UserBench. arXiv:2507.22034.
  • Kimi Team 2025 · Kimi K2. arXiv:2507.20534. Scores are from Table 3. The evaluation section says the ACEBench score covers all three groups.

Multi-turn Agent Eval 3 - MultiChallenge Fixes the Conversation and Grades One Answer

This paper was made to automatically grade how well a model talks with a person over many turns. It uses problems that even the latest models get wrong.

Scale AI released it in January 2025. The paper says that the latest models score almost perfectly on existing multi-turn benchmarks. So it collected only conversations those models actually fail, and all scores were below 50%.

1. It asks about four things

  Category                    Items   What it checks
  Instruction retention       69      Does it follow the instruction from the first turn until the end
  Inference memory            113     Does it use details the user mentioned earlier, without being reminded
  Reliable versioned editing  41      After many edits, does it keep editing the right version
  Self-coherence              50      Does it drop an earlier correct answer when the user doubts it

The last row checks whether the model agrees with the user just to please them (sycophancy). When the user asks the same thing again or sounds a little unsure, the model drops its earlier correct answer and agrees with the user. The paper says this makes conversations awkward and lowers trust.

2. One problem looks like this

Each line of the released file benchmark_questions.jsonl is one problem. Here is one Inference memory problem.

  AXIS            INFERENCE_MEMORY
  CONVERSATION
    user        "... I prefer venues that are within a 5-minute walk from the
                 UN headquarters."
    assistant   "... Here are a few suggestions that are within a 5-minute walk:
                 ..."
    user        "I am meeting a German diplomat on Friday. I am looking for a
                 suitable place to have lunch with him, preferably an up-class
                 restaurant. ..."
  TARGET_QUESTION "Are the restaurants chosen within a 5-minute walk from the
                   UN headquarters?"
  PASS_CRITERIA   "YES"

The conversation ends on a user turn. The model writes a single answer to that last turn. The last turn does not repeat the "5-minute walk". The model has to remember and use the information from the first turn without being reminded.

  CONVERSATION      the user and assistant take turns. 9.1 turns on average (3-19)
  TARGET_QUESTION   a yes / no question you can answer by reading only the model's answer. Written by people
  PASS_CRITERIA     the answer needed to pass. "YES" for all 273

It reads many turns and writes one. This is the "scripted conversation" from post 1. Looking at the last turn alone, any fancy restaurant could be a correct answer. The answer is only right if it uses the first turn, and that is what makes it a multi-turn test. So this test cannot show whether a model can fix its own earlier mistake. But every model starts from the same history, so we can compare them under the same conditions.

3. The problems were made like this

How MultiChallenge problems are made. Three LLM agents talk until the answering model makes a mistake, then people edit and review twice

This figure shows how the test problems are made. You do not run it when measuring your agent; you only use the files it produced. The figure in section 4 shows how grading works.

Three LLM agents create the conversation. The paper calls this setup MMSE.

  Planner      takes a topic, a description of a person and a category definition, and
               writes a plan (blueprint) for the conversation. Changes the plan as the
               conversation continues and checks whether the answering model made a mistake
  User agent   turns the plan into real user lines. Tries to make the answering model make a mistake
  Responder    the answering side. One of the 6 latest models, picked at random for each problem

If the Planner finds a failure it stops and saves; if it finds none within the turn limit, the conversation is dropped. People edit each saved conversation. They check that it fits the category, that it reads naturally, and that at least 3 of the 6 latest models fail it. Then people who did not make the first edits review it in two more stages.

Because an LLM wrote the first version, people had less work to do. Writing a whole new problem took 154.4 minutes; editing one took 73.6 minutes. The text before and after editing was 74.5% alike on average, measured by Levenshtein distance (a way to count text changes), and the authors took the remaining 25.5% as the part people edited.

4. Grading uses one question

MultiChallenge grading. Only the model's answer and a yes/no question go to the judge model; the conversation history does not

The judge model does not see the conversation. It gets only the model's answer and a yes / no question. Here is the full judge prompt, exactly as written in the authors' code.

  You are tasked with evaluating a model response to see if it meets a specific criteria.
  The criteria will always be YES/NO evaluation.
  The model response is as follows:
  <MODEL_RESPONSE>
  {}
  </MODEL_RESPONSE>
  The criteria that the model response must meet is as follows. Be VERY STRICT!:
  <CRITERIA>
  {}
  </CRITERIA>
  Print your reasoning followed by your verdict, either "YES" or "NO".

The model's answer goes in the first {} position, and TARGET_QUESTION goes in the second (I removed the blank lines). gpt-4o-2024-08-06 judges at temperature 0, and the answer passes if the judge's result matches PASS_CRITERIA.

Why not show the conversation? Given the whole conversation and the rules for passing or failing in that category, the judge agreed with people 37.33% of the time. Given one question, it agreed 93.95% of the time. The paper explains it this way. The judge models themselves cannot score above 50% on this test, so it is hard to trust them to read the conversation and judge someone else's answer correctly. With only one question, the judge only has to check simple things, such as is there a nut in the answer, is the restaurant 5 minutes away.

How often each judging method agrees with people. 31-44% when given the conversation, 92-95% when given a single yes/no question

The overall score is a simple average of the four category scores. The category with 41 problems and the category with 113 problems count equally.

5. There is code

ekwinox117/multi-challenge, linked directly from the paper, has the data for all 273 problems, the grading code, and answers from the 12 models tested in the paper. Here is how to use it.

  If you already have answers   python main.py --responses-file my_responses.jsonl --output-file results.txt
  To ask a model directly       python main.py --model-provider openai --provider-args model=gpt-4o temp=0 ...

Judging needs an OpenAI API key. If you run several times, as with --attempts 3, it counts as a pass if any one attempt passes. This is pass@k, the opposite of pass^k in post 1.

With the code at commit 5ccefcc, grading probably will not start. src/evaluator.py passes max_tokens=4096, but the constructor in src/models/openai.py does not accept that argument. This is what I think after reading the code; I did not run it.

6. What the paper found

These are the results graded directly by people (Table 2). Each is the average of the four categories.

MultiChallenge human-graded averages. Claude 3.5 Sonnet 41.4, o1-preview 37.2, Gemini 1.5 Pro 20.0, Llama 3.1 405B 14.9, Mistral Large 14.6, GPT-4o 12.5

Here is what the paper found.

  1  All of the latest models are under 50%. First place is 41.4%
  2  Each model is best at a different category. Claude is highest on retention (58.6),
     o1-preview on memory (41.5) and editing (39.0)
  3  Scores show no clear pattern as the number of turns grows. The authors think the hard
     part may be reasoning that uses earlier turns, rather than the conversation's length
  4  Judging with a single question agrees with people 93.95% of the time. Automatic
     grading can be trusted

The paper also lists its own limits. First, the test is harder for the 6 models used to select the problems. Only problems those models failed were kept. Even so, the models that are publicly available and were tested later all scored below Claude 3.5 Sonnet and o1-preview. Second, problems that were hard to judge even with a yes / no question were left out. The authors wrote that they will release them when they can grade them.

Later models scored higher. As we saw in post 2, Kimi K2 (July 2025) scores 54.1.

7. To evaluate your agent

  For each of the 273 problems
    1  give CONVERSATION to the agent as the conversation history. The last turn is a user turn
    2  your agent writes one answer
    3  collect {"QUESTION_ID": ..., "RESPONSE": ["answer"]}, one per line
  grade with python main.py --responses-file my_responses.jsonl --output-file results.txt

Things to decide before giving the history to the agent.

  • How to give the agent the conversation history. This test gives the earlier turns as the history of the current conversation. It does not test whether the agent can remember a past session. Even if your agent has a long-term memory system, putting the history directly into the context matches what the test is meant to measure.
  • The earlier assistant answers are not yours. They were written by another model (one of the 6 latest models). Leave them as they are, even if they do not sound like your agent.
  • Run it once. If you increase --attempts, the task passes when any one attempt passes, so the score rises. To compare with the paper's numbers, keep it at 1.

Post 6 suggests how to build a test like this from your own data.

Sources

  • Sirdeshmukh and others 2025 (Scale AI) · MultiChallenge: A Realistic Multi-Turn Conversation Evaluation Benchmark Challenging to Frontier LLMs. arXiv:2501.17399 (January 2025).
  • The table and the text differ in one place. The text of section 5.1 gives Claude 3.5 Sonnet 38.3%, o1-preview 34.6 and Gemini 19.1, but Table 2 right above it and the paper's summary give 41.42 · 37.23 · 19.96. v1 (January 2025) and v2 (March 2025) are the same. The chart follows the table.
  • The data and grading in sections 2 · 4 · 5 · 7 were checked in the authors' repository. They are data/benchmark_questions.jsonl, src/evaluator.py, src/result_parser.py and main.py in ekwinox117/multi-challenge, as of commit 5ccefcc from February 5, 2025.
  • Kimi K2 describes it differently. The K2 report introduces this test in one line as "multi-turn dialogues with conflicting instructions", but the original paper's instruction retention actually says "human users don't provide followup instructions that contradict the first-turn instructions".
  • The license is the arXiv default, so the paper's figures are not included. The figures in sections 3 · 4 are drawn by scripts/gen_multichallenge_graphs.py, and the charts in sections 4 · 6 by scripts/gen_multiturn_charts.py from the numbers in Table 4 and Table 2.

Multi-turn Agent Eval 4 - τ2-Bench Gives the User Tools Too

This paper was made to measure agents that guide users and solve problems with them.

Sierra released it in June 2025. The paper says that existing benchmarks are "single-control". Only the agent uses tools; the user just gives information. But in real situations like tech support, the problem is solved only when the user does something themselves. Things like "try turning off airplane mode".

1. Structure — the agent and the user change the same world

The structure of τ2-Bench. The agent and the user LLM send messages to each other, and each changes the same world (the company DB and the phone) with its own tools
  agent         gets the company policy document, talks with the user, calls agent tools
  user          an LLM plays the customer. The task instructions are hidden from the agent
                looks at and changes its own phone with user tools
  same world    the company DB and the user's phone. This state is checked when the
                conversation ends

Because the user uses tools too, there are things the agent cannot fix directly. It has to tell the user to do them.

  agent    What do you see in the status bar?
  user     (tool that checks the phone status) There's an airplane mode icon
  agent    Please turn off airplane mode
  user     (tool that turns off airplane mode)

There are three domains. Retail and airline came from τ-bench (June 2024), with some changes; telecom is new.

                 retail             airline            telecom
  agent tools    write 7 · read 6   write 6 · read 6   write 6 · read 7
  user tools     none               none               write 15 · read 15
  tasks          115                50                 114 (2,285 in total)

2. One task looks like this

The first task in the repository's data/tau2/domains/airline/tasks.json.

  purpose              checks whether the agent refuses to cancel when the user cannot
                       get a refund, even when the user keeps asking
  user_scenario
    reason_for_call    "You want to cancel reservation EHGLP3. ..."
    known_info         "You are Emma Kim. Your user id is emma_kim_9957."
    task_instructions  "If Agent tells you that cancellation is not possible,
                        mention that you were told that you didn't need to get
                        insurance ... You don't want to cancel if you don't get a
                        refund."
  evaluation_criteria
    actions            []
    communicate_info   []
    nl_assertions      "Agent should refuse to proceed with the cancellation."
    reward_basis       DB, COMMUNICATE

Only the user LLM sees user_scenario. It holds what the user knows (known_info), why they called, and what to do depending on what the agent says. evaluation_criteria is used only for grading. nl_assertions is not in reward_basis, so it does not affect the score. The score only checks that the DB was not changed. The information to communicate is also empty, so grading does not check whether the agent clearly refused the cancellation.

3. Grading — choose from five checks after the conversation ends

  DB check            is the final DB the same as the expected DB      same as τ-bench
  communicate info    did it give the user all required values         same as τ-bench
  status assertion    is a condition true in the final world
                      (for example, is the service connected)
  NL assertion        does the conversation meet a condition
                      (for example, did it find the cause)
  action matching     are the required calls present in the conversation

Each task uses some of these. The airline task above checks the DB and the information given to the user; the telecom domain uses only the status check. And each task is run four times to get pass^k. As we saw in post 1, that is the chance that all k runs of the same task succeed. The user simulator is gpt-4.1, at temperature 0.

The telecom tasks were not written one by one by people. A program combines small problems defined by functions that set them up, solve them and check the results. This keeps the expected answers correct and lets the authors change the difficulty in steps. Each task also gets a user type (none · experienced · inexperienced).

4. What the paper found

When all k runs have to succeed, the score drops. This is gpt-4.1's pass^k.

gpt-4.1's τ2-Bench pass^k. From k=1 to 4, retail drops from 0.74 to 0.53, airline from 0.56 to 0.40, and telecom from 0.34 to 0.19

Telecom is the lowest. It is the domain where the agent has to tell the user what to do.

Guiding the user is hard. The telecom domain was run three ways.

  default       the agent and the user split the tools and solve it together
  no user       no user; the agent gets a problem summary, can use every tool and solves the task alone
  oracle plan   it is also told the solution steps (who calls which tool)
τ2-Bench telecom pass^1. gpt-4.1 scores 0.34 by default, 0.52 with no user, 0.73 when given the solution steps (oracle plan). o4-mini scores 0.42, 0.67, 0.96

Alone it scores 0.52; together with the user, 0.34. gpt-4.1 dropped by 0.18 and o4-mini by 0.25. Knowing how to solve a problem and explaining the steps so the user can follow them are different abilities. The paper says that talking and working with the user limits success more than reasoning does.

The user simulator was also made to make fewer mistakes. With tools for the actions the user can take, its error rate in the telecom domain was 16% (6% critical errors), lower than the 40% for retail and 47% for airline taken from τ-bench.

The paper lists three limits. User tools are not yet used in retail and airline. Experts are still needed to build a new domain. And the test does not separately model the difference between experts and beginners: understanding what an inexperienced user knows and explaining things in a way they can follow.

5. The code and your agent

sierra-research/tau2-bench, linked from the paper, has the domains, tasks, user simulator and grading.

  tau2 run --domain airline --agent-llm gpt-4.1 --user-llm gpt-4.1 \
    --num-trials 1 --num-tasks 5

To use your own agent, subclass HalfDuplexAgent. The constructor takes tools and domain_policy (the company policy document), and you implement two methods.

  get_init_state(message_history) -> state
    builds the agent's state when the conversation starts
  generate_next_message(message, state) -> (AssistantMessage, state)
    message is either a user line or a tool result. Returns the next line or tool call

Then register a factory like create_agent(tools, domain_policy, **kwargs). Run your agent with tau2 run --agent my_agent. The repository runs the tools and the user simulator and grades the results.

Kimi K2 (July 2025) used this test. It scored 70.6 on retail, 56.5 on airline and 65.8 on telecom; in the same table Claude Opus 4 scored 81.8 · 60.0 · 57.0.

Sources

  • Barres and others 2025 · Victor Barres, Honghua Dong, Soham Ray, Xujie Si, Karthik Narasimhan, τ2-Bench: Evaluating Conversational Agents in a Dual-Control Environment. arXiv:2506.07982 (June 2025). CC BY 4.0. The domain table is Table 1, grading is section 3.3, pass^k is Figure 3, the three ways are shown on the left side of Figure 4 (original policy document), and the simulator errors are section 4.3 and Table 2.
  • The charts and figures were redrawn. The numbers were copied from the tables and figures above and are drawn by scripts/gen_multiturn_charts.py.
  • Sections 2 and 5 were checked in the repository. As of commit 5ade54e: data/tau2/domains/airline/tasks.json, README.md and src/tau2/agent/README.md. This commit also includes voice and a new domain (banking_knowledge) added after the paper.
  • Kimi Team 2025 · Kimi K2. arXiv:2507.20534. The Tau2 rows of Table 3.

Multi-turn Agent Eval 5 - An LLM User Runs on a User Prompt

When an LLM reads the agent's answer and writes the next line, that LLM needs a prompt that makes it play the user. Change this prompt and the same agent gets a different score. So the prompt is part of the test. The originals stay in English, and only parts are quoted.

1. Rules they share

  Don't say everything at once              give only what is needed now
  Don't make up what isn't in the           if you don't know, say so
  instruction
  Keep acting as the user                   do not act like the agent
  When you reach the goal, end with the     ###STOP###, finish conversation, etc.
  set signal

Almost every prompt has these rules. The rest differs from test to test.

2. MINT (September 2023) — feedback only, like a teacher

Here no user talks with the model. Instead, when the model gets it wrong, GPT-4 gives advice. In the default setting GPT-4 is not given the answer either. It uses "NOT GIVEN" for {gt_solution}. In another version of the experiment, GPT-4 does get the answer. That version keeps the line below telling GPT-4 not to give the answer.

  You are an expert tasked with evaluating and providing feedback on an
  assistant's performance.
  ...
  Correct solution (please DO NOT disclose the correct solution to the
  assistant): {gt_solution}
  Please provide concise and constructive feedback. Remember, your role is
  similar to a teacher. Rather than giving away the solution or details
  about the answer, guide the assistant toward understanding how to
  arrive at the correct answer.

3. τ-bench (June 2024) — the basic form

This is the default prompt in the repository code (tau_bench/envs/user.py). It puts in the task instruction and adds rules.

  You are a user interacting with an agent.
  Instruction: {task instruction}
  Rules:
  - Just generate one line at a time to simulate the user's message.
  - Do not give away all the instruction at once. Only provide the information
    that is necessary for the current step.
  - Do not hallucinate information that is not provided in the instruction. ...
    just say you do not remember or have it.
  - If the instruction goal is satisified, generate '###STOP###' as a
    standalone message without anything else to end the conversation.
  - Do not repeat the exact instruction in the conversation. ...
  - Try to make the conversation as natural as possible, and stick to the
    personalities in the instruction.

The same file also has a version that writes a thought (Thought) first and then speaks. The prompt says the thought does not go to the agent. But the code that splits the response (parse_response) sends everything after Thought: to the agent. Unless the code is changed, the thought goes to the agent too.

4. ToolSandbox (August 2024) — what to add so it makes fewer mistakes

This paper from Apple tested the user prompt itself. It split the prompt into these parts.

  User Goal            what the user wants
  Knowledge Boundary   what the user knows and does not know
                       for example "You do not have any more information."
  Demonstration        example dialogue for the user role. Seen only by the user LLM
ToolSandbox user simulator errors. Goal only: making up information 12.4% · breaking instructions 6.2%; adding the knowledge boundary: 7.75% · 3.88%; adding the demonstration as well: 6.97% · 0.77%

With the knowledge boundary written down, the user LLM makes up less information. With a demonstration, it almost never forgets to act as the user. The prompt in the code starts like this.

  You are no longer an assistant. From now on role play as a user (User A)
  talking to another user (User B).
  ...
  0. DO NOT act as if you (User A) are an assistant. ALWAYS treat yourself as
     a user (User A).

There is a reason the agent is called "User B". The authors wrote that the simulator got confused when asked to act as the user instead of the assistant. Calling the other side a user too helped it follow instructions better.

5. ACEBench (January 2025) — one question at a time

  As a user, your role is to interact with an agent. ...
  1 Break down your inquiries and only raise one question per exchange to
    simulate a real user's messages.
  ...
  4 ... You cannot offer proactive help to the agent; respond to the agent's
    questions according to the instructions, and do not invent any
    information that you do not know.
  5 Once all tasks are complete, generate a 'finish conversation' message as
    a standalone line to end the discussion.

6. τ2-Bench (June 2025) — the user uses tools too

This is the template from Appendix C.2. The user uses tools, so there are more rules.

  You are playing the role of a customer contacting a customer service
  representative agent.
  ...
  - At each turn you can either:
  - Send a message to the agent.
  - Make a tool call to perform an action requested by the agent.
  - You cannot do both at the same time.
  ...
  - Never make up the results of tool calls that the agent has requested, ...
  - Avoid repeating the exact instructions verbatim. ...
  - Disclose information progressively. Wait for the agent to ask for specific
    information before providing it.
  - Only call a tool if the agent has requested it. Ask clarifying questions if you
    do not know what tools to call.
  ...
  - '###STOP###'          when the goal is reached
  - '###TRANSFER###'      when the conversation is passed to another support agent
  - '###OUT-OF-SCOPE###'  when the instructions do not cover the situation and
                          the conversation cannot continue

Note that there are three end signals. A conversation that stopped because the instructions were not enough gets a label, so it is easy to choose which conversations to read again. You still have to read the conversation to know whose fault it was. In the paper, two people also read each conversation and counted the errors.

7. UserBench (July 2025) — showing preferences without saying them directly

When the agent asks what the user prefers, the prompt says not to say it directly.

  You are a helpful user in a travel planning conversation who needs to
  respond to an agent's explicit request for your preference, which you
  should elicit in an implicit and indirect manner.
  ...
  • Don't directly state "My preference is..." – be more subtle,
    conversational, and indirect.

The answer comes back as JSON with two fields: thought (how to show the preference without saying it directly) and response (what to actually say).

8. What to remember when using an LLM user

  Do not change the user prompt and user model   keep them the same for every
                                                 agent you compare
  Write down the knowledge boundary              less made-up information
                                                 (ToolSandbox)
  Use separate end signals                       success · passed to another agent ·
                                                 not enough information in the
                                                 instructions (τ2-Bench)
  Count simulator errors separately              read a few conversations and write
                                                 the error count next to the raw
                                                 score

In the ToolSandbox experiment, simulator errors stayed around 8% even when the agent changed. So the authors thought these errors had little effect when comparing agents. Still, simulator errors can change the score itself.

Sources

  • The month is when it first appeared on arXiv. Prompts are quoted in part from the English originals, and cuts are marked with ....
  • Wang and others 2023 · MINT. arXiv:2309.10691. Appendix F.4.2.
  • Yao and others 2024 · τ-bench. arXiv:2406.12045. The prompt is in tau_bench/envs/user.py of sierra-research/tau-bench, which the paper links to. The paper itself has only an example task instruction.
  • Lu and others 2024 · ToolSandbox. arXiv:2408.04682. CC BY-SA 4.0. Error rates are from Table 2 (GPT-4o user · GPT-4o agent, 1,032 conversations) and Table 3; the prompt is from tool_sandbox/scenarios/user_simulator_few_shot_examples.py in apple/ToolSandbox, which the paper links to.
  • Chen and others 2025 · ACEBench. arXiv:2501.12851. Appendix Figure 29.
  • Barres and others 2025 · τ2-Bench. arXiv:2506.07982. Appendix C.2. The explanations next to the three end signals are shortened from the original sentences.
  • Qian and others 2025 · UserBench. arXiv:2507.22034. Appendix Figure 9.
  • The chart in section 4 is drawn by scripts/gen_multiturn_charts.py from the numbers in Table 2.

Multi-turn Agent Eval 6 - Measure Your Agent Twice: Scripted, Then With an LLM User

A scripted conversation shows whether the agent remembers what was said earlier, and an LLM user shows whether it finishes the task.

Here is a proposal that combines methods from the earlier papers — τ-bench (June 2024), ToolSandbox (August 2024), MultiChallenge (January 2025), τ2-Bench (June 2025). None of the papers recommends this exact order. The name next to each step is the paper the method comes from.

1. Scripted conversation — does it remember what was said earlier?

Scripted conversation evaluation. A fixed conversation history goes in, the agent writes one answer, and a judge LLM grades it seeing only the answer and a yes/no question
  1  Build the problem   in a real conversation from your service, find a user
                         turn where earlier information or instructions are
                         needed. End the conversation history at that turn
  2  Add a question      one question that can be judged yes / no from the
                         answer alone                                       MultiChallenge
  3  Get the answer      clear the agent's memory, give it the conversation
                         history, get one answer
  4  Judge               give the judge LLM only the answer and the
                         question. Not the conversation                     MultiChallenge
  5  Count               pass rate for each category. Run once

For step 1, use MultiChallenge's four categories as a checklist.

  Does it follow the first turn's instruction until the end   "From now on, answer in three lines"
  Does it use information the user mentioned only briefly     "I would like it to be within a 5-minute walk"
  Does it edit the right version of a text that has been changed many times
  Does it keep its correct answer even when the user doubts it

Step 2 matters most. Ask a question like "does the answer have nuts?" rather than "is this a good answer?" In MultiChallenge, the judge agreed with people 37% of the time when given the whole conversation. With just one question, it agreed 94% of the time.

Check the judge LLM once before trusting it. Have a person grade about 50 problems. Then check how often the judge LLM gives the same grade. MultiChallenge also checked its grades against people's grades before using automatic grading.

You can also run a public test first. MultiChallenge's 273 problems and grading code are public. Post 3 explains how to add your agent.

2. LLM user — does it finish the task?

LLM user evaluation. A user LLM given a task talks with the agent, and the agent calls tools in a sandbox. At the end the final state is checked, and repeating k times gives pass^k
  1  Write the task         user instruction + what the final state
                            must be                                         τ2-Bench format
  2  Build a sandbox        make the agent's tools change a fake DB
                            instead of the real one                         τ-bench
  3  Set up the user LLM    the rules from post 5 + knowledge boundary
                            + demonstration                                 ToolSandbox
  4  Run the conversation   until the user sends an end signal or the
                            conversation reaches the turn limit
  5  Grade                  does the final state match the answer? Use
                            yes / no questions only to check things the
                            state cannot show                               τ2-Bench
  6  Run k times            report pass^1 and pass^k together               τ-bench
  7  Count simulator        read a few failed conversations and mark
     errors                 failures that were the user's fault             τ2-Bench

For step 1, use τ2-Bench's task format without changing it.

  user_scenario         seen only by the user LLM
    reason_for_call       why the user contacted support
    known_info            what the user knows (name, reservation number)
    task_instructions     if the agent does this, do that
  evaluation_criteria   used only for grading
    required final state     the DB must change like this
    information to tell      this value must be told to the user
    the user

In step 6, setting k to about 4 is enough. τ2-Bench also ran each task four times. Looking only at pass^1 does not show whether a success happened just by luck. For an agent that deals with customers, pass^4 is closer to reality.

Run one more comparison. As τ2-Bench does, let the agent solve the task without a user, with all the tools available, and compare the scores. If it cannot solve the task even alone, check reasoning and tool use first. If it solves it alone but fails with the user, check how it explains things and guides the user first. Read the failed conversations to check the cause.

You can also run a public test first. If you add your agent as a HalfDuplexAgent, the τ2-Bench repository runs the user simulator and the grading for you. Post 4 explains how.

3. What to report with the results

For the same agent, the score changes when any of these change.

  agent         model, system prompt, tools turned on, whether a memory system is on
  user side     user model and user prompt (for a scripted conversation, where
                the conversation history came from)
  judge side    judge model, judge prompt, how often the judge agrees with people
  how it ran    k, temperature, number of failures that look like the simulator's
                fault (separate from the raw score)

4. Which one first

  An assistant that learns what the user        scripted conversation first.
  needs through conversation                    You can see what information it misses
  An agent that uses tools to finish tasks      LLM user first. You can grade it
                                                directly from the final state

Either way, don't guess multi-turn ability from a single-turn score. MINT (September 2023) wrote that a model can do well in one turn but poorly over multiple turns. Lost in Conversation (May 2025) wrote that when the same task was split across multiple turns, recent models' scores fell by 39% on average.

Sources

  • This post is a proposal. The paper behind each step is named next to the step, and the numbers were checked against the originals in the earlier posts.
  • MultiChallenge · arXiv:2501.17399. Four categories, yes / no question, 37% · 94%.
  • τ-bench · arXiv:2406.12045. Fake DB and final state, pass^k.
  • ToolSandbox · arXiv:2408.04682. Knowledge boundary and demonstration.
  • τ2-Bench · arXiv:2506.07982. Task format (the repository's tasks.json), four runs, solving without a user, counting simulator errors.
  • MINT · arXiv:2309.10691.
  • Lost in Conversation · arXiv:2505.06120.
  • The two figures are drawn by scripts/gen_multiturn_charts.py.