Give a big-o estimate of the number of operations


Question: Give a big-O estimate of the number of operations (comparisons and additions) used by Floyd's algorithm to determine the shortest distance between every pair of vertices in a weighted simple graph with n vertices.

Floyd's algorithm, displayed as Algorithm 2, can be used to find the length of a shortest path between all pairs of vertices in a weighted connected simple graph. However, this algorithm cannot be used to construct shortest paths. (We assign an infinite weight to any pair of vertices not connected by an edge in the graph.)

ALGORITHM 2 Floyd's Algorithm.

procedure Floyd(G: weighted simple graph)

{G has vertices v1, v2........... vn and weights w(vi, vj)

with w(vi, vj) = ∞ if {vi, vj} is not an edge}

for i := 1 to n

for j := 1 to n

d(vi, vj):= w(vi, vj)

for i := 1 to n

for j := 1 to n

for k := 1 to n

if d(vj, vi) + d(vi, vk) < d(vj, vk)

then d(vj, vk) := d(vj, vi) + d(vi, vk)

return [d(vi, vj)] {d(vi, vj) is the length of a shortest path between vi and vj for 1 ≤ i ≤ n, 1 ≤ j ≤ n}

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Give a big-o estimate of the number of operations
Reference No:- TGS02370763

Now Priced at $20 (50% Discount)

Recommended (91%)

Rated (4.3/5)