Date post: | 15-Jul-2015 |
Category: |
Technology |
Upload: | jehat-hassan |
View: | 215 times |
Download: | 9 times |
Queck Sort
Jehat Hassan
Serbast Hamid
Serhldan Salih
Walid Abduljabar
What is Quick Sort ??
Ranking manner Quick Sort is the most widely used of all the
other sorting algorithms because they are faster and consume
less memory.
It is superior to (bubble sort) and (insertion sort) and (selection
sort) speed and distinct from (merge sort) speed and available
memory in spite of the latter outweigh the three counterparts,
but he also quickly consumes more memory.
What is Quick Sort ??
Division here is to divide the list into two smaller and larger where there is a so-called (pivot) and it is determined smaller or larger is not required to be a number of elements in both sections of equal or arranged in ascending or descending order, but what is important in the partitioning phase is to make the smallest of the axis division in the department and the largest in the last section.
What is Quick Sort ??
This algorithm is the order of the array at a rate of ( n*log n), where n is the step number of the elements of the array ..
Meaning:
If we have a array of the element 128, this will Khurazem Petrtaha in step 896 ..
And this number is very appropriate when compared to other ranking algorithms
For example, in Bubble sort algorithm will need to step 16384 in any way ..
What is Quick Sort ??
p
numbers less
than p
numbers greater than or
equal to p
p
Quick Sort
41 62 3513 28579684 79
Quick Sort
41 62 3513 28579684 79
Pivot = 41
Quick Sort
41 62 3513 28579684 79
Pivot = 41
i
Quick Sort
41 62 3513 28579684 79
Pivot = 41
i j
Quick Sort
41 62 3513 28579684 79
Pivot = 41
i j
41>79 ??
Quick Sort
41 62 3513 28579684 79
Pivot = 41
i j
41>79 ??
Fals
e
Quick Sort
41 62 3513 28579684
Pivot = 41
i j
j--
79
Quick Sort
41 62 3513 28579684
Pivot = 41
i j
79
41>28 ??
Quick Sort
41 62 3513 28579684
Pivot = 41
i j
79
41>28 ??
True
Quick Sort
41 62 3513 28579684
Pivot = 41
i j
79
Quick Sort
4162 351328 579684
Pivot = 41
i j
79
Pivot = j
Quick Sort
4162 351328 579684
Pivot = 41
i j
79
i++
Quick Sort
4162 351328 579684
Pivot = 41
i j
79
62>41 ??
Quick Sort
4162 351328 579684
Pivot = 41
i j
79
62>41 ??
True
Quick Sort
4162 351328 579684
Pivot = 41
i j
79
Quick Sort
41 351328 579684
Pivot = 41
i j
79
Pivot = i
62
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
j--
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
41>57 ??
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
41>57 ??
Fals
e
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
j--
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
41>96 ??
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
41>96 ??
Fals
e
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
j--
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
41>35 ??
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
41>35 ??
True
Quick Sort
41 351328 579684
Pivot = 41
i j
7962
Quick Sort
35 1328 579684
Pivot = 41
i j
796241
Pivot = j
Quick Sort
35 1328 579684
Pivot = 41
i j
796241
i++
Quick Sort
35 1328 579684
Pivot = 41
i j
796241
13>41 ??
Quick Sort
35 1328 579684
Pivot = 41
i j
796241
13>41 ??
Fals
e
Quick Sort
35 1328 579684
Pivot = 41
i j
796241
i++
Quick Sort
35 1328 579684
Pivot = 41
i j
796241
84>41 ??
Quick Sort
35 1328 579684
Pivot = 41
i j
796241
Quick Sort
35 1328 5796
Pivot = 41
i j
796241 84
Quick Sort
35 1328 5796
Pivot = 41
i j
796241 84
j++
Quick Sort
35 1328 5796
Pivot = 41
i j
796241 84
i=j
Quick Sort
35 1328 5796
Pivot = 41
796241 84
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]
a[8]
Quick Sort
35 1328 5796
Pivot = 41
796241 84
a[0] a[1] a[2]
Quick Sort
35 1328 5796
Pivot = 41
796241 84
a[0] a[1] a[2] a[0] a[1] a[2] a[3] a[4]
Quick Sort
35 1328 5796 796241 84
a[0] a[1] a[2] a[0] a[0] a[1] a[2] a[3]
a[4]
numbers less than p numbers greater than or equal to p
Quick Sort
35 1328
5796 796241 84
Now we sort numbers less than p
Quick Sort
35 1328
5796 796241 84
Pivot = 28
Quick Sort
5796 796241 84
Pivot = 28
i
35 1328
Quick Sort
35 1328
5796 796241 84Pivot = 28
i j
Quick Sort
35 1328
5796 796241 84Pivot = 28
i j
28>13 ??
Quick Sort
35 1328
5796 796241 84Pivot = 28
i j
28>13 ??
True
Quick Sort
35 1328
5796 796241 84Pivot = 28
i j
Quick Sort
3513
5796 796241 84Pivot = 28
i j
28
Pivot = j
Quick Sort
3513
5796 796241 84Pivot = 28
i j
28
i++
Quick Sort
3513
5796 796241 84Pivot = 28
i j
28
35>28 ??
True
Quick Sort
3513
5796 796241 84Pivot = 28
i j
28
Quick Sort
13
5796 796241 84Pivot = 28
i j
28 35
Quick Sort
13
5796 796241 84
28 35
a[0] a[0]
a[0]
Quick Sort
13
5796 7962
41
84
28 35
Now we sort numbers greater than or equal
to p
Quick Sort
13
5796 7962
41
84
28 35
a[0] a[1] a[2] a[3]
a[4]
Quick Sort
13
5796 7962
41
84
28 35
Pivot = 84
Quick Sort
13
5796 7962
41
84
28 35
i=84 j=79
i j
Quick Sort
13
5796 7962
41
84
28 35
i j
84>79 ??
Quick Sort
13
5796 7962
41
84
28 35
i j
84>79 ??
True
Quick Sort
13
5796 7962
41
84
28 35
i j
Quick Sort
13
579679 62
41
84
28 35
i j
Quick Sort
13
579679 62
41
84
28 35
i j
Quick Sort
13
579679 62
41
84
28 35
i j
i=96
Quick Sort
13
579679 62
41
84
28 35
i j
96>84 ??
Quick Sort
13
579679 62
41
84
28 35
i j
96>84 ??
True
Quick Sort
13
579679 62
41
84
28 35
i j
Quick Sort
13
5779 62
41
84
28 35
i j
96
Quick Sort
13
5779 62
41
84
28 35
i j
96
j--
Quick Sort
13
5779 62
41
84
28 35
i j
96
84>62 ??
Quick Sort
13
5779 62
41
84
28 35
i j
96
84>62 ??
True
Quick Sort
13
5779 62
41
84
28 35
i j
96
Quick Sort
13
5779 62
4128 35
i j
9684
Quick Sort
13
5779 62
4128 35
i j
9684
i++
Quick Sort
13
5779 62
4128 35
i j
9684
57>84 ??
Quick Sort
13
5779 62
4128 35
i j
9684
57>84 ??
Fals
e
Quick Sort
13
5779 62
4128 35
i j
9684
Quick Sort
13
5779 62
4128 35
i j
9684
i++
Quick Sort
13
5779 62
4128 35
i j
9684
i=j
Quick Sort
13
5779 62
4128 35
i j
9684
a[0] a[1] a[2] a[0] a[0]
Quick Sort
13
5779 62
4128 35
9684
a[0] a[1] a[2] a[0] a[0]
numbers less than pnumbers greater
than or equal to
p
Quick Sort
13
5779 62
4128 35
96
84
Quick Sort
13 5779 624128 35
96
84
Now we sort numbers greater than or equal to p
Quick Sort
13 5779 624128 35
96
84
i j
i=j=96
Quick Sort
13
5779 62
4128 35 9684
Now we sort numbers less than p
Quick Sort
13
5779 62
4128 35 9684
i j
Pivot = 79
Quick Sort
13
5779 62
4128 35 9684
i j
79>57 ??
Quick Sort
13
5779 62
4128 35 9684
i j
79>57 ??
True
Quick Sort
13
5779 62
4128 35 9684
i j
Quick Sort
13
62
4128 35 9684
i j
7957
Quick Sort
13
62
4128 35 9684
i j
7957
i++
Quick Sort
13
62
4128 35 9684
i j
7957
62>79 ??
Quick Sort
13
62
4128 35 9684
i j
7957
62>79 ??
Fals
e
Quick Sort
13
62
4128 35 9684
i j
7957
i++
Quick Sort
13
62
4128 35 9684
i j
7957
i=j
Quick Sort
13
62
4128 35 9684
7957
a[0] a[1]
a[0]
Quick Sort
13
62
4128 35 9684
7957
a[0] a[1]
a[0]
numbers less than p
Quick Sort
13
62
4128 35 968479
57
Quick Sort
13
62
4128 35 968479
57
Now we sort numbers less than p
Quick Sort
13
62
4128 35 968479
57
i=84 j=79
Pivot = 84
i j
Quick Sort
13
62
4128 35 968479
57
i j
57>62 ??
False
Quick Sort
13
62
4128 35 968479
57
i j
j--
Quick Sort
13
62
4128 35 968479
57
i j
i=j
Quick Sort
13
62
4128 35 968479
57
numbers greater
than or equal to p
Quick Sort
13
62
4128 35 96847957
Now we sort numbers greater than or equal to p
Quick Sort
13
62
4128 35 96847957
i=79 j=79
Pivot = 79
i j
Quick Sort
13
62
4128 35 96847957
i j
i=j
Quick Sort
13
62
4128 35 96847957
Quick Sort
13 624128 35 96847957
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]
a[8]
Do you
understand
Quick Sort ?
If you do not understand.........
See this video.....
And do not laugh ;)
لماذا أسلوب الفرز السريع ؟
وأقل الترتيب بأسلوب الفرز السريع يعتبر األكثر استخداما من جميع خوارزميات الفرز األخرى ألنها األسرع.استهالكا للذاكرة
و الفرز بأسلوب (insertion sort)و الفرز بأسلوب اإلدخال (bubble sort)إذ هي تتفوق على الفرز بأسلوب الفقاعةselection sort)االختيار بالسرعة وتوفيرها للذاكرة بالرغم (merge sort)بالسرعة وتتميز عن الفرز بأسلوب الدمج (
.من تفوق األخير على نظرائه الثالثة بالسرعة أيضا إال انه يستهلك الذاكرة أكثر
partitioningالتقسيم :
خل على تقسيم المقسم وتجزئة المجزأ لعدة مرات حتى تحصل على ترتيب للعناصر داQuicksortيعتمد أسلوب.القائمة تصاعديا أو تنازليا
pivot)التقسيم هنا هو تقسيم قائمة إلى جزأين أصغر وأكبر حيث هناك يكون مايسمى محور التقسيم وعليها يتم (ديا أو تنازليا بل تحديد أصغر أو أكبر ال يشترط أن تكون عدد العناصر في كال القسمين متساوية أو مرتبة ترتيبا تصاع
.ما هو مهم في مرحلة التقسيم هو جعل األصغر من محور التقسيم في قسم واألكبر في قسم آخر
درجة حيث 50درجة والحاصلين على أكثر من 50تقسيم درجات الطالب الحاصلين على أقل من مثال على ذلك.هو محور التقسيم 50القيمة
------------------------------------------..هي عدد عناصر المصفوفة nخطوة حيث n log nيقوم هذا الخوارزم بترتيب المصفوفة بمعدل
: بمعنى
..خطوة 896عنصر فإن هذا الخورازم سيقوم بترتيها في 128إذا كان لدينا مصفوفة بها
و يعتبر هذا العدد مناسبا جدا إذا ما قورن ب خوارزميات الترتيب األخرى
..خطوة في بأي حال من األحوال 16384سنحتاج إلى Bubble sortفعلى سبيل المثال في خوارزم