Mapping a Tree to a HashTable data structure
I think a HashTable (of a HashSet) is a very convenient way to represent a tree. It gives you instant access to any element of the tree if there is a unique id representing each node. The problem (and code) below exemplifies this point. Once the representation is there, performing a Depth-First Search becomes very trivial. Code is down below, cheers, ACC. Kill Process - LeetCode You have n processes forming a rooted tree structure. You are given two integer arrays pid and ppid , where pid[i] is the ID of the i th process and ppid[i] is the ID of the i th process's parent process. Each process has only one parent process but may have multiple children processes. Only one process has ppid[i] = 0 , which means this process has no parent process (the root of the tree). When a process is killed , all of its children processes will also be killed. Given an integer kill ...