शाटन की कलनविधि

testwiki से
नेविगेशन पर जाएँ खोज पर जाएँ

कम्प्यूटर विज्ञान में उन कलनविधियों को अनुक्रमण कलनविधि (sorting algorithm) कहते हैं जो किसी सूची के अवयवों का मूल क्रम बदलकर किसी अन्य क्रमविशेष में व्यवस्थित करने के काम आतीं हैं। जैसे २, ७, ४, ५, ६ को अनुक्रमित करने पर २, ४, ५, ६, ७ मिलते हैं। दो प्रकार के क्रम सबसे अधिक प्रयुक्त होते हैं - संक्यात्मक क्रम (numerical order) तथा कोशक्रम (lexicographical order)। कम्प्यूटर प्रोग्रामों में अनुक्रमण का सम्भवतः सबसे अधिक उपयोग होता है। इसलिए दक्षतापूर्वक अनुक्रमण करने वाले अल्गोरिद्म बहुत महत्व रखते हैं। कुछ अन्य कलनविधियाँ तभी कार्य कर सकती हैं जब पहले आंक। दों को किसी क्रम में व्यवस्थित किया गया हो। उदाहरण के लिए खोजने (search algorithms) और विलय करने वाले (merge algorithms) अल्गोरिद्म (search and merge algorithms) ठीक से तभी काम करेंगे जब उनका उपयोग किसी अनुक्रमित सूची पर किया जाय।

कम्प्यूटरी के आरम्भ से ही अनुक्रमण के प्रश्न पर बहुत अधिक अनुसंधान होता आया है। यद्यपि अनुक्रमण का कार्य बहुत ही सरल कार्य है किन्तु जब किसी वृहद सूची को दक्षतापूर्वक अनुक्रमित करना हो तब यह एक जटिल समस्या बन जाती है।

प्रमुख विधियाँ

  • हीप अनुक्रमण (Heapsort) - यह चयन अनुक्रमण का ही एक रूप है जो अपेक्षाकृत बहुत दक्ष है।
  • द्रुत अनुक्रमण (Quicksort) - यह विभाजन द्वारा विजय (divide and conquer) पर आधारित अनुक्रमण अल्गोरिद्म है। यह सबसे तेज अनुक्रमण विधियों में से एक है।

अनुक्रमण विधियों की तुलना

E=mc^2

Comparison of algorithms

नीचे की सारणी में n अनुक्रमित किए जाने वाले रेकार्डों की संख्या है।

तुलना अनुक्रमण
विधि का नाम सर्वोत्तम मध्यम सबसे खराब
स्मृति (Memory) स्थायित्व विधि
टिप्पणी
द्रुत अनुक्रमण साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Depends Partitioning Quicksort is usually done in place with O(log(n)) stack space.साँचा:Citation needed Most implementations are unstable, as stable in-place partitioning is more complex. Naïve variants use an O(n) space array to store the partition.साँचा:Citation needed
Merge sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Merging Highly parallelizable (up to O(log(n))) for processing large amounts of data.
In-place Merge sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Merging Implemented in Standard Template Library (STL);[] can be implemented as a stable sort based on stable in-place merging.[]
Heapsort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Selection
Insertion sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Insertion O(n + d), where d is the number of inversions
Introsort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Partitioning & Selection Used in several STL implementations
Selection sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Selection Stable with O(n) extra space, for example using lists.[] Used to sort this table in Safari or other Webkit web browser.[]
Timsort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Insertion & Merging n comparisons when the data is already sorted or reverse sorted.
Shell sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Insertion
Bubble sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Exchanging Tiny code size
Binary tree sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Insertion When using a self-balancing binary search tree
Cycle sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Insertion In-place with theoretically optimal number of writes
Library sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Insertion
Patience sorting साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Insertion & Selection Finds all the longest increasing subsequences within O(n log n)
Smoothsort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Selection An adaptive sort - n comparisons when the data is already sorted, and 0 swaps.
Strand sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Selection
Tournament sort साँचा:Sort साँचा:Sort साँचा:Sort Selection
Cocktail sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Exchanging
Comb sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Exchanging Small code size
Gnome sort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes Exchanging Tiny code size
Bogosort साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort No Luck Randomly permute the array and check if sorted.
[] साँचा:Sort साँचा:Sort साँचा:Sort साँचा:Sort Yes
गैर-तुलना अनुक्रमण
Name Best Average Worst
Memory
Stable n << 2k Notes
Pigeonhole sort साँचा:Sort n+2k n+2k 2k Yes Yes
Bucket sort (uniform keys) साँचा:Sort n+k n2k nk Yes No Assumes uniform distribution of elements from the domain in the array.[]
Bucket sort (integer keys) साँचा:Sort n+r n+r n+r Yes Yes r is the range of numbers to be sorted. If r = 𝒪(n) then Avg RT = 𝒪(n)[]
Counting sort साँचा:Sort n+r n+r n+r Yes Yes r is the range of numbers to be sorted. If r = 𝒪(n) then Avg RT = 𝒪(n)[]
LSD Radix Sort साँचा:Sort nkd nkd n Yes No [][]
MSD Radix Sort साँचा:Sort nkd nkd n+kd2d Yes No Stable version uses an external array of size n to hold all of the bins
MSD Radix Sort साँचा:Sort nkd nkd kd2d No No In-Place. k / d recursion levels, 2d for count array
Spreadsort साँचा:Sort nkd n(ks+d) kd2d No No Asymptotics are based on the assumption that n << 2k, but the algorithm does not require this.

सन्दर्भ

इन्हें भी देखें

बाहरी कड़ियाँ

साँचा:Wikibooks साँचा:Wikibooks

साँचा:आधार