# O(N) Sort Data Structures

**URL:** <https://es.discourse.group/t/o-n-sort-data-structures/598>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [December 29, 2020, 6:13am UTC](https://es.discourse.group/t/o-n-sort-data-structures/598 "2020-12-29T06:13:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seagat2011](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/seagat2011/32/367_2.png) [@Seagat2011](https://es.discourse.group/u/Seagat2011)\
**Post date:** [December 29, 2020, 6:13am UTC](https://es.discourse.group/t/o-n-sort-data-structures/598/1 "2020-12-29T06:13:22Z")

</div>

There are now neural networks powerful enough to facilitate order O(N) Sort, provided all entries are matching datatype...

```javascript
Example #1

let a = new SortedUInt8Array() // cf. SortedUInt16Array SortedUInt32Array SortedUInt64Array SortedInt8Array SortedInt16Array SortedInt32Array SortedInt64Array

a.push(255)
a.push(8)
a.push(12)
a.push(7)

a /* [7,8,12,255] */
a[0] /* 7 */

Example #2

a = new SortedCharArray() // cf. SortedCharArrayUpper SortedTextArray SortedTextArrayUpper

a.push('c')
a.push('z')
a.push('e')
a.push('a')

a /* ['a','c','e','z'] */
a[0] /* 'a' */

```

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [December 29, 2020, 4:09pm UTC](https://es.discourse.group/t/o-n-sort-data-structures/598/2 "2020-12-29T16:09:40Z")

</div>

Did you confuse a [sorting network](https://en.wikipedia.org/wiki/Sorting_network) with a neural network?

Also it's not quite clear what the array types you are suggesting would be doing exactly, and why they would need to be builtin instead of being provided by a library.

---

<div class="post-metadata">

**Author:** ![jun-sheaf](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jun-sheaf/32/505_2.png) [@jun-sheaf](https://es.discourse.group/u/jun-sheaf)\
**Post date:** [December 29, 2020, 4:50pm UTC](https://es.discourse.group/t/o-n-sort-data-structures/598/3 "2020-12-29T16:50:39Z")

</div>

Can you provide a paper? By the way, O(n) sort is already achieved using radix and counting sort, but in practice, they are not viable for sufficiently small arrays.

---

<div class="post-metadata">

**Author:** ![Seagat2011](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/seagat2011/32/367_2.png) [@Seagat2011](https://es.discourse.group/u/Seagat2011)\
**Post date:** [December 30, 2020, 12:26am UTC](https://es.discourse.group/t/o-n-sort-data-structures/598/4 "2020-12-30T00:26:07Z")

</div>

```javascript
// A non-radix based O( N ) solution, implementing a NN global shift register
a.push( 8 ) // = 1 1 1 1 1 1 1 1
a.push( 3 ) // = 1 1 1 0 0 0 0 0
a.push( 5 ) // = 1 1 1 1 1 0 0 0 
a.push( 7 ) // = 1 1 1 1 1 1 1 0
            // Allowing 1's to the bottom of a column; and 0's to the top of a column...
            //--------------------
a[0] // = 1 1 1 0 0 0 0 0 = 3
a[1] // = 1 1 1 1 1 0 0 0 = 5
a[2] // = 1 1 1 1 1 1 1 0 = 7
a[3] // = 1 1 1 1 1 1 1 1 = 8

```

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [December 30, 2020, 3:10pm UTC](https://es.discourse.group/t/o-n-sort-data-structures/598/5 "2020-12-30T15:10:29Z")

</div>

Please provide an _algorithm_ (or a link to it) for your `O(1)` sorted-push method, not a random example.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [January 2, 2021, 6:50pm UTC](https://es.discourse.group/t/o-n-sort-data-structures/598/6 "2021-01-02T18:50:51Z")

</div>

I did find one example (provided a known upper bound exists): [https://en.wikipedia.org/wiki/Bucket\_queue](https://en.wikipedia.org/wiki/Bucket_queue)

Also, things like counting sort, pigeonhole sort, and bubble sort exist that provide O(n) integer sorting and [those could be used to build fully constant-time integer priority queues](https://dl.acm.org/doi/10.1145/1314690.1314692), though this doesn't necessarily specify any particular algorithm (only a blueprint for various algorithm_s_).

The immediate proposal here is confusing this with neural networks, though, and really needs to go back to the drawing board and take into better account existing algorithms and how they might be implemented. Also, I'm not sure why they're suggesting this be incorporated into the core language when I don't even see libraries being cited here (or cases where the language legitimately doesn't provide the facilities necessary to implement it).
