Categories
algorithm graph python python-3.x

Build graph of organizational structure

I’m having trouble writing an algo that can read a CSV of employee/managers, and output a directed graph featuring the employee/manager relationships.

My foobar example: given the following CSV file

john,
jill, john
tom, john
tim, jill
felisa, tom
ray, tom
bob, tim
jim, tim
pam, felisa
ben, ray
james, ray
mike, pam
rashad, ben
henry, james

How can I build a DiGraph such that the following organizational structure can be shown:

         john
/ \
jill tom
/ / \
tim felisa ray
/ \ / / \
bob jim pam ben james
/ / \
mike rashad henry

Obviously this is a graph problem, but I’m having trouble deciding which structure(s) to use (e.g., would it be best to use a dict or to build a custom OrganizationalGraph object, etc). Any help is appreciated.

The language of choice isn’t really important (though we can just say Python for simplicity [updated tags accordingly]), I’m more so just trying to understand the fundamentals of this type of problem (i.e., recursion vs. iteration, using set() to store a manager’s direct reports vs using only abstracted data structures). Finally, no, using any package outside of the standard library is a non-starter.