Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time Complexity of the Kruskal Algorithm?

Tags:

I am calculating time complexity for kruskal algorithm like this (Please see the algorithm in the Image Attached)

T(n) = O(1) + O(V) + O(E log E) + O(V log V)      = O(E log E) + O(V log V) as |E| >= |V| - 1 T(n) = E log E + E log E      = E log E 

The CLRS Algorithm:

enter image description here

Is it correct or I'm doing something wrong please tell.

like image 875
Sonali Avatar asked Dec 06 '13 20:12

Sonali


2 Answers

Kruskal is O(E log E); your derivation is right. You could also say O(E log V) because E <= V * V, so log(E) <= 2 log(V) (I don't know why I remember that, other than that I think a prof put that on an exam at one point...)

like image 148
Bandrami Avatar answered Sep 29 '22 22:09

Bandrami


Since |V| > |E|+1, we prefer a tight upper bound with V terms instead of E terms.

    |E| <= |V|²    .   log |E| < log |V|²    .   log |E| < 2 log |V|  .   running time of MST-KRUSKAL is: O(E log V) 
like image 38
MOHIT KUMAR Avatar answered Sep 29 '22 22:09

MOHIT KUMAR