02-greedy

42 but how do you keep track of what trees a node is

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: ” + edgelist[i].w) count = count + 1 union(edgelist[i].v ,edgelist[i].w) } i = i + 1 } } 43 Union/Find and Disjoint Sets Sets stored as a parent array findset(v): trace upward in parent array union(i,j): make one tree a child of a node it the other Improvements! Union by rank Path compression 44 Union by rank 45 Path Compression 46 Complexity for Kruskal’s A basic analysis leads us to (n2) But with the optimizations presented here, it can be reduced to (m lg m) 47 Interval Selection 48 Activity­Selection Problem Problem: You and your classmates go on Semester at Sea Each starting and ending at different times Many exciting activities each morning Maximize your “education” by doing as many as possible. (They’re all equally good!) Welcome to the activity selection problem 49 Also called interval scheduling The Activities! Id Start End 1 2 9:00 9:15 10:45 10:15 3 4 9:30 9:45 12:30 10:30 5 6 7 8 9 10 11 9:45 10:15 10:15 10:30 11:00 11:00 12:00 11:15 11:00 11:30 11:45 12:00 12:15 12:45 50 Activity Fractals, Recursion and Crayolas Tropical Drink Engineering with...
View Full Document

Ask a homework question - tutors are online