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

Sign in to watch this lesson
Algorithms - Recursion, Backtracking and Combinatorics · 4:22
Three ways to list every subset: counting bitmasks from 0 to 2^n - 1 like an odometer, the take-or-leave recursion, and the Gray code i ^ (i >> 1), where one item changes per step so a running total updates in constant time (prices 2, 5 and 7 hit a target of 7 twice; on 24 items the Gray walk was dozens of times faster than recomputing every sum). Then std::next_permutation in three moves (pivot, swap, reverse the tail), why aabc gives 12 arrangements and not 24, why you must sort first, and a measured table of how far listing goes.