P-group: Difference between revisions
en>Headbomb m Various citation cleanup + AWB fixes using AWB (8062) |
en>Wikfr m more specific |
||
Line 1: | Line 1: | ||
{{Infobox Algorithm | |||
|class=[[Sorting algorithm]] | |||
|image= | |||
|data=[[Array data structure|Array]] | |||
|time=<math>O(N+n)</math>, where ''N'' is the range of key values and ''n'' is the input size | |||
|space=<math>O(N+n)</math> | |||
|optimal=If and only if <math>N=O(n)</math> | |||
}} | |||
'''Pigeonhole sorting''', also known as '''count sort''' (not to be confused with [[counting sort]]), is a [[sorting algorithm]] that is suitable for sorting lists of elements where the number of elements (''n'') and the number of possible key values (''N'') are approximately the same.<ref>[http://www.nist.gov/dads/HTML/pigeonholeSort.html NIST's Dictionary of Algorithms and Data Structures: pigeonhole sort]</ref> It requires [[big O notation|O]](''n'' + ''N'') time. | |||
The pigeonhole algorithm works as follows: | |||
# Given an array of values to be sorted, set up an auxiliary array of initially empty "pigeonholes," one pigeonhole for each key through the [[Range_(computer_science)|range]] of the original array. | |||
# Going over the original array, put each value into the pigeonhole corresponding to its key, such that each pigeonhole eventually contains a list of all values with that key. | |||
# Iterate over the pigeonhole array in order, and put elements from non-empty pigeonholes back into the original array. | |||
==Example== | |||
Suppose we were sorting these value pairs by their first element: | |||
* (5, "hello") | |||
* (3, "pie") | |||
* (8, "apple") | |||
* (5, "king") | |||
For each value between 3 and 8 we set up a pigeonhole, then move each element to its pigeonhole: | |||
* 3: (3, "pie") | |||
* 4: | |||
* 5: (5, "hello"), (5, "king") | |||
* 6: | |||
* 7: | |||
* 8: (8, "apple") | |||
We then iterate over the pigeonhole array in order and move them back to the original list. | |||
The difference between pigeonhole sort and counting sort is that in counting sort, the auxiliary array does not contain lists of input elements, only counts: | |||
* 3: 1 | |||
* 4: 0 | |||
* 5: 2 | |||
* 6: 0 | |||
* 7: 0 | |||
* 8: 1 | |||
Using this information we can perform a series of exchanges on the input array that puts it in order, moving items only once. Pigeonhole sort, in contrast, moves items twice: once onto the pigeonhole/bucket array and again onto the destination array. <ref>{{cite web| url=http://www.itl.nist.gov/div897/sqg/dads/HTML/pigeonholeSort.html| first=Paul E.| last=Black| title="pigeonhole sort", in Dictionary of Algorithms and Data Structures [online]| publisher=U.S. National Institute of Standards and Technology| date=2006-06-19| accessdate=2009-04-26}}</ref> | |||
For arrays where ''N'' is much larger than ''n'', [[bucket sort]] is a generalization that is more efficient in space and time. | |||
== See also == | |||
* [[Pigeonhole principle]] | |||
* [[Radix sort]] | |||
== References == | |||
<references /> | |||
{{Wikibooks|Algorithm implementation|Sorting/Pigeonhole sort|Pigeonhole sort}} | |||
{{sorting}} | |||
[[Category:Sorting algorithms]] | |||
[[Category:Stable sorts]] | |||
[[ru:Сортировка подсчётом#Алгоритм со списком]] |
Revision as of 23:33, 18 December 2013
Template:Infobox Algorithm Pigeonhole sorting, also known as count sort (not to be confused with counting sort), is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the number of possible key values (N) are approximately the same.[1] It requires O(n + N) time.
The pigeonhole algorithm works as follows:
- Given an array of values to be sorted, set up an auxiliary array of initially empty "pigeonholes," one pigeonhole for each key through the range of the original array.
- Going over the original array, put each value into the pigeonhole corresponding to its key, such that each pigeonhole eventually contains a list of all values with that key.
- Iterate over the pigeonhole array in order, and put elements from non-empty pigeonholes back into the original array.
Example
Suppose we were sorting these value pairs by their first element:
- (5, "hello")
- (3, "pie")
- (8, "apple")
- (5, "king")
For each value between 3 and 8 we set up a pigeonhole, then move each element to its pigeonhole:
- 3: (3, "pie")
- 4:
- 5: (5, "hello"), (5, "king")
- 6:
- 7:
- 8: (8, "apple")
We then iterate over the pigeonhole array in order and move them back to the original list.
The difference between pigeonhole sort and counting sort is that in counting sort, the auxiliary array does not contain lists of input elements, only counts:
- 3: 1
- 4: 0
- 5: 2
- 6: 0
- 7: 0
- 8: 1
Using this information we can perform a series of exchanges on the input array that puts it in order, moving items only once. Pigeonhole sort, in contrast, moves items twice: once onto the pigeonhole/bucket array and again onto the destination array. [2]
For arrays where N is much larger than n, bucket sort is a generalization that is more efficient in space and time.
See also
References
DTZ's auction group in Singapore auctions all types of residential, workplace and retail properties, retailers, homes, accommodations, boarding houses, industrial buildings and development websites. Auctions are at the moment held as soon as a month.
Whitehaven @ Pasir Panjang – A boutique improvement nicely nestled peacefully in serene Pasir Panjang personal estate presenting a hundred and twenty rare freehold private apartments tastefully designed by the famend Ong & Ong Architect. Only a short drive away from Science Park and NUS Campus, Jade Residences, a recent Freehold condominium which offers high quality lifestyle with wonderful facilities and conveniences proper at its door steps. Its fashionable linear architectural fashion promotes peace and tranquility living nestled within the D19 personal housing enclave. Rising workplace sector leads real estate market efficiency, while prime retail and enterprise park segments moderate and residential sector continues in decline International Market Perspectives - 1st Quarter 2014
There are a lot of websites out there stating to be one of the best seek for propertycondominiumhouse, and likewise some ways to discover a low cost propertycondominiumhouse. Owning a propertycondominiumhouse in Singapore is the dream of virtually all individuals in Singapore, It is likely one of the large choice we make in a lifetime. Even if you happen to're new to Property listing singapore funding, we are right here that will help you in making the best resolution to purchase a propertycondominiumhouse at the least expensive value.
Jun 18 ROCHESTER in MIXED USE IMPROVEMENT $1338000 / 1br - 861ft² - (THE ROCHESTER CLOSE TO NORTH BUONA VISTA RD) pic real property - by broker Jun 18 MIXED USE IMPROVEMENT @ ROCHESTER @ ROCHESTER PK $1880000 / 1br - 1281ft² - (ROCHESTER CLOSE TO NORTH BUONA VISTA) pic real estate - by broker Tue 17 Jun Jun 17 Sunny Artwork Deco Gem Near Seashore-Super Deal!!! $103600 / 2br - 980ft² - (Ventnor) pic actual estate - by owner Jun 17 Freehold semi-d for rent (Jalan Rebana ) $7000000 / 5909ft² - (Jalan Rebana ) actual property - by dealer Jun sixteen Ascent @ 456 in D12 (456 Balestier Highway,Singapore) pic real property - by proprietor Jun 16 RETAIL SHOP AT SIM LIM SQUARE FOR SALE, IT MALL, ROCHOR, BUGIS MRT $2000000 / 506ft² - (ROCHOR, BUGIS MRT) pic real estate - by dealer HDB Scheme Any DBSS BTO
In case you are eligible to purchase landed houses (open solely to Singapore residents) it is without doubt one of the best property investment choices. Landed housing varieties solely a small fraction of available residential property in Singapore, due to shortage of land right here. In the long term it should hold its worth and appreciate as the supply is small. In truth, landed housing costs have risen the most, having doubled within the last eight years or so. However he got here back the following day with two suitcases full of money. Typically we've got to clarify to such folks that there are rules and paperwork in Singapore and you can't just buy a home like that,' she said. For conveyancing matters there shall be a recommendedLondon Regulation agency familiar with Singapore London propertyinvestors to symbolize you
Sales transaction volumes have been expected to hit four,000 units for 2012, close to the mixed EC gross sales volume in 2010 and 2011, in accordance with Savills Singapore. Nevertheless the last quarter was weak. In Q4 2012, sales transactions were 22.8% down q-q to 7,931 units, in line with the URA. The quarterly sales discount was felt throughout the board. When the sale just starts, I am not in a hurry to buy. It's completely different from a private sale open for privileged clients for one day solely. Orchard / Holland (D09-10) House For Sale The Tembusu is a singular large freehold land outdoors the central area. Designed by multiple award-profitable architects Arc Studio Architecture + Urbanism, the event is targeted for launch in mid 2013. Post your Property Condos Close to MRT
Template:Sorting