Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Binary Branches

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Carry just enough state to reject an illegal one: The Binary Branches.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Recursive binary decision tree matches the clues
  2. 2Keep this true after every move: the current path has the requested prefix length and contains no adjacent ones
  3. 3Reach the result within O(Fibonacci(n)) output-sensitive time

Rules and pressure

  • Target cost: O(Fibonacci(n)) output-sensitive time
  • State rule: the current path has the requested prefix length and contains no adjacent ones
Lesson 1 of 3

Live algorithm trace

Recursive binary decision tree

Complete execution
1 of 5
node
0
00
01
10
101

Begin at the root with no chosen bits.

1search(path, previousOne)
2if path length is n: record it
3always append 0 and recurse
4if previous bit was not 1
5append 1 and recurse
6undo after each branch
n = 3path = emptypreviousOne = false
Truth to preserve / Cost target
Truth to preserve

the current path has the requested prefix length and contains no adjacent ones

Cost target

O(Fibonacci(n)) output-sensitive time

At every position choose 0 or 1. The previous bit is sufficient state to prune a 1 after another 1, while the path itself records the candidate.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead