Unformatted text preview: O (  V  +  E  ). Implementation Issue: ( 8 points ) We use two FIFO queues Q 1 and Q 2 to achieve the function of a priority queue. Q 1 contains items of weight 1 and Q 2 contains items of weight 2. • Operation Extract Min() can be done in O (1) time as follows: If Q 1 is not empty, dequeue the ±rst item from the front of Q 1 ; else if Q 1 is empty, dequeue the ±rst item from the front of Q 2 . • Operation Decrease Key( u , newKey ) can be done in O (1) time as follows: If newKey is 2 (or 1), enqueue the element u to the rear of Q 2 (or Q 1 ). By replace the priority queue with the two FIFO queues, Prim’s algorithm can compute a MST of G in O (  V  +  E  ) time. 1...
View
Full
Document
This note was uploaded on 10/18/2009 for the course COMP 271 taught by Professor Arya during the Spring '07 term at HKUST.
 Spring '07
 ARYA
 Algorithms

Click to edit the document details