Graph Theory37 sections · 1633 units
Open in Course

Think First - Company Queries II

(Before jumping to code)

Pause here. Ask yourself: what type of query is this? Is it asking about a subtree, a path, or an ancestor relationship?

How many queries are there? Can you answer each query in O(n)O(n) time by walking the tree, or do you need faster lookups with preprocessing?

Also consider: are there updates to the tree structure or node values? Or is the tree static after it is built?

Try to identify the technique before reading on. I'll reveal the answer in the next unit.