|
|
|
|
|
by mcintyre1994
4566 days ago
|
|
I know it's a bit off-topic, but I'm a student so anything about interviews interests me a lot. For the Bacon Number question, I'm struggling a bit to get my head around a good way to do it. My immediate idea is to derive a graph where nodes are actors and an edge between 2 actors means they've been in 1 or more films together. I believe the shortest path between them and Bacon could then be found by breadth-first search. It looks like that graph would be quite slow to derive though - my naive pseudocode being something like: for bucket in hashtable:
for actor in bucket:
if actor not in graph, add a node for actor
for other_actor in bucket (up to actor):
add an edge between other_actor and actor
That looks pretty slow without deriving a running time, so I'm guessing there's some optimisation that can be made from the current structure of the hashtable. Could anybody give me a pointer in the right direction please? |
|
Instead, your graph should comprise movies and actors as vertices (edge = actor was in a given movie), and to get the Bacon number you just halve the distance in this graph.
So you code would look like
If each movie contains exactly K actors, and there are N movies, then your graph has O(NK^2) edges while mine has O(NK) edges.