tags:

views:

119

answers:

2

Hi, I was wondering if this rope bridge problem could be solved with a graphing algorithm search:

My gut feeling says DFS but how should I define the states? (That is if DFS is even the way to go.)

Rope Bridge

+2  A: 

This task is supposed to be solved without a computer.

However, if you generalize the case, then, I suppose, you can do it with graph searching, but you should take the size of the graph into account. If each vertex is the "state", then the number of this states estimates as 2N⋅L, where N is the number of people, and L is the length of the flashlight. Each state contains information, which side is each person at, and of remaining flashlight duration. If there's a path from initial state to one of those states where everyone's on the camp's side, then this path is the solution.

That's the most obvious way to create states, but maybe you can do it in a more efficient way (current number of states, hence the runtime, is exponential to the input size).

However, for the sizes that small as in the sample you provided, exponential runtime (with graphs) is acceptable. The interviewer may even like it, if you suggest programmatic solution instead of doing it by hand.

Pavel Shved
Length of the flashlight??? I guess you meant either length of the bridge or flashlight runtime.
sharptooth
He means the length of time left in the flashlight (or as you put it flashlight runtime).
NickPoussin
Thanks Pavel. Your explanation of the state "Each state contains information, which side is each person at, and of remaining flashlight duration" helped me a lot. I think I will try programming this for fun tomorrow.
NickPoussin
A: 

You might want to look at EWD 1255.

TheMachineCharmer
TheMachineCharmer,Thanks for the link, I found it to be an interesting read. If I understand what Prof Dijkstra is conveying, though, then there are no “alphas” in the Rope Bridge problem. Perhaps there are and I just don't see them?
NickPoussin
I just posted as something related and informative. Made it c-wiki. :D
TheMachineCharmer