Skip to content

Commit 473d64f

Browse files
committed
Adding a Radix LSB
1 parent cc1b339 commit 473d64f

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

algorithm/category.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"bubble": "Bubble Sort",
3131
"quick": "Quicksort",
3232
"merge": "Mergesort",
33-
"heap" : "Heap Sort"
33+
"heap" : "Heap Sort",
34+
"radixlsb" : "Radix LSB sort"
3435
}
3536
},
3637
"string": {

algorithm/category.json~

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"graph_search": {
3+
"name": "Graph Search",
4+
"list": {
5+
"dfs": "DFS",
6+
"bfs": "BFS",
7+
"dijkstra": "Dijkstra",
8+
"bellman_ford": "Bellman-Ford",
9+
"floyd_warshall": "Floyd-Warshall",
10+
"topological_sort": "Topological-Sort"
11+
}
12+
},
13+
"mst": {
14+
"name": "Minimum Spanning Tree",
15+
"list": {
16+
"prim": "Prim's Algorithm"
17+
}
18+
},
19+
"search": {
20+
"name": "Search",
21+
"list": {
22+
"binary_search": "Binary Search"
23+
}
24+
},
25+
"sorting": {
26+
"name": "Sorting",
27+
"list": {
28+
"insertion": "Insertion Sort",
29+
"selection": "Selection Sort",
30+
"bubble": "Bubble Sort",
31+
"quick": "Quicksort",
32+
"merge": "Mergesort",
33+
"heap" : "Heap Sort"
34+
}
35+
},
36+
"string": {
37+
"name": "String",
38+
"list": {
39+
"edit_distance": "Edit Distance"
40+
}
41+
},
42+
"etc": {
43+
"name": "Uncategorized",
44+
"list": {
45+
"dp": "Dynamic Programming",
46+
"scratch_paper": "<i class='fa fa-code'></i> Scratch Paper"
47+
}
48+
}
49+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
tracer._print('original array = [' + D[0].join(', ') + ']');
2+
tracer._sleep(1000);
3+
tracer._pace(300);
4+
function pow(base, expo){
5+
var ans = 1;
6+
for(var i = 0; i < expo;i++){
7+
ans *= base;
8+
}
9+
return ans;
10+
}
11+
for(var exp = 0; exp < 8;exp ++){
12+
tracer._print("Bit "+exp);
13+
for(var i = 0; i < D[0].length; i++){
14+
tracer._select(0, i);
15+
D[2][ parseInt( D[0][i] / pow(2, exp) % 2) ] += 1;
16+
tracer._notify(2, parseInt( D[0][i] / pow(2, exp) % 2) );
17+
tracer._deselect(0, i);
18+
}
19+
D[2][1] += D[2][0];
20+
tracer._notify(2, 1);
21+
for(var i = D[0].length - 1; i >= 0; i--){
22+
tracer._select(0, i);
23+
D[2][parseInt( D[0][i] / pow(2, exp) % 2) ] -= 1;
24+
tracer._notify(2, parseInt( D[0][i] / pow(2, exp) % 2) );
25+
D[1][ D[2][ parseInt( D[0][i] / pow(2, exp) % 2) ] ] = D[0][i];
26+
tracer._notify(1, D[2][ parseInt( D[0][i] / pow(2, exp) % 2) ] );
27+
tracer._deselect(0, i);
28+
}
29+
for(var i = 0; i < D[0].length; i++){
30+
tracer._select(1, i);
31+
D[0][i] = D[1][i];
32+
tracer._notify(0, i);
33+
tracer._deselect(1, i);
34+
}
35+
D[2][0] = 0;
36+
D[2][1] = 0;
37+
tracer._notify(2, 0);
38+
tracer._notify(2, 1);
39+
}
40+
tracer._print('sorted array = [' + D[0].join(', ') + ']');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var tracer = new Array2DTracer();
2+
var k = [5,4,3,5,7,5,6,9];
3+
var D = [
4+
k,
5+
Array1D.random(k.length),
6+
[0,0]
7+
];
8+
tracer._setData(D);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Radix LSB Sort": "Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual bits which share the same significant position and value.",
3+
"Complexity": {
4+
"time": "worst O(n), best O(n), average O(n)",
5+
"space": "always O(n)"
6+
},
7+
"References": [
8+
"<a href='https://en.wikipedia.org/wiki/Radix_sort'>Wikipedia</a>"
9+
],
10+
"files": {
11+
"basic": "Basic"
12+
}
13+
}

0 commit comments

Comments
 (0)