1 / 18

Bin Sort: A Time-Efficient Sorting Algorithm

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.

babineau
Download Presentation

Bin Sort: A Time-Efficient Sorting Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 Data Representation Part 3

  2. 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

  3. An example - Student records

  4. Algorithm • Move down the input chain moving nodes to the appropriate bin • Collect and concatenate chains from the bins into a single sorted chain

  5. Bin Sort as a Member of the Class Chain

  6. Bin Sort as a Member of the Class Chain

  7. 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)

  8. 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}

  9. 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

  10. 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

  11. 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)

  12. Implementation • Therefore, when slot a is assigned a task, we need the union on the equiv. Classes of a and (a-1)

  13. 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

  14. 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}

  15. 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)

  16. Array based solution • Initilization - Θ(n)

  17. Union and Find • Union - Θ(n) • Find - Θ(1) • u unions and f finds - Θ(n+u*n+f) = Θ(u*n+f)

  18. The end of Chapter 3Part 3

More Related