With integer edge weights you can use bucketing to achieve a priority queue with worst-case O(1)
complexity, but additional O(U)
space complexity.
Within the MST algorithms you've mentioned you should be able to replace the comparison based priority queues with this integer structure, and hence remove the O(log(n))
depenedence in the complexity requirements. I expect you'd end up with an overall complexity in the style of O(n + m)
.
Essentially you setup a set of compressed linked-lists, where each list is indexed by the (integer!) cost associated with that bucket:
struct bucket_list
{
_cost; // array[0..N-1] holding current cost for each item
_head; // array[0..U-1] holding index of first item in each bucket
_next; // array[0..N-1] where _next[i] is the next item
// in a list for the ith item
_prev; // array[0..N-1] where _prev[i] is the last item
// in a list for the ith item
};
This structure is based on the fact that each item can only be in a single bucket list at once.
Based on this structure you can achieve worst-case O(1)
complexity for these operations:
push(item, cost); // push an item onto the head of the appropriate bucket list
_pop(item, cost); // _pop an item from (anywhere!) within a bucket list
update(item, old_cost, new_cost); // move an item between buckets by combining
// push and _pop
To use this structure as a priority queue you simply maintain an index pointing at the current minimum bucket to scan. When you want to get the next lowest cost item, you simply pop the head item from this bucket. If the bucket is empty you increment your bucket index until you find a non-empty one.
Of course if U
becomes very large the extra space complexity, and the possiblity of a sparse distribution of items over the buckets may make this kind of approach unattractive.
O(log(n))
style structure). As usual with a hash queue all items with the same integer cost are placed in the same bucket, and you can get worst-caseO(1)
operations. I assume this would remove theO(log(n))
complexity from the algorithms you've mentioned, leaving something likeO(m + n)
... – Darren Engwirda