The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+20 votes

What is the time complexity of Bellman-Ford single-source shortest path algorithm on a complete graph of n vertices?

- $\theta(n^2)$
- $\theta(n^2\log n)$
- $\theta(n^3)$
- $\theta(n^3\log n)$

+39 votes

Best answer

Time complexity of Bellman-Ford algorithm is $\Theta(|V||E|)$ where $|V|$ is number of vertices and $|E|$ is number of edges. If the graph is complete, the value of $|E|$ becomes $\Theta\left(|V|^2\right)$. So overall time complexity becomes $\Theta\left(|V|^3\right)$. And given here is $n$ vertices. So, the answer ends up to be $\Theta\left(n^3\right)$.

+13 votes

as we know time complexity of bellman-ford is O(En) where E is no of edges and n is no of vertices

and in complete graph no of edges is E=n(n-1)/2 where n is no of vertices

here E=O(n^{2})

so time complexity of bellman-ford algorithm on complete graph with n vertices is O(n^{3})

so ans is C.)

- All categories
- General Aptitude 1.5k
- Engineering Mathematics 7.1k
- Digital Logic 2.7k
- Programming & DS 4.9k
- Algorithms 4.2k
- Theory of Computation 5.3k
- Compiler Design 2.1k
- Databases 4k
- CO & Architecture 3.5k
- Computer Networks 4k
- Non GATE 1.4k
- Others 1.5k
- Admissions 559
- Exam Queries 555
- Tier 1 Placement Questions 23
- Job Queries 69
- Projects 18

47,932 questions

52,335 answers

182,384 comments

67,817 users