← SAP questions

Generate connectivity matrix from a tree using preorder traversal

Filed under SAP

Given a rooted directed tree with $N$ nodes labeled from $0$ to $N-1$, generate an $N \times N$ connectivity/reachability matrix using preorder traversal. Entry `matrix[u][v] = 1` if node $v$ is…

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related SAP questions

Collected from public candidate posts and coding forums. Updated Nov 2026.