algorithm - Is it possible to implement linear time BFS in Haskell? -


I have a guided graph as given in the list of instructions list:

  Newtype Graph Int = Graph [(Int, [Int]]  

In G has n sectors and m edges, I am trying to implement the BFS algorithm in Haskell which o ) Runs in time (maybe refined), but the best solution I was able to run in O (M * log n) and data Map Module

My idea of ​​a linear solution is as follows: Use the structure as the efficient FIFA queue from Data.Sequence and make any compulsory BFS Do as much, but I'm stuck at that point. I have to visit the nodes.

My question is: Is it possible to implement BFS in HSKS (or any other purely functional language) that runs in O (M)? And if it is not so, what logic can you use to prove such a statement?

I believe your problem is that you can not apply a good line. Take a look at

Data.Sequence - it should be fixed for the double queue queue because the sequences are incredibly fast adding an element in any form O (1) and removing an element from any side is O (1) .

Once you queue, it should be done along with DFS.

Instead of using an map int [int] you probably might be away from Vector Int [Int]. (If your rows are integer from 1 to n )

Mark to mark the nodes as you type in a IntSet .

This will give you the O (V + E) .

  should get bfs :: V.Vector [Int] -> and gtg. ; Int - & gt; [Int] BFF graph start = ISAMPT graph starting $ S.Salton :: ISIINSetset-> V. Vector [int] - & gt; s. Susunness int -> [Int] Graphical Qi = Case S. AVL Q. Aptyl L - & gt; [] Pinnacle S.: & lt; Rest = Vertical: (Going to 'graph queue') where neighbors = filter (not seen. ISMverver) (graph v. Top!) Seen '= queue seen in SINSERT vortex' = queue s & gt; & Lt; s. Frostist Neighbors  

Note that the way we make this list is completely lazy! So if you only need the first half of BFS, then it does not calculate the remainder.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -