0

I have a simple graphing problem where I traverse a graph looking for an item. Each node in the graph has a probability n/100 of the item being there, where the sum of all the probabilities equals 1. How can I find the minimum expected time to search for the item in the entire graph?

The item is guaranteed to exist in only one node.

At first glance it seems like a traveling sales person problem and that is simple. Just get the permutations of the the paths and calculate the path for each and return the minimum.

But then it gets tricky when I need to find the minimum expected time. Is there any mathimatical formula that I could plug in on the minimal path to get the result?

ie: sum = 0
    for node in path:
        sum += node.prob * node.weight

Or is there something more complicated that needs to be done?

TheOne
  • 10,819
  • 20
  • 81
  • 119
  • Please don't tag questions with what _might_ be a possible solution. Also, you are missing details. How exactly do you traverse the graph? –  Feb 24 '11 at 18:58
  • @Moron: you mean math? Regarding the traversal, I mention that I get the permutations of all the paths and return the one with the minimum cost. – TheOne Feb 24 '11 at 19:01
  • 3
    I mean [traveling-salesman]. Also, my point was, the expected time depends on _how_ you traverse. You claim you are looking for an item.... If you are looking at all permutations, why even talk about a graph? Your question is not at all clear. –  Feb 24 '11 at 19:04
  • 2
    The minimum expected time is 1. That is, at minimum, you will find the item at the first node you search. The maximum expected time will depend on the depth of your graph. All other expectations are highly dependent on the structure of your graph. "Just get the permutations" is simple, but I think you'll find that if you try to do that it will take you longer than forever if you have more than a handful of nodes in the graph. – Jim Mischel Feb 24 '11 at 21:20
  • Wait ... are you trying to find the shortest path (http://en.wikipedia.org/wiki/Shortest_path_problem) to a node in a directed graph? – Jim Mischel Feb 24 '11 at 21:23

1 Answers1

2

If all you're doing is looking for a particular item, then you're guaranteed to be at most n lookups.

If the item is 100% guaranteed to exist in the graph, and it will exist exactly once, then you'll find it after approximately n/2 searches. So (time to search one node) * (n / 2) is your expected time.

If you want a better answer than that you need more information.

Also, you should clarify what "each node in the graph has a probability n/100 of the item being there" means. This seems to indicate if I have 1 node in my graph, there's a 1/100 chance of it being on the node I check, but that if I have 100 nodes, I have a 100/100 chance. That, my friend, makes as much sense as a chimpanzee in a tutu.

corsiKa
  • 81,495
  • 25
  • 153
  • 204
  • Then your expected time will be `aw*n/2` where `aw` is the average weight of a node (assuming the weight and the time are proportional.) On average you will have to search half the nodes. – corsiKa Feb 24 '11 at 21:08
  • but what if the path contains dead ends, so you have to revisit some nodes you've already hit? It seems to me like this is a quite hard problem, and one that is probably related to the min TSP length, as the OP suggests. – Xodarap Feb 25 '11 at 19:03
  • @Xodarap That's a good question - it shows thought put into the nature graphs. However you won't have to revisit nodes if you have a recursive function, you'll simply go to the next node connected to your current node based on the return value of the first one. A search that requires you to visit each node at least once should be implemented in a way that allows you to visit each node exactly once. – corsiKa Feb 25 '11 at 19:06