Skip to content

Implemented Pigeonhole Sort #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion algorithm/category.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@
"bucket": "Bucket Sort",
"bubble": "Bubble Sort",
"comb": "Comb Sort",
"counting": "Counting Sort",
"counting": "Counting Sort",
"cycle": "Cycle Sort",
"heap": "Heapsort",
"insertion": "Insertion Sort",
"merge": "Merge Sort",
"pigeonhole": "Pigeonhole Sort",
"quick": "Quicksort",
"radix": "Radix Sort",
"selection": "Selection Sort",
Expand Down
42 changes: 42 additions & 0 deletions algorithm/sorting/pigeonhole/basic/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var min = A[0];
var max = A[0];

for( var i = 1; i < N; i++ ) {
if( A[i] < min ) {
min = A[i];
}
if( A[i] > max ) {
max = A[i];
}
}
var range = max - min + 1;

var holes = new Array ( range );
for ( var i = 0; i < range; i++ ) {
holes[i] = [];
}
tracer2._setData( holes );

logTracer._print ( 'Filling up holes' );
for ( var i = 0; i < N ; i++ ) {
tracer1._select ( i )._wait ();

holes[ A[i] - min ].push( A[i] );

tracer2._setData( holes );
tracer1._deselect ( i );
}

logTracer._print ( 'Building sorted array' );
var k = 0;
for ( var i = 0; i < range ; i++ ) {
for (var j = 0; j < holes[i].length; j++ ) {
tracer2._select ( i, j )._wait ();
A[k++] = holes[i][j];
tracer1._notify ( k-1, A[k-1] )._wait ();
tracer2._deselect ( i, j );
tracer1._denotify ( k-1 );
}
}

logTracer._print ( 'Sorted array is ' + A );
6 changes: 6 additions & 0 deletions algorithm/sorting/pigeonhole/basic/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var A = Array1D.random(7);
var N = A.length;

var tracer1 = new Array1DTracer ( 'Array' )._setData ( A );
var tracer2 = new Array2DTracer ( 'Holes' );
var logTracer = new LogTracer ( 'Console' );
13 changes: 13 additions & 0 deletions algorithm/sorting/pigeonhole/desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Pigeonhole Sort": "Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the number of possible key values (N) are approximately the same.",
"Complexity": {
"time": " O(n + N)",
"space": "O(n)"
},
"References": [
"<a href='https://en.wikipedia.org/wiki/Pigeonhole_sort'>Wikipedia</a>"
],
"files": {
"basic": "Pigeonhole Sort"
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy