allalgorithms-python

Pigeonhole Sort

Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the length of the range of possible key values (N) are approximately the same. It requires O(n + N) time. It is similar to counting sort, but differs in that it “moves items twice: once to the bucket array and again to the final destination [whereas] counting sort builds an auxiliary array then uses the array to compute each item’s final destination and move the item there.”

Install

pip install allalgorithms

Usage

from allalgorithms.sorting import pigeonhole_sort

arr = [77, 2, 10, -2, 1, 7]

print(pigeonhole_sort(arr))
# -> [-2, 1, 2, 7, 10, 77]

API

pigeonhole_sort(array)

Returns a sorted array

Params:
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