{"id":16758115,"url":"https://github.com/foo123/sortingalgorithms","last_synced_at":"2025-08-10T03:32:42.569Z","repository":{"id":11508565,"uuid":"13988016","full_name":"foo123/SortingAlgorithms","owner":"foo123","description":"Sorting Algorithms implementations in JavaScript","archived":false,"fork":false,"pushed_at":"2024-07-23T13:19:27.000Z","size":259,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T17:33:59.027Z","etag":null,"topics":["analysis","complexity","sorting-algorithms","sorting-algorithms-implemented"],"latest_commit_sha":null,"homepage":"https://foo123.github.io/examples/sorting-algorithms/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foo123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-30T13:55:38.000Z","updated_at":"2024-07-23T13:19:30.000Z","dependencies_parsed_at":"2025-02-17T16:46:37.264Z","dependency_job_id":null,"html_url":"https://github.com/foo123/SortingAlgorithms","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/foo123/SortingAlgorithms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FSortingAlgorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FSortingAlgorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FSortingAlgorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FSortingAlgorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foo123","download_url":"https://codeload.github.com/foo123/SortingAlgorithms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FSortingAlgorithms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269672003,"owners_count":24457110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analysis","complexity","sorting-algorithms","sorting-algorithms-implemented"],"created_at":"2024-10-13T04:04:11.596Z","updated_at":"2025-08-10T03:32:41.898Z","avatar_url":"https://github.com/foo123.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Sorting Algorithms\n===================\n\n![sort.js](/sort.jpg)\n\n\n__Various sorting algorithms implementations in JavaScript__\n\n\n[sort.min.js](https://raw.githubusercontent.com/foo123/SortingAlgorithms/master/test/js/sort.min.js)\n\n\n[![screenshot](/test/screenshot.png)](https://foo123.github.io/examples/sorting-algorithms/)\n\n\n* [Live Playground Example](https://foo123.github.io/examples/sorting-algorithms/)\n\n\nSorting Series, which is also a **kind of discrete optimization problem** (eg the permutation function `perm` of `0..N-1` which **maximizes** `0*a[perm[0]]+1*a[perm[1]]+..+(N-1)*a[perm[N-1]]` is the **permutation which sorts the array `a` in ascending order** that is `a[perm[0]] \u003c= a[perm[1]] \u003c= .. \u003c= a[perm[N-1]]`); lies at the center of Computer Science and Algorithms because of its many uses.\n\n(Ref. [Sorting Algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm))\n\nFurthermore Sorting, in one way or another, is integral part of many other important algorithms and applications (see eg. Knuth *The Art Of Computer Programming*)\n\nFor example Sorting is very closely associated to Searching, another topic of immense importance and applications.\n\nUnder certain sorting states, searching can be achieved in `O(logN)` time or even in `O(1)` time (constant) for almost every search term.\n\nSorting has 3 approaches:\n\n(eg. NIST.gov maintains a dictionary of various algorithms at:  http://xlinux.nist.gov/dads// )\n\n\n### Block vs. Online/Adaptive:\n\n1. In the Block case, the whole array is available at once\nfor this case many algorithms are known (comparison-based =\u003e `O(N^2)`, `O(NlogN)` complexities) and (number/count based =\u003e `O(N)` complexity) (see below)\n\n2. In the Adaptive/Online case, the input series is\naccesed one at a time (for example an time-input signal). In this case some of the previous algorithms can be transformed to work adaptively\n\n    Apart from that, there are algorithms (like Dynamic Lists, Dynamic Heaps and Balanced Trees, Tries, eg AVL Trees) which keep an input sequence always in a 'sorted' state (with each new input) with relatively low complexity (eg `O(logN)`).\n\n\n### Comparison-Based vs. Arithmetic/Count-Based:\n\n* Comparison-based sorting algorithms (InsertionSort, MergeSort, QuickSort, etc..) sort a series by comparing elements with each other in some optimum sense\n\n    The best time complexity of these algorithms is `O(NlogN)`.  \n    However better than this can be achieved   \n\n* Statistics-based sorting algorithms (CountingSort, BucketSort, RadixSort, etc..), do not use comparisons (of any kind) between elements, but instead use their arithmetic/statistical properties\n\n    This makes possible algorithms which can sort in linear `O(N)` time (the fastest possible).   \n    However these algorithms have some limitations (eg only Integers, or special kinds of Numbers). \n\n\n\u003e Is `O(N)` sorting possible for arbitrary random numbers??\n\n\nComputing the value of a certain number `n` (in a fixed type of encoding, eg `decimal-place`) requires approximately `O(logn)` *\"primitive digit\"* operations. Since, statistically, the **range of values of numbers in a list of given size is increasingly correlated to the size of the list as the size of the list increases** (i.e lists of size `N` containing random numbers with values over the whole range `0..N` have increasingly greater probability, as `N` increases, over all lists of same size `N`, containing random numbers whose values do not cover the whole range `0..N`), one then has an overall complexity of `O(NlogN)` even for arithmetic-based sorting algorithms.  \n\nSee for example *\"what is the true complexity of radix sort?\"*.\n\n\u003e Classical algorithms for integer sorting require **assumptions about the size of the integers** to be sorted, or else have a **running time dependent on the size**.\n\n-- [*Sorting in Linear Time?* Arne Andersson, Torben Hagerupt, Stefan Nilsson, Rajeev Ramam](https://www.cs.unc.edu/~plaisted/comp550/linear%20time%20sorting.pdf)\n\nHowever the *catch* here is that same holds for comparing arbitrary numbers, computationaly one has to compare `primitive digit` by `primitive digit` in sequence on average, hence an additional `O(logn)` complexity for comparison-based algorithms, over the `O(NlogN)` bound.\n\n\n\u003e Is `O(NlogN)` complexity a kind of *strict base line* for this computational model??\n\nAccording to Knuth's theoretical lower bound theorem for general (comparison) sorting algorithms (note `O(logN!) = O(NlogN)`): the `O(NlogN)` bound is asymptoticaly tight (see also [information-theoretic lower bound for comparison sorts](https://www.inf.fh-flensburg.de/lang/algorithmen/sortieren/lowerbounden.htm) is \u0026Omega;(NlogN) ).\n\n\nA summary of various sorting and searching algorithms can be found in [*SORTING AND SEARCHING ALGORITHMS*, Tom Niemann (pdf)](https://www.epaperpress.com/sortsearch/download/sortsearch.pdf)\n\n\n**Included Algorithms**\n\n* Builtin (JavaScript's default sorting algorithm)\n* [Bubble Sort](http://en.wikipedia.org/wiki/Bubble_sort)\n* [Cocktail Sort](http://en.wikipedia.org/wiki/Cocktail_shaker_sort)\n* [Cycle Sort](http://en.wikipedia.org/wiki/Cycle_sort)\n* [Heap Sort](http://en.wikipedia.org/wiki/Heap_sort)\n* [Insertion Sort](http://en.wikipedia.org/wiki/Insertion_sort)\n* [Library Sort](http://en.wikipedia.org/wiki/Library_sort)\n* [Shell Sort](http://en.wikipedia.org/wiki/Shellsort)\n* [Quick Sort](http://en.wikipedia.org/wiki/Quicksort) (**recursive \u0026amp; iterative**)\n* [Tree Sort](http://en.wikipedia.org/wiki/Tree_sort)\n* [Merge Sort](http://en.wikipedia.org/wiki/Merge_sort) (**recursive, iterative \u0026amp; natural TODO: in-place `O(1)` extra space version**)\n* [Counting Sort](http://en.wikipedia.org/wiki/Counting_sort)\n* [Bucket Sort](http://en.wikipedia.org/wiki/Bucket_sort)\n* [Radix Sort](http://en.wikipedia.org/wiki/Radix_sort) (**not implemented yet**)\n* [Intro Sort](https://en.wikipedia.org/wiki/Introsort) (**not implemented yet**)\n* [Burst Sort](http://en.wikipedia.org/wiki/Burstsort) (**not implemented yet**)\n* [Tim Sort](http://en.wikipedia.org/wiki/Timsort) (**not implemented yet**)\n* Permutation Sort (**custom**)\n* Index Sort (**custom**)\n* Statistical Sort (**custom, in progress**)\n\n\n------------------------------------------------------\n\nNOTE: The calculation of asymptotic complexity is done usually (using recursive relations)\nwith the Master Theorem :\n\nRefs.\n        http://en.wikipedia.org/wiki/Master_theorem,\n        http://en.wikipedia.org/wiki/Introduction_to_Algorithms\n\n\nT(n) = aT(n/b) + f(n),  a\u003e=1, b\u003e1\n\neg. for MergeSort =\u003e T(n) = 2T(n/2) + O(n) =\u003e  T(n) = O(nlogn)\n\n\n---------------------------------------------------------\n\nThis package implements showcases of various (best known) sorting algorithms\n(and a couple of custom ones)\nfor study, experimentation and use in applications\nIn a concice library\n\n\n\u003e __Algorithms as a technology__   Suppose computers were infinitely fast and memory was free. Would you have any reason to study algorithms? The answer is yes, if for no other reason than that you would  still like to demonstrate that your solution method terminates and does so with the correct answer.  ...Of course, computers may be fast but not infinitely fast and memory may be cheap but not completely free. Computing time is therefore a  bounded resource, and so is space in memory. These resources should be used wisely and algorithms that are efficient in terms of time and space will help you do so.  This demostrates that algorithms, like computer hardware, are a __technology__ . Total system performance depends on choosing efficient algorithms as much as choosing fast hardware. Just as rapid advances are being made in other computer technologies, they are being made in algorithms as well. (__Introduction to algorithms, 2nd Ed. Cormen,Leiserson,Rivest,Stein__)\n\n\n\n\u003e __Algorithms as a ecological technology__     Additionaly, every operation/instruction a computer performs has an energy consumption cost. Thus an efficient algorithm saves energy!  An efficient algorithm performs a computation by trying to use the resources in the best possible manner, so effectively uses energy in the best possible manner.  Where does energy come from? It comes from burning coal or gas (mainly).  So there you have it; efficient code is ecological!  Better start learning your [complexity]( http://en.wikipedia.org/wiki/Computational_complexity_theory) soon.\n\n\n**see also:**\n\n* [Abacus](https://github.com/foo123/Abacus) advanced Combinatorics and Algebraic Number Theory Symbolic Computation library for JavaScript, Python\n* [Plot.js](https://github.com/foo123/Plot.js) simple and small library which can plot graphs of functions and various simple charts and can render to Canvas, SVG and plain HTML\n* [HAAR.js](https://github.com/foo123/HAAR.js) image feature detection based on Haar Cascades in JavaScript (Viola-Jones-Lienhart et al Algorithm)\n* [HAARPHP](https://github.com/foo123/HAARPHP) image feature detection based on Haar Cascades in PHP (Viola-Jones-Lienhart et al Algorithm)\n* [FILTER.js](https://github.com/foo123/FILTER.js) video and image processing and computer vision Library in pure JavaScript (browser and node)\n* [Xpresion](https://github.com/foo123/Xpresion) a simple and flexible eXpression parser engine (with custom functions and variables support), based on [GrammarTemplate](https://github.com/foo123/GrammarTemplate), for PHP, JavaScript, Python\n* [Regex Analyzer/Composer](https://github.com/foo123/RegexAnalyzer) Regular Expression Analyzer and Composer for PHP, JavaScript, Python\n* [GrammarTemplate](https://github.com/foo123/GrammarTemplate) grammar-based templating for PHP, JavaScript, Python\n* [codemirror-grammar](https://github.com/foo123/codemirror-grammar) transform a formal grammar in JSON format into a syntax-highlight parser for CodeMirror editor\n* [ace-grammar](https://github.com/foo123/ace-grammar) transform a formal grammar in JSON format into a syntax-highlight parser for ACE editor\n* [prism-grammar](https://github.com/foo123/prism-grammar) transform a formal grammar in JSON format into a syntax-highlighter for Prism code highlighter\n* [highlightjs-grammar](https://github.com/foo123/highlightjs-grammar) transform a formal grammar in JSON format into a syntax-highlight mode for Highlight.js code highlighter\n* [syntaxhighlighter-grammar](https://github.com/foo123/syntaxhighlighter-grammar) transform a formal grammar in JSON format to a highlight brush for SyntaxHighlighter code highlighter\n* [SortingAlgorithms](https://github.com/foo123/SortingAlgorithms) implementations of Sorting Algorithms in JavaScript\n* [PatternMatchingAlgorithms](https://github.com/foo123/PatternMatchingAlgorithms) implementations of Pattern Matching Algorithms in JavaScript\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo123%2Fsortingalgorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoo123%2Fsortingalgorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo123%2Fsortingalgorithms/lists"}