02-greedy

Cost for one call is n but if we can index an array

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ations Consider using a min-heap for the Priority Queue PQ.ExtractMin() is O(lg n) each time What about PQ.decreaseKey() ? Our need: given a vertex-ID, change the value stored Called n times, so like Heap’s Construct: efficient! But our basic heap implementation does not allow lookups based on vertex-ID! Solution: Indirect heaps 35 Heap structure stores indices to data in an array that doesn’t change Better PQ Implementations (2) Use Indirect Heaps for the PQ PQ.decreaseKey() is O(lg n) also So O(m lg n) Called for each edge encountered in MST algorithm Overall: Might be better: (n2) than if m << n2 Fibonacci heaps: an even more efficient PQ implementation. We won’t cover these. 36 (m + n lg n) Kruskal’s MST 37 Kruskal’s MST Algorithm Prim’s approach: Build one tree. Make the one tree bigger and as good as it can be. Kruskal’s approach Choose the best edge possible: smallest weight Not one tree – maintain a forest! Each edge added will Can’t form a cycle in a tree...
View Full Document

This note was uploaded on 02/25/2014 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.

Ask a homework question - tutors are online