User Tools

Site Tools


library_sort

Library sort

Return to List of Algorithms, Algorithms

Also called gapped insertion sort

Snippet from Wikipedia: Library sort

Library sort or gapped insertion sort is a sorting algorithm that uses an insertion sort, but with gaps in the array to accelerate subsequent insertions. The name comes from an analogy:

Suppose a librarian were to store their books alphabetically on a long shelf, starting with the As at the left end, and continuing to the right along the shelf with no spaces between the books until the end of the Zs. If the librarian acquired a new book that belongs to the B section, once they find the correct space in the B section, they will have to move every book over, from the middle of the Bs all the way down to the Zs in order to make room for the new book. This is an insertion sort. However, if they were to leave a space after every letter, as long as there was still space after B, they would only have to move a few books to make room for the new one. This is the basic principle of the Library Sort.

The algorithm was proposed by Michael A. Bender, Martín Farach-Colton, and Miguel Mosteiro in 2004 and was published in 2006.

Like the insertion sort it is based on, library sort is a comparison sort; however, it was shown to have a high probability of running in O(n log n) time (comparable to quicksort), rather than an insertion sort's O(n2). There is no full implementation given in the paper, nor the exact algorithms of important parts, such as insertion and rebalancing. Further information would be needed to discuss how the efficiency of library sort compares to that of other sorting methods in reality.

Compared to basic insertion sort, the drawback of library sort is that it requires extra space for the gaps. The amount and distribution of that space would depend on implementation. In the paper the size of the needed array is (1 + ε)n, but with no further recommendations on how to choose ε. Moreover, it is neither adaptive nor stable. In order to warrant the high-probability time bounds, it must randomly permute the input, which changes the relative order of equal elements and shuffles any presorted input. Also, the algorithm uses binary search to find the insertion point for each element, which does not take advantage of presorted input.

Another drawback is that it cannot be run as an online algorithm, because it is not possible to randomly shuffle the input. If used without this shuffling, it could easily degenerate into quadratic behaviour.

One weakness of insertion sort is that it may require a high number of swap operations and be costly if memory write is expensive. Library sort may improve that somewhat in the insertion step, as fewer elements need to move to make room, but also adds an extra cost in the rebalancing step. In addition, locality of reference will be poor compared to mergesort, as each insertion from a random data set may access memory that is no longer in cache, especially with large data sets.

Algorithms: Big O Notation, Iterative method Chase algorithm, Grokking Algorithms, Edsger Dijkstra, Donald Knuth: The Art of Computer Programming (TAOCP), Analysis of algorithms. Algorithms GitHub. (navbar_algorithms)

navbar_Algorithms

Algorithms: Algorithms Fundamentals, Algorithms Inventor: Algorithms Language Designer: ZZZ on DATE, YEAR; Algorithms DevOps - Algorithms SRE, Cloud Native Algorithms (Algorithms on Kubernetes - Algorithms on AWS - Algorithms on Azure - Algorithms on GCP), Algorithms Microservices, Algorithms Containerization (Algorithms Docker - Algorithms on Docker Hub), Serverless Algorithms, Algorithms Data Science - Algorithms DataOps - Algorithms and Databases (Algorithms ORM), Algorithms ML - Algorithms DL, Functional Algorithms (1. Algorithms Immutability, 2. Algorithms Purity - Algorithms No Side-Effects, 3. Algorithms First-Class Functions - Algorithms Higher-Order Functions, Algorithms Lambdas - Algorithms Anonymous Functions - Algorithms Closures, Algorithms Lazy Evaluation, 4. Algorithms Recursion), Reactive Algorithms), Algorithms Concurrency - Algorithms Parallel Programming - Async Algorithms, Algorithms Networking, Algorithms Security - Algorithms DevSecOps - Algorithms OAuth, Algorithms Memory Allocation (Algorithms Heap - Algorithms Stack - Algorithms Garbage Collection), Algorithms CI/CD - Algorithms Dependency Management - Algorithms DI - Algorithms IoC - Algorithms Build Pipeline, Algorithms Automation - Algorithms Scripting, Algorithms Package Managers, Algorithms Modules - Algorithms Packages, Algorithms Installation (Algorithms Windows - Chocolatey Algorithms, Algorithms macOS - Homebrew Algorithms, Algorithms on Linux), Algorithms Configuration, Algorithms Observability (Algorithms Monitoring, Algorithms Performance - Algorithms Logging), Algorithms Language Spec - Algorithms RFCs - Algorithms Roadmap, Algorithms Keywords, Algorithms Operators, Algorithms Functions, Algorithms Data Structures - Algorithms Algorithms, Algorithms Syntax, Algorithms OOP (1. Algorithms Encapsulation - 2. Algorithms Inheritance - 3. Algorithms Polymorphism - 4. Algorithms Abstraction), Algorithms Design Patterns - Algorithms Best Practices - Algorithms Style Guide - Clean Algorithms - Algorithms BDD, Algorithms Generics, Algorithms I/O, Algorithms Serialization - Algorithms Deserialization, Algorithms APIs, Algorithms REST - Algorithms JSON - Algorithms GraphQL, Algorithms gRPC, Algorithms Virtualization, Algorithms Development Tools: Algorithms SDK, Algorithms Compiler - Algorithms Transpiler, Algorithms Interpreter - Algorithms REPL, Algorithms IDEs (JetBrains Algorithms, Algorithms Visual Studio Code), Algorithms Linter, Algorithms Community - Algorithmsaceans - Algorithms User, Algorithms Standard Library - Algorithms Libraries - Algorithms Frameworks, Algorithms Testing - Algorithms TDD, Algorithms History, Algorithms Research, Algorithms Topics, Algorithms Uses - List of Algorithms Software - Written in Algorithms - Algorithms Popularity, Algorithms Bibliography - Algorithms Courses, Algorithms Glossary - Algorithms Official Glossary, Algorithms GitHub, Awesome Algorithms. (navbar_Algorithms)


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


library_sort.txt · Last modified: 2024/04/28 03:44 (external edit)