Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 47s1 days 16 hours 1 minutes 47 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 47s1 days 16 hours 1 minutes 47 seconds.

Sign in to watch this lesson
Algorithms - Recursion, Backtracking and Combinatorics · 4:13
An order book that receives n buys and n fills and may never go negative is a lattice path that never rises above the diagonal. For n = 3, 5 of the 20 paths survive, and the reflection trick explains why: flipping a bad path after its first step above the diagonal pairs it with one of the 15 paths to (2, 4), so C_n = C(2n, n) - C(2n, n-1) = C(2n, n)/(n+1). The survivors become balanced brackets and full binary trees, the (A)B split gives the recurrence, and we finish with the traps (int overflow, 64-bit limits, dividing under a modulus) and the ballot problem.