مورد · دليل أو مقال
Counting Sort
ترتيب العدّ للمفاتيح الصحيحة الصغيرة، بما في ذلك لماذا يتجاوز الحد الأدنى لترتيبات المقارنة وكيف يرتبط بترتيب الأساس (radix) وترتيب الدلاء.
تمت المراجعة
افتح المصدر الأصلي: Counting Sort (يفتح الموقع الأصلي في علامة تبويب جديدة)أضِف إلى خريطة طريق
احتفظ بهذا المورد مع خريطة طريق تتبعها. يظهر موردًا إضافيًا خاصًا بك، فلا تتغير خطوات الخريطة ولا يُحتسب ضمن خطواتك المتتبَّعة.
لغة المحتوى الأصلي: الإنجليزية
In computer science, counting sort is an algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm. It operates by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each key value in the output sequence. Its running time is linear in the number of items and the difference between the maximum and minimum key values, so it is only suitable for direct use in situations where the variation in keys is not significantly greater than the number of items. However, it is often used as a subroutine in another sorting algorithm, radix sort, that can handle larger keys more efficiently. Because counting sort uses key values as indexes into an array, it is not a comparison sort, and the Ω(n log n) lower bound for comparison sorting does not apply to it. Bucket sort may be used for many of the same tasks as counting sort, with a similar time analysis; however, compared to counting sort, bucket sort requires linked lists, dynamic arrays or a large amount of preallocated memory to hold the sets of items within each bucket, whereas counting…
نظرة عامة من PrepKit
كتب محررو PrepKit هذه النظرة العامة وراجعوها اعتمادًا على المستودع المصدر. وهي ليست نصًا من المورد نفسه.
- مناسب لـ
- لا يحدد المصدر مستوى
- الشكل
- مرجع
ما الذي يغطيه
- لماذا ليس ترتيب مقارنة، ومتى يجعله مدى المفاتيح مناسبًا.
- ثلاث خطوات: عدّ مرات الظهور، وبناء الأعداد التراكمية، ووضع العناصر في مصفوفة المخرجات.
- جدول التعقيد: n + r للزمن والذاكرة، ومستقر، حيث r أكبر عدد.
كيف تستخدمه
نصيحة دراسية من PrepKit، وليست ادعاءً من المصدر.
رتّب [4, 2, 2, 8, 3, 3, 1] يدويًا عبر الخطوات الثلاث كلها، ثم برمجه وحافظ على استقراره.
النطاق والقيود
رسوم الخطوات صور مستضافة على مدونة خارجية. لا معالجة للأعداد السالبة ولا تمارين. توجد نسخة برتغالية مرتبطة بالصفحة.
الوصول والشكل
ملف README مجاني بالإنجليزية على GitHub في trekhleb/javascript-algorithms (ترخيص MIT).
راجعه PrepKit في 02/10/2026. إيداع مصدر المورد: 85293e3e2b88
أدلة هذه النظرة العامة
- src/algorithms/sorting/counting-sort/README.md
صفحات تتضمن هذا العنصر
اشترك في النشرة البريدية من PrepKit
اختيارية. لا تحتاج إليها لاستخدام PrepKit.