Docsity

Kruskal's Algorithm-Algorithm Fundamentals-Assignment Solution, Exercises of Algorithms and Programming

Toggle sidebar
bg1
CS 502 Fundamental of Algorithms
Assignment # 05
Spring 2012 Total Marks = 20
Deadline
Your๎˜ƒassignment๎˜ƒmust๎˜ƒbe๎˜ƒuploaded๎˜ƒ/๎˜ƒsubmitted๎˜ƒbefore๎˜ƒor๎˜ƒon๎˜ƒJuly 04, 2012
Upload Instructions
Please๎˜ƒview๎˜ƒthe๎˜ƒassignment๎˜ƒsubmission๎˜ƒprocess๎˜ƒdocument๎˜ƒprovided๎˜ƒto๎˜ƒyou๎˜ƒby๎˜ƒthe๎˜ƒ
Virtual๎˜ƒUniversity.๎˜ƒ
๎˜ƒ
Rules for Marking
Please๎˜ƒnote๎˜ƒthat๎˜ƒyour๎˜ƒassignment๎˜ƒwill๎˜ƒnot๎˜ƒbe๎˜ƒgraded๎˜ƒif:๎˜ƒ
โ€ข It๎˜ƒis๎˜ƒsubmitted๎˜ƒafter๎˜ƒdue๎˜ƒdate๎˜ƒ
โ€ข The๎˜ƒfile๎˜ƒyou๎˜ƒuploaded๎˜ƒdoes๎˜ƒnot๎˜ƒopen๎˜ƒ
โ€ข The๎˜ƒfile๎˜ƒyou๎˜ƒuploaded๎˜ƒis๎˜ƒcopied๎˜ƒfrom๎˜ƒsomeone๎˜ƒelse๎˜ƒor๎˜ƒfrom๎˜ƒinternet๎˜ƒ
โ€ข It๎˜ƒis๎˜ƒin๎˜ƒsome๎˜ƒformat๎˜ƒother๎˜ƒthan๎˜ƒ.doc
Note: Material that is an exact copy from handouts or internet would be graded
Zero marks. Your solution should consist of the material found through
different sources and written in your own words.
Assignment Statements:
Question:
Suppose that all edge weights in a graph are integers in the
range from 1 to |V|. How fast can you make Kruskal's
algorithm run? What if the edge weights are integers in the
range from 1 to W for some constant W?
Solution:
We know that Kruskal.s algorithm takes O(V) time for
initialization, O(E lg E) time to sort the edges, and O(E ฮฑ(V))
time for the disjoint-set operations, for a total running time of
O(V + E lg E + E ฮฑ(V)) = O(E lg E).
If we knew that all of the edge weights in the graph were
integers in the range from 1 to |V|, then we could sort the
edges in O(V + E) time using counting sort. Since the graph is
connected, V = O(E), and so the sorting time is reduced to
docsity.com
pf2

Partial preview of the text

Download Kruskal's Algorithm-Algorithm Fundamentals-Assignment Solution and more Exercises Algorithms and Programming in PDF only on Docsity!

CS 502 Fundamental of Algorithms

Assignment # 05

Spring 2012

Total Marks = 20

Deadline

Your assignment must be uploaded / submitted before or on July 04, 2012

Upload Instructions

Please view the assignment submission process document provided to you by the Virtual University.

Rules for Marking

Please note that your assignment will not be graded if:

  • It is submitted after due date
  • The file you uploaded does not open
  • The file you uploaded is copied from someone else or from internet
  • It is in some format other than .doc

Note: Material that is an exact copy from handouts or internet would be graded Zero marks. Your solution should consist of the material found through different sources and written in your own words.

Assignment Statements:

Question:

Suppose that all edge weights in a graph are integers in the range from 1 to | V |. How fast can you make Kruskal's algorithm run? What if the edge weights are integers in the range from 1 to W for some constant W****?

Solution:

We know that Kruskal.s algorithm takes O(V) time for initialization, O(E lg E) time to sort the edges, and O(E ฮฑ(V)) time for the disjoint-set operations, for a total running time of O(V + E lg E + E ฮฑ(V)) = O(E lg E)****.

If we knew that all of the edge weights in the graph were integers in the range from 1 to | V |, then we could sort the edges in O(V + E) time using counting sort. Since the graph is connected, V = O(E) , and so the sorting time is reduced to

docsity.com

O(E)****. This would yield a total running time of O(V + E + E ฮฑ(V)) = O(E ฮฑ(V)) , again since V = O(E) , and since E = O(E ฮฑ(V))****. The time to process the edges, not the time to sort them, is now the dominant term. Knowledge about the weights won.t help speed up any other part of the algorithm, since nothing besides the sort uses the weight values.

If the edge weights were integers in the range from 1 to W for some constant W , then we could again use counting sort to sort the edges more quickly. This time, sorting would take O(E + W) = O(E) time, since W is a constant. As in the first part, we get a total running time of O(E ฮฑ(V))****.

docsity.com