180 likes | 191 Views
Bin sort is an efficient sorting algorithm that takes O(n) time and places nodes with the same key into bins. These bins are then combined to create a sorted list. This chapter also covers equivalence classes, the Union-Find problem, scheduling with deadlines, and net finding problems in data representation.
E N D
Chapter 3 Data Representation Part 3
Applications Bin Sort • Former sorting algorithms take O(n2) time • Bin sort takes O(n) time • In bin sort the nodes are placed into bins, each bin containing nodes with the same key. Then bins are combined to create the sorted list
Algorithm • Move down the input chain moving nodes to the appropriate bin • Collect and concatenate chains from the bins into a single sorted chain
Equivalence Classes Equivalence relation: Given a set U={1,2,…,n} and a set R={(i1,j1),(i2,j2),…,(ir,jr)}, R is equivalence relation iff • (a,a) Є R for all a (reflexivity) • (a,b) Є R iff (b,a) Є R (symmetry) • (a,b) Є R and (b,c) Є R imply that (a,c) Є R (transitivity)
Equivalence class • a and b are equivalent iff (a,b) Є R • Equivalence class: maximal set of equivalent elements e.g., n=14, R={(1,11),(7,11),(2,12),(12,8),(11,12),(3,13),(4,13),(13,14),(14,9),(5,14),(6,10)}, equivalence classes: {1,2,7,8,11,12}, {3,4,5,9,13,14}, {6,10}
Union-Find problem • Offline equivalence class problem: given n and R, determine equivalence classes • Online equivalence class problem: begin with n elements, each in a separate class, process a sequence of Combine(a,b) and Find(e) -- Whenever given a new relation (a,b), determine whether a and b are already in the same class, if not, perform a Union on the two classes that contain a and b • Also called as union-find problem
Scheduling with Deadlines • The problem: single machine that is to perform n tasks, each requires one unit of time, e.g., Task 1 2 3 4 Release time 0 0 1 2 Deadline 4 4 2 3 • Algorithm • Sort the tasks into nonincreasing order of release time • For each task determine the free slot nearest to, but not after, its deadline. If the free slot is before the task’s release time, fail. Otherwise, assign the task to this slot
Implementation • For any slot a (i<=a<=d),near(a) is the largest i such that i<=a and slot i is free. If no such i exists, define near(a)=near(0)=0. Two slots a and b are in the same equivalence class iff near(a)=near(b) • At the beginning, near(a)=a • When slot a is assigned a task, near changes for all slots b with near(b)=a. For these slots the new value of near is near(a-1)
Implementation • Therefore, when slot a is assigned a task, we need the union on the equiv. Classes of a and (a-1)
From Wires to Nets • An electronic circuit consists of components, pins, and wires • Two pins a and b are electrically equivalent iff they are connected directly by a wire or indirectly by wires • A net is a maximal set of electrically equivalent pins
An example • Pins: 1, 2, …, 14 • Wires: {(1,11), (7,11), (2,12), (12,8), (11,12), (3,13), (4,13), (13,14), (14,9), (5,14), (6,10)} • Nets: {1,2,7,8,11,12}, {3,4,5,9,13,14} and {6,10}
Net finding problem • Offline net finding problem - modeled by the offline equivalence problem • Online net finding problem - online equivalence problem • add a wire to connect pins a and b - Combine(a,b) • find the net that contains a - Find(a)
Array based solution • Initilization - Θ(n)
Union and Find • Union - Θ(n) • Find - Θ(1) • u unions and f finds - Θ(n+u*n+f) = Θ(u*n+f)