English 中文(简体)
Graph Adjacency List How to implement O(1) lookup for nodes/vertexes. Array?
原标题:

I read in the specifications for graphs implemented with Adjacency List that adding edges is done in constant time. BUT that would require a node lookup with O(1). I would like best possible performance. The question here is which datatype would would give me that. Hashmap has been considered, worst case with hashmap is still O(n).

Could I use an Array for this? The node s can be of any datatype, generics. Could this be done with some hash function generating index values based on the node alone? That would give me O(1). Sure I can just capitalize and use LinkedList with indexOf. Constant time is best.

最佳回答

Anything with a hashing step you run the risk of collision, so worst case (however unlikely) is Omega(N).

The best possible guaranteed asymptotic performance for insert and retrieve simultaneously when working with lists is O(log N). You ll get that if you store your nodes in something like a heap or balanced tree. You can t do any better on both operations because it would let you violate the provable O(N log N) bound on sorting.

问题回答

暂无回答




相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签