Download - Bead-Sort - A natural algorithm for sorting
![Page 1: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/1.jpg)
Bead-Sort- A natural algorithm for sorting
![Page 2: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/2.jpg)
Beads sort themselves out
![Page 3: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/3.jpg)
900
Bead-Stack machineThe “tilt” operation
![Page 4: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/4.jpg)
Sorting {3, 1, 2}
2. Drop 1 bead
3. Drop 2 beads
1. Drop 3 beads(Remember, always from left-to-right)
12
3
Bead-Sort: illustration 1
![Page 5: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/5.jpg)
Sorting {2, 3, 1}
2. Drop 3 beads
3. Drop 1 beads
1. Drop 2 beads(Remember, always from left-to-right)
1
2
3
Bead-Sort: illustration 2
![Page 6: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/6.jpg)
Sorting {1, 3, 2}
2. Drop 3 beads
3. Drop 2 beads
1. Drop 1 bead(Remember, always from left-to-right)
1
2
3
Bead-Sort: illustration 3
![Page 7: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/7.jpg)
Sorting {1, 3, 2, 4}
2. Drop 3 beads
3. Drop 2 beads
1. Drop 1 bead(Remember, always from left-to-right)
4. Drop 4 beads
3
4
1
2
Bead-Sort: illustration 4
![Page 8: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/8.jpg)
Sorting {2, 4, 3, 2}
2. Drop 4 beads
3. Drop 3 beads
1. Drop 2 beads(Remember, always from left-to-right)
4. Drop 2 beads
4
2
2
3
Bead-Sort: illustration 5
![Page 9: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/9.jpg)
Simulating Bead-Sort with a program
• Two linear arrays used.
• Rod_Count keeps track of number of beads in each rod.
• Level_Count records number of beads in each level.
• Finally, Level_Count will contain sorted data.
1
3
0
0
Lev
el_C
ount
Rod_Count
2 1 1
![Page 10: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/10.jpg)
Bead-Sort: Proof of correctnessMathematical induction on number of rows of beadsClaims:
(i) Rows of beads represent the same set of positive integers before and after dropping down.
(ii) After dropping, each row has beads less than (or equal to) that on the row directly below it.
1 row (k = 1)
2 rows (k = 2)
(i)
(ii)
(iii)
x
x + i x i
xx + i
x
i
![Page 11: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/11.jpg)
Bead-Sort: Proof of correctness
k+1th row
k rows
the smallest amongst k rows
the smallest amongst k+1 rows has already emerged on top
![Page 12: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/12.jpg)
Parallel implementation of Bead-SortUsing a digital circuit
flip-flops
presence of bead - 1
absence of bead - 0
c1
c2
cn
1 1 1
1 1
1 1 1
0
0
0
0 0
0
0
0
0
0
00
c1
c2
cn
1 1 1
1 1
1 1
1
0
0
0
0 0
0
0
0
0
00
0Data entry register 1 1 1
0ci
t
ci-1
Cit+1
Input from corresponding cell in data entry register
![Page 13: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/13.jpg)
Calculating currentResistor chain 1:I1 = V1/R = 3/(1+2+3) = 1/2 AResistor chain 2:I2 = V2/R = 2/(1+2+3) = 1/3 AResistor chain 3:I3 = V3/R = 1/(1+2+3) = 1/6 A
1 1 0 (no.2)
1 0 0 (no. 1)
1 1 1 (no. 3)
3 2 1
‘Trim’ Voltage :
Trim( v ) =
1 if v >= 0.5
0 otherwise
V2V2V1V1 V3V3
Trim
Trim
Trim
Trim
Trim
Trim
Trim
Trim
Trim
vv11
vv22
vv33
1
2
3
1
2
3
1
2
3
Increase voltage by 1 unit every time a ‘1’ is sent
1 1 0
(strings of 1’s similar to balls)DATA ENTRY
1 1 01 1 02 1 02 1 03 2 13 2 1
1/2 A 1/3 A 1/6 A
0.5 V
1 V
1.5 V
0.3 V
0.7 V
1 V
0.2 V
0.3 V
0.5 V
1 V
2 V
3 V
sorted data
Parallel implementation Using an analog circuit
![Page 14: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/14.jpg)
000
initial configuration
{2,1,3}
1 1 1
1
11
0 0
0
final configuration
{1,2,3}
000
1
1
1
1
11
0
00
0
0 0
0
1
0 1
0
0
0 0
1
1
0 1
1
0
1 0
0
1
1 0
0
0
1 1
1
1
1 1
1
1 2 3 4 5 6 7 8
CA rules for Bead-Sort simulation
Parallel simulationUsing a cellular automaton (CA)
![Page 15: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/15.jpg)
Bead-Stack machineLoading the input (beads)
1 2 3 4
Pushing button-1 will make one bead to drop down, pushing button-2 will make two beads to drop down (in parallel), and so on.
![Page 16: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/16.jpg)
900
Bead-Stack machineThe “tilt” operation
![Page 17: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/17.jpg)
Bead-Stack machineReading the output
only label ‘3’ is seen
11 22 33
11 22 33 44
11 22
11
labels stuck on the sides (of the beads)
Beads rolled down along rod-1 will have the label “1”, those rolled down along rod-2 will have “2”, and so on.
![Page 18: Bead-Sort - A natural algorithm for sorting](https://reader036.vdocuments.mx/reader036/viewer/2022062301/568143a1550346895db02385/html5/thumbnails/18.jpg)
Bead-Stack machineComplexity of inputting, sorting and outputting a listInputting a list: Using the gadget that loads a row-of-beads, we need N (loading) operations to input a list of size N (into the frame of the Bead-Stack machine).
Sorting a list: We tilt the frame 90o (a single operation, from the Bead-Stack machine’s perspective). The time taken by the falling beads to settle down is sqrt(2h/g), where h is the height of the rods and g, the acceleration due to gravity. If we fix the height of rods to be the same as the size (N) of the list, then the time taken is given by sqrt(2N/g), i.e. O(sqrt(N)).
Outputting a list: Nothing needs to be done to explicitly output rows of beads; the user could (literally) read the output (row by row).