Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Patterns & lessons
Sign inSign up
Patterns/Graphs/Strongly Connected Components & Condensation

Technique

2-SAT

Model each boolean variable as two literals, each clause (a or b) as implications not a -> b and not b -> a, and solve with SCCs.

Learn firstStrongly Connected Components & Condensation
0%
mastery
0/2 solved
Practise nextGiant Pizza
IdeaPracticePitfalls

Recognise it

The signal

each item picks one of two options with pairwise constraints

  1. 1Brute force

    Try all 2n assignments.

  2. 2The observation

    Exponential assignments: implications propagate in the SCC condensation.

  3. 3Why it works

    Unsatisfiable iff x and not x are in the same SCC; otherwise pick the literal later in topological order.

Reach for it when

  • +clauses of size two

Not when

  • ×clauses of size three (3-SAT is NP-hard)

Practice

Next

Giant Pizza

0/2 solved
  • Giant PizzaCSESHard
  • Two Stacks SortingCSESHard

Pitfalls

Misconceptions

  • !adding only one direction of each implication
Go deeper1 combinations · resources

Combinations

  • Strongly Connected Components & Condensation+2-SAT

    each item chooses one of two options with pairwise 'at least one' constraints

    Strongly Connected Components & Condensation:
    finds contradictions x <-> not x
    2-SAT:
    models the clauses as implications

    Giant Pizza

Resources

  • Graph Theory playlistWilliam Fiset · video
  • Graph TraversalUSACO Guide · course
  • Disjoint Set Unioncp-algorithms · article
  • Dijkstracp-algorithms · article
  • Topological sortingcp-algorithms · article
  • Shortest paths visualizerVisuAlgo · tool
  • Graph cheatsheetTech Interview Handbook · article
TodayReviewPatternsProblems