Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

"Firehouse" Problem

Name: Anonymous 2009-01-30 15:51

If you have an undirected, unweighted graph G, and a marked subset of points called 'Firehouses,' is there an O(n+m) algorithm to find every vertex's closes firehouse?

I can only come up with O(n^2) stuff. Although I do like the idea of repeatedly raising the adjacency matrix to a power n, until every vertex has a nonzero entry :P

Name: Anonymous 2009-01-30 15:56

Install Linux and read SICP.

Name: Anonymous 2009-01-30 16:03

:( I'm on linux and I'm browsing SICP.

Name: Anonymous 2009-01-30 16:06

HOW ABOUT YOU READ IT FAGGOT

Name: Anonymous 2009-01-30 16:11

You could use some sort of parallel breadth first search.

Name: Anonymous 2009-01-30 16:41

Install OpenBSD and read TAOCP.

Name: Anonymous 2009-01-30 17:32

Install Windows and read "Everybody Poops".

Name: Anonymous 2009-01-30 17:37

Install Mac OS X and pretend you can read.

Name: Anonymous 2009-01-30 18:34

Fuck it, get a Wii

Name: Anonymous 2009-01-30 20:36

You didn't even specify what n and m are, so I will assume that m = 2^n, in which case you are wanting a O(2^n) algorithm which is simple to find. Good luck.

Name: Anonymous 2009-01-30 21:53

Call the people living at every vertex, ask them what the closest firehouse is. O(n).

Name: Anonymous 2009-01-31 0:01

>>11
Suck my dick. O(n^3).

Name: Anonymous 2009-01-31 0:46

>>12
There's therapy for that now.

Name: Anonymous 2009-01-31 5:24

Use a large megaphone to ask everybody all at once. O(1).

Name: Anonymous 2009-01-31 6:38

let the shit burn. O(0)

Name: Anonymous 2009-01-31 7:37

For each firehouse assign the neighbors of that firehouse to it. Then for each firehouse assign the neighbors of the vertices that were assigned to that firehouse in the previous round to it. Repeat until all vertices have been assigned.

Name: Anonymous 2009-01-31 8:59

>>10-15
I love you, /prog/

Name: Anonymous 2009-01-31 9:24

The best algorithm I can come up with is O(nm), where n is the number of firehouses and m is the number of edges in G.

Name: >>18 2009-01-31 9:27

Fuck, I hadn't read >>16. Oh well, carry on.

Name: Anonymous 2009-01-31 12:38

>>18

That's not good enough. I think I might have gotten it though.

You're not allowed to know which are firehouses until you visit the points so here's what I came up with.

Initialize every vertex's distance to 0.
Begin a standard depth first search on any vertex v.
Until the first firehouse is found, add 1 to the distance of each vertex you have visited.

When the first firehouse is found, keep it's distance to zero, and then continue the depth first search, assigning the distance as the minimum of its parent's distance+1, or any of it's backedges+1.

I think that works in O(n+m) time.

Name: Anonymous 2009-01-31 13:14

>>20
You still haven't defined n or m, so assuming m = 2^n, yes, the algorithm does run in O(n+m) = O(2^n) time.

Name: Anonymous 2009-01-31 13:19

m is the number of edges, n is the number of vertices.

Name: Anonymous 2009-01-31 14:04

Did >>5 elude you somehow? Do any search you'd like first to find all the fucking firehouses. Do a BFS with a start point at each firehouse, keep track of origin (optional), and assign nodes to houses as you encounter them. Oh, and of course, don't keep your graph in a god damn adjacency matrix. HTH, Now stop trolling.

Name: Anonymous 2009-01-31 14:20

>>23


That doesn't run in the given bounds since you're doing 2 searches.

Fail.

Name: Anonymous 2009-01-31 14:22

Do the firehouses have anii? If so it's advised you hax them.

Name: Anonymous 2009-01-31 16:41

>>24
You can run each BFS concurrently.

Name: Anonymous 2009-01-31 22:35

>>24
You must have missed the part in my post where I quite explicitly said "Now stop trolling."

Name: Anonymous 2009-03-06 10:54

substring 1 c length   2 0x var.

Name: Anonymous 2009-03-06 12:42


firehouse to it Then you are greatly.

Name: Anonymous 2011-02-03 8:12

Don't change these.
Name: Email:
Entire Thread Thread List