๐ŸŒฒ
๐Ÿ“ Trees, Heaps & Tries ยท DS-201 ยท Assignments

Trees, Heaps & Tries โ€” Assignments

Work each problem yourself first, then open the worked solution to check your thinking. This is where the course sticks.

๐Ÿ“ 5 problemsโœ๏ธ Worked solutions
Problem 1

Give an example where a list or dict strains, and which structure fixes it.

Show worked solution

A strong answer names a real need (sorted+searchable / top-priority / prefix search) that lists or dicts handle poorly, and matches it to the structure (tree / heap / trie), citing the DS-101 principle that the right structure makes a slow operation fast.

Problem 2

Explain the BST rule and why it makes search fast, in your own words.

Show worked solution

Good answers state smaller-left/larger-right, explain that each comparison discards half the tree (like binary search, O(log n) balanced), and note in-order reading gives sorted values - plus the balance caveat.

Problem 3

Describe the four traversals and one use of each.

Show worked solution

Strong answers give in-order (sorted BST reading), pre-order (copy/serialise), post-order (delete/evaluate), level-order (breadth-first), and note the three depth-first ones differ only in when the node is visited.

Problem 4

Explain how a heap gives the top-priority item fast without full sorting.

Show worked solution

Good answers explain the parent-beats-children rule keeps the top at the root, push/pop are O(log n) via bubble-up/sink-down, and a heap does less than sorting - only the top is guaranteed - which is all a priority queue needs.

Problem 5

Explain how a trie makes prefix search / autocomplete fast.

Show worked solution

Strong answers describe storing words letter by letter so shared prefixes share a path, so prefix search walks to the prefix node and collects everything below - instant autocomplete, trading memory for fast prefix queries.

More in this course

Course home → · Browse all courses →