+ All Categories
Home > Technology > Quick sort

Quick sort

Date post: 15-Jul-2015
Category:
Upload: jehat-hassan
View: 215 times
Download: 9 times
Share this document with a friend
119
Queck Sort Jehat Hassan Serbast Hamid Serhldan Salih Walid Abduljabar
Transcript
Page 1: Quick sort

Queck Sort

Jehat Hassan

Serbast Hamid

Serhldan Salih

Walid Abduljabar

Page 2: Quick sort

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.

Page 3: Quick sort

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.

Page 4: Quick sort

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 ..

Page 5: Quick sort

What is Quick Sort ??

p

numbers less

than p

numbers greater than or

equal to p

p

Page 6: Quick sort

Quick Sort

41 62 3513 28579684 79

Page 7: Quick sort

Quick Sort

41 62 3513 28579684 79

Pivot = 41

Page 8: Quick sort

Quick Sort

41 62 3513 28579684 79

Pivot = 41

i

Page 9: Quick sort

Quick Sort

41 62 3513 28579684 79

Pivot = 41

i j

Page 10: Quick sort

Quick Sort

41 62 3513 28579684 79

Pivot = 41

i j

41>79 ??

Page 11: Quick sort

Quick Sort

41 62 3513 28579684 79

Pivot = 41

i j

41>79 ??

Fals

e

Page 12: Quick sort

Quick Sort

41 62 3513 28579684

Pivot = 41

i j

j--

79

Page 13: Quick sort

Quick Sort

41 62 3513 28579684

Pivot = 41

i j

79

41>28 ??

Page 14: Quick sort

Quick Sort

41 62 3513 28579684

Pivot = 41

i j

79

41>28 ??

True

Page 15: Quick sort

Quick Sort

41 62 3513 28579684

Pivot = 41

i j

79

Page 16: Quick sort

Quick Sort

4162 351328 579684

Pivot = 41

i j

79

Pivot = j

Page 17: Quick sort

Quick Sort

4162 351328 579684

Pivot = 41

i j

79

i++

Page 18: Quick sort

Quick Sort

4162 351328 579684

Pivot = 41

i j

79

62>41 ??

Page 19: Quick sort

Quick Sort

4162 351328 579684

Pivot = 41

i j

79

62>41 ??

True

Page 20: Quick sort

Quick Sort

4162 351328 579684

Pivot = 41

i j

79

Page 21: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

79

Pivot = i

62

Page 22: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

j--

Page 23: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

41>57 ??

Page 24: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

41>57 ??

Fals

e

Page 25: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

j--

Page 26: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

Page 27: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

41>96 ??

Page 28: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

41>96 ??

Fals

e

Page 29: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

j--

Page 30: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

Page 31: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

41>35 ??

Page 32: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

41>35 ??

True

Page 33: Quick sort

Quick Sort

41 351328 579684

Pivot = 41

i j

7962

Page 34: Quick sort

Quick Sort

35 1328 579684

Pivot = 41

i j

796241

Pivot = j

Page 35: Quick sort

Quick Sort

35 1328 579684

Pivot = 41

i j

796241

i++

Page 36: Quick sort

Quick Sort

35 1328 579684

Pivot = 41

i j

796241

13>41 ??

Page 37: Quick sort

Quick Sort

35 1328 579684

Pivot = 41

i j

796241

13>41 ??

Fals

e

Page 38: Quick sort

Quick Sort

35 1328 579684

Pivot = 41

i j

796241

i++

Page 39: Quick sort

Quick Sort

35 1328 579684

Pivot = 41

i j

796241

84>41 ??

Page 40: Quick sort

Quick Sort

35 1328 579684

Pivot = 41

i j

796241

Page 41: Quick sort

Quick Sort

35 1328 5796

Pivot = 41

i j

796241 84

Page 42: Quick sort

Quick Sort

35 1328 5796

Pivot = 41

i j

796241 84

j++

Page 43: Quick sort

Quick Sort

35 1328 5796

Pivot = 41

i j

796241 84

i=j

Page 44: Quick sort

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]

Page 45: Quick sort

Quick Sort

35 1328 5796

Pivot = 41

796241 84

a[0] a[1] a[2]

Page 46: Quick sort

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]

Page 47: Quick sort

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

Page 48: Quick sort

Quick Sort

35 1328

5796 796241 84

Now we sort numbers less than p

Page 49: Quick sort

Quick Sort

35 1328

5796 796241 84

Pivot = 28

Page 50: Quick sort

Quick Sort

5796 796241 84

Pivot = 28

i

35 1328

Page 51: Quick sort

Quick Sort

35 1328

5796 796241 84Pivot = 28

i j

Page 52: Quick sort

Quick Sort

35 1328

5796 796241 84Pivot = 28

i j

28>13 ??

Page 53: Quick sort

Quick Sort

35 1328

5796 796241 84Pivot = 28

i j

28>13 ??

True

Page 54: Quick sort

Quick Sort

35 1328

5796 796241 84Pivot = 28

i j

Page 55: Quick sort

Quick Sort

3513

5796 796241 84Pivot = 28

i j

28

Pivot = j

Page 56: Quick sort

Quick Sort

3513

5796 796241 84Pivot = 28

i j

28

i++

Page 57: Quick sort

Quick Sort

3513

5796 796241 84Pivot = 28

i j

28

35>28 ??

True

Page 58: Quick sort

Quick Sort

3513

5796 796241 84Pivot = 28

i j

28

Page 59: Quick sort

Quick Sort

13

5796 796241 84Pivot = 28

i j

28 35

Page 60: Quick sort

Quick Sort

13

5796 796241 84

28 35

a[0] a[0]

a[0]

Page 61: Quick sort

Quick Sort

13

5796 7962

41

84

28 35

Now we sort numbers greater than or equal

to p

Page 62: Quick sort

Quick Sort

13

5796 7962

41

84

28 35

a[0] a[1] a[2] a[3]

a[4]

Page 63: Quick sort

Quick Sort

13

5796 7962

41

84

28 35

Pivot = 84

Page 64: Quick sort

Quick Sort

13

5796 7962

41

84

28 35

i=84 j=79

i j

Page 65: Quick sort

Quick Sort

13

5796 7962

41

84

28 35

i j

84>79 ??

Page 66: Quick sort

Quick Sort

13

5796 7962

41

84

28 35

i j

84>79 ??

True

Page 67: Quick sort

Quick Sort

13

5796 7962

41

84

28 35

i j

Page 68: Quick sort

Quick Sort

13

579679 62

41

84

28 35

i j

Page 69: Quick sort

Quick Sort

13

579679 62

41

84

28 35

i j

Page 70: Quick sort

Quick Sort

13

579679 62

41

84

28 35

i j

i=96

Page 71: Quick sort

Quick Sort

13

579679 62

41

84

28 35

i j

96>84 ??

Page 72: Quick sort

Quick Sort

13

579679 62

41

84

28 35

i j

96>84 ??

True

Page 73: Quick sort

Quick Sort

13

579679 62

41

84

28 35

i j

Page 74: Quick sort

Quick Sort

13

5779 62

41

84

28 35

i j

96

Page 75: Quick sort

Quick Sort

13

5779 62

41

84

28 35

i j

96

j--

Page 76: Quick sort

Quick Sort

13

5779 62

41

84

28 35

i j

96

84>62 ??

Page 77: Quick sort

Quick Sort

13

5779 62

41

84

28 35

i j

96

84>62 ??

True

Page 78: Quick sort

Quick Sort

13

5779 62

41

84

28 35

i j

96

Page 79: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

Page 80: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

i++

Page 81: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

57>84 ??

Page 82: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

57>84 ??

Fals

e

Page 83: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

Page 84: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

i++

Page 85: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

i=j

Page 86: Quick sort

Quick Sort

13

5779 62

4128 35

i j

9684

a[0] a[1] a[2] a[0] a[0]

Page 87: Quick sort

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

Page 88: Quick sort

Quick Sort

13

5779 62

4128 35

96

84

Page 89: Quick sort

Quick Sort

13 5779 624128 35

96

84

Now we sort numbers greater than or equal to p

Page 90: Quick sort

Quick Sort

13 5779 624128 35

96

84

i j

i=j=96

Page 91: Quick sort

Quick Sort

13

5779 62

4128 35 9684

Now we sort numbers less than p

Page 92: Quick sort

Quick Sort

13

5779 62

4128 35 9684

i j

Pivot = 79

Page 93: Quick sort

Quick Sort

13

5779 62

4128 35 9684

i j

79>57 ??

Page 94: Quick sort

Quick Sort

13

5779 62

4128 35 9684

i j

79>57 ??

True

Page 95: Quick sort

Quick Sort

13

5779 62

4128 35 9684

i j

Page 96: Quick sort

Quick Sort

13

62

4128 35 9684

i j

7957

Page 97: Quick sort

Quick Sort

13

62

4128 35 9684

i j

7957

i++

Page 98: Quick sort

Quick Sort

13

62

4128 35 9684

i j

7957

62>79 ??

Page 99: Quick sort

Quick Sort

13

62

4128 35 9684

i j

7957

62>79 ??

Fals

e

Page 100: Quick sort

Quick Sort

13

62

4128 35 9684

i j

7957

i++

Page 101: Quick sort

Quick Sort

13

62

4128 35 9684

i j

7957

i=j

Page 102: Quick sort

Quick Sort

13

62

4128 35 9684

7957

a[0] a[1]

a[0]

Page 103: Quick sort

Quick Sort

13

62

4128 35 9684

7957

a[0] a[1]

a[0]

numbers less than p

Page 104: Quick sort

Quick Sort

13

62

4128 35 968479

57

Page 105: Quick sort

Quick Sort

13

62

4128 35 968479

57

Now we sort numbers less than p

Page 106: Quick sort

Quick Sort

13

62

4128 35 968479

57

i=84 j=79

Pivot = 84

i j

Page 107: Quick sort

Quick Sort

13

62

4128 35 968479

57

i j

57>62 ??

False

Page 108: Quick sort

Quick Sort

13

62

4128 35 968479

57

i j

j--

Page 109: Quick sort

Quick Sort

13

62

4128 35 968479

57

i j

i=j

Page 110: Quick sort

Quick Sort

13

62

4128 35 968479

57

numbers greater

than or equal to p

Page 111: Quick sort

Quick Sort

13

62

4128 35 96847957

Now we sort numbers greater than or equal to p

Page 112: Quick sort

Quick Sort

13

62

4128 35 96847957

i=79 j=79

Pivot = 79

i j

Page 113: Quick sort

Quick Sort

13

62

4128 35 96847957

i j

i=j

Page 114: Quick sort

Quick Sort

13

62

4128 35 96847957

Page 115: Quick sort

Quick Sort

13 624128 35 96847957

a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]

a[8]

Page 116: Quick sort

Do you

understand

Quick Sort ?

Page 117: Quick sort

If you do not understand.........

See this video.....

And do not laugh ;)

Page 118: Quick sort
Page 119: Quick sort

لماذا أسلوب الفرز السريع ؟

وأقل الترتيب بأسلوب الفرز السريع يعتبر األكثر استخداما من جميع خوارزميات الفرز األخرى ألنها األسرع.استهالكا للذاكرة

و الفرز بأسلوب (insertion sort)و الفرز بأسلوب اإلدخال (bubble sort)إذ هي تتفوق على الفرز بأسلوب الفقاعةselection sort)االختيار بالسرعة وتوفيرها للذاكرة بالرغم (merge sort)بالسرعة وتتميز عن الفرز بأسلوب الدمج (

.من تفوق األخير على نظرائه الثالثة بالسرعة أيضا إال انه يستهلك الذاكرة أكثر

partitioningالتقسيم :

خل على تقسيم المقسم وتجزئة المجزأ لعدة مرات حتى تحصل على ترتيب للعناصر داQuicksortيعتمد أسلوب.القائمة تصاعديا أو تنازليا

pivot)التقسيم هنا هو تقسيم قائمة إلى جزأين أصغر وأكبر حيث هناك يكون مايسمى محور التقسيم وعليها يتم (ديا أو تنازليا بل تحديد أصغر أو أكبر ال يشترط أن تكون عدد العناصر في كال القسمين متساوية أو مرتبة ترتيبا تصاع

.ما هو مهم في مرحلة التقسيم هو جعل األصغر من محور التقسيم في قسم واألكبر في قسم آخر

درجة حيث 50درجة والحاصلين على أكثر من 50تقسيم درجات الطالب الحاصلين على أقل من مثال على ذلك.هو محور التقسيم 50القيمة

------------------------------------------..هي عدد عناصر المصفوفة nخطوة حيث n log nيقوم هذا الخوارزم بترتيب المصفوفة بمعدل

: بمعنى

..خطوة 896عنصر فإن هذا الخورازم سيقوم بترتيها في 128إذا كان لدينا مصفوفة بها

و يعتبر هذا العدد مناسبا جدا إذا ما قورن ب خوارزميات الترتيب األخرى

..خطوة في بأي حال من األحوال 16384سنحتاج إلى Bubble sortفعلى سبيل المثال في خوارزم


Recommended